Salbris/Spider-Fish — Issue #31: Allowing changes in the group of a PhysicalEntity is not correctly implemented
Author: erisco
Created: 2011-10-11 05:29:48+00:00
State: open
Labels: Bug

Consider if a PhysicalEntity, say `myEntity`, is added to a CollisionManager. When being added, the CollisionManager will look at the group of `myEntity` and correctly pass it along to the appropriate CollisionSpace. After being added, say that we change the group of `myEntity` by calling `myEntity.setGroup(64)`. Now there are two issues.

1. Notifying the CollisionManager that a change occurred.
1. Removing the PhysicalEntity from the space it is currently in.
1. Adding the PhysicalEntity from the space it should be in.

Therefore, instead of allowing group hot-swapping, it would be much better to ask programmers to do the following.

1. Remove the entity from the CollisionManager.
2. Update the group of the entity.
3. Add the entity to the CollisionManager.

Although it is possible to muck up and create a hard-to-find bug, the problem is solved without requiring any additional code or fancywork.

Another solution would be to abolish `PhysicalEntity::_group` and maintain a `group -> PhysicalEntity&` map internally in CollisionManager. Although safer, it still results in having to notify the CollisionManager of group changes. This may also impact performance on adding/removing entities, as the internal map will need maintenance (we're only talking logN complexity stuff, but there is still overhead).

Discuss.