This repository has been archived by the owner on Mar 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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. |
miguelmartin75
suggested changes
Dec 16, 2016
} | ||
|
||
bool EntityIdPool::isValid(Entity::Id id) const | ||
{ | ||
return id.counter == m_counts[id.index]; | ||
if( id.index >= m_counts.size() ) |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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) ) |
There was a problem hiding this comment.
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.
Made requested changes to the formatting. |
miguelmartin75
approved these changes
Dec 17, 2016
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.