Search in sources :

Example 1 with IUpdateable

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();
    }
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) IUpdateable(de.gurkenlabs.litiengine.IUpdateable) ICollisionEntity(de.gurkenlabs.litiengine.entities.ICollisionEntity) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Aggregations

IUpdateable (de.gurkenlabs.litiengine.IUpdateable)1 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)1 ICollisionEntity (de.gurkenlabs.litiengine.entities.ICollisionEntity)1 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)1 IAnimationController (de.gurkenlabs.litiengine.graphics.animation.IAnimationController)1 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)1