use of de.gurkenlabs.litiengine.entities.IMobileEntity 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();
}
}
use of de.gurkenlabs.litiengine.entities.IMobileEntity in project litiengine by gurkenlabs.
the class EntityControllerManager method disposeControllers.
public void disposeControllers(final IEntity entity) {
final IEntityController<? extends IEntity> aiController = this.getAIController(entity);
if (aiController != null) {
Game.getLoop().detach(aiController);
this.aiControllers.remove(entity);
}
if (entity instanceof IMobileEntity) {
final IMovementController<? extends IMobileEntity> controller = this.getMovementController((IMobileEntity) entity);
if (controller != null) {
Game.getLoop().detach(controller);
this.movementControllers.remove(entity);
}
}
final IAnimationController animationController = this.getAnimationController(entity);
if (animationController != null) {
animationController.dispose();
this.animationControllers.remove(entity);
}
}
use of de.gurkenlabs.litiengine.entities.IMobileEntity in project litiengine by gurkenlabs.
the class Environment method remove.
@Override
public void remove(final IEntity entity) {
if (entity == null) {
return;
}
if (this.entities.get(entity.getRenderType()) != null) {
this.entities.get(entity.getRenderType()).entrySet().removeIf(e -> e.getValue().getMapId() == entity.getMapId());
}
for (String tag : entity.getTags()) {
if (this.entitiesByTag.containsKey(tag)) {
this.entitiesByTag.get(tag).remove(entity);
if (this.entitiesByTag.get(tag).isEmpty()) {
this.entitiesByTag.remove(tag);
}
}
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.groundRenderable.remove(emitter.getGroundRenderable());
this.overlayRenderable.remove(emitter.getOverlayRenderable());
this.emitters.remove(emitter);
}
if (entity instanceof MapArea) {
this.mapAreas.remove(entity);
}
if (entity instanceof Prop) {
this.props.remove(entity);
}
if (entity instanceof Creature) {
this.creatures.remove(entity);
}
if (entity instanceof CollisionBox) {
this.colliders.remove(entity);
this.staticShadows.removeIf(x -> x.getOrigin() != null && x.getOrigin().equals(entity));
}
if (entity instanceof LightSource) {
this.lightSources.remove(entity);
this.updateColorLayers(entity);
}
if (entity instanceof Trigger) {
this.triggers.remove(entity);
}
if (entity instanceof Spawnpoint) {
this.spawnPoints.remove(entity);
}
if (entity instanceof StaticShadow) {
this.staticShadows.remove(entity);
this.updateColorLayers(entity);
}
if (entity instanceof IMobileEntity) {
this.mobileEntities.values().remove(entity);
}
if (entity instanceof ICombatEntity) {
this.combatEntities.values().remove(entity);
}
this.unload(entity);
for (Consumer<IEntity> cons : this.entityRemovedConsumers) {
cons.accept(entity);
}
}
Aggregations