Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Making isValid More Useful #80

Merged
merged 4 commits into from
Dec 17, 2016
Merged

Conversation

spitofland
Copy link
Contributor

@spitofland spitofland commented Dec 15, 2016

The isValid function can hit assert statements for several conditions. This can make anax a bit hostile to newcomers as a test like 'isValid' is not often expected to fail. On Windows, assert does not throw an exception that can be caught, so returning an invalid ID from EntityIdPool::get is more useful at run-time.

Also fixed a bug in clearing the m_counts vector. This was causing a crash after calling World::clear, because the m_counts vector would suddenly be larger than other vectors that are expected to be the same size.

Updated the unit tests to account for an invalid get returning an invalid entity instead of crashing.

Added some tests to make it easier to check if an entity exists at a given index without throwing asserts.
Removed a resize command in the 'clear' function. The code seems to expect the m_counts vector and several other vectors to be the same size. When the World::clear function is called, this call to 'resize' breaks that assumption, which can result in crashes due to out-of-bounds indexes on the other vectors.
Made it easier to test the activation status without hitting asserts by testing validity first.
Corrected a test that was expecting an exception and now should expect an invalid entity.
@miguelmartin75
Copy link
Owner

This seems nice. I appreciate the effort. I'll merge it in if you update the coding style to be more consistent to what I've already written.

}

bool EntityIdPool::isValid(Entity::Id id) const
{
return id.counter == m_counts[id.index];
if( id.index >= m_counts.size() )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove spaces

ANAX_ASSERT(!(m_counts[index] == 0), "Entity ID does not exist");
return Entity::Id{index, m_counts[index]};
if( index < m_counts.size() )
return Entity::Id(index, m_counts[index]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use '{' to construct

ANAX_ASSERT(isValid(entity), "invalid entity passed to isActivated");

return m_entityAttributes.attributes[entity.getId().index].activated;
if( isValid(entity) )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the spaces

* Update World.cpp
* Update EntityIdPool.cpp

Correcting the formatting of changes to match coding style.
@spitofland
Copy link
Contributor Author

Made requested changes to the formatting.

@miguelmartin75 miguelmartin75 merged commit fa01241 into miguelmartin75:master Dec 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants