use of de.gurkenlabs.litiengine.IUpdateable in project litiengine by gurkenlabs.
the class Environment method unload.
/**
* Unload the specified entity by performing the following steps:
* <ol>
* <li>remove entities from physics engine</li>
* <li>unregister units from update</li>
* <li>unregister ai controller from update</li>
* <li>unregister animation controller from update</li>
* <li>unregister movement controller from update</li>
* </ol>
*
* @param entity
*/
private void unload(final IEntity entity) {
// 1. remove from physics engine
if (entity instanceof CollisionBox) {
final CollisionBox coll = (CollisionBox) entity;
if (coll.isObstacle()) {
Game.getPhysicsEngine().remove(coll.getBoundingBox());
} else {
Game.getPhysicsEngine().remove(coll);
}
} else if (entity instanceof ICollisionEntity) {
final ICollisionEntity coll = (ICollisionEntity) entity;
Game.getPhysicsEngine().remove(coll);
}
// 2. unregister from update
if (entity instanceof IUpdateable) {
Game.getLoop().detach((IUpdateable) entity);
}
// 3. unregister ai controller from update
final IEntityController<? extends IEntity> controller = Game.getEntityControllerManager().getAIController(entity);
if (controller != null) {
Game.getLoop().detach(controller);
}
// 4. unregister animation controller from update
final IAnimationController animation = Game.getEntityControllerManager().getAnimationController(entity);
if (animation != null) {
Game.getLoop().detach(animation);
}
// 5. unregister movement controller from update
if (entity instanceof IMobileEntity) {
final IMovementController<? extends IMobileEntity> movementController = Game.getEntityControllerManager().getMovementController((IMobileEntity) entity);
if (movementController != null) {
Game.getLoop().detach(movementController);
}
}
if (entity instanceof Emitter) {
Emitter em = (Emitter) entity;
em.deactivate();
}
}
Aggregations