use of de.gurkenlabs.litiengine.graphics.emitters.Emitter in project litiengine by gurkenlabs.
the class Environment method remove.
/**
* Removes the specified entity from this environment and unloads is.
*
* @param entity
* The entity to be removed.
*
* @see #remove(int)
* @see #remove(String)
* @see #removeAll(Iterable)
* @see #unload(IEntity)
* @see EnvironmentEntityListener#entityRemoved(IEntity)
* @see IEntity#removed(Environment)
* @see EntityListener#removed(IEntity, Environment)
*/
public void remove(final IEntity entity) {
if (entity == null) {
return;
}
this.allEntities.remove(entity.getMapId());
Iterator<List<IEntity>> iter = this.layerEntities.values().iterator();
while (iter.hasNext()) {
List<IEntity> layer = iter.next();
if (layer.remove(entity) && layer.isEmpty()) {
iter.remove();
}
}
if (this.miscEntities.get(entity.getRenderType()) != null) {
this.miscEntities.get(entity.getRenderType()).values().remove(entity);
}
for (String tag : entity.getTags()) {
if (this.getEntitiesByTag().containsKey(tag)) {
this.getEntitiesByTag().get(tag).remove(entity);
if (this.getEntitiesByTag().get(tag).isEmpty()) {
this.getEntitiesByTag().remove(tag);
}
}
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.removeEmitter(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.updateLighting(entity);
}
if (entity instanceof Trigger) {
this.triggers.remove(entity);
}
if (entity instanceof Spawnpoint) {
this.spawnPoints.remove(entity);
}
if (entity instanceof SoundSource) {
this.soundSources.remove(entity);
}
if (entity instanceof StaticShadow) {
this.staticShadows.remove(entity);
this.updateLighting(entity);
}
if (entity instanceof IMobileEntity) {
this.mobileEntities.values().remove(entity);
}
if (entity instanceof ICombatEntity) {
this.combatEntities.values().remove(entity);
}
this.unload(entity);
this.fireEntityEvent(l -> l.entityRemoved(entity));
}
use of de.gurkenlabs.litiengine.graphics.emitters.Emitter in project litiengine by gurkenlabs.
the class Environment method addEntity.
private void addEntity(final IEntity entity) {
int desiredID = entity.getMapId();
// assign local map id if the entity's mapID is invalid
if (desiredID == 0 || this.allEntities.keySet().contains(desiredID)) {
entity.setMapId(getLocalMapId());
log.fine(() -> String.format("Entity [%s] was assigned a local mapID because #%d was already taken or invalid.", entity, desiredID));
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.addEmitter(emitter);
}
if (entity instanceof ICombatEntity) {
this.combatEntities.put(entity.getMapId(), (ICombatEntity) entity);
}
if (entity instanceof IMobileEntity) {
this.mobileEntities.put(entity.getMapId(), (IMobileEntity) entity);
}
if (entity instanceof Prop) {
this.props.add((Prop) entity);
}
if (entity instanceof Creature) {
this.creatures.add((Creature) entity);
}
if (entity instanceof CollisionBox) {
this.colliders.add((CollisionBox) entity);
}
if (entity instanceof LightSource) {
this.lightSources.add((LightSource) entity);
}
if (entity instanceof Trigger) {
this.triggers.add((Trigger) entity);
}
if (entity instanceof Spawnpoint) {
this.spawnPoints.add((Spawnpoint) entity);
}
if (entity instanceof SoundSource) {
this.soundSources.add((SoundSource) entity);
}
if (entity instanceof StaticShadow) {
this.staticShadows.add((StaticShadow) entity);
} else if (entity instanceof MapArea) {
this.mapAreas.add((MapArea) entity);
}
for (String rawTag : entity.getTags()) {
if (rawTag == null) {
continue;
}
final String tag = rawTag.trim().toLowerCase();
if (tag.isEmpty()) {
continue;
}
this.getEntitiesByTag().computeIfAbsent(tag, t -> new CopyOnWriteArrayList<>()).add(entity);
}
// we need to load the new entity manually
if (this.loaded) {
this.load(entity);
}
this.allEntities.put(entity.getMapId(), entity);
}
Aggregations