private void addEntityToTypeList(Entity entity) { ArrayList<Entity> type_list = this.getEntitiesByType(entity.getClass()); if (type_list == null) { type_list = new ArrayList<Entity>(1); this._entities_by_type.put(entity.getClass(), type_list); } type_list.add(entity); }
/** remove the given entity */ public Entity remove(Entity entity) { if (!(this.contains(entity))) { Logger.get().log(Level.WARNING, "Tried to remove an entity which wasnt in the world"); return (null); } // remove from global list this._entities.remove(entity.getWorldID()); // remove from type list ArrayList<Entity> type_list = this.getEntitiesByType(entity); if (type_list != null) { type_list.remove(entity); if (type_list.size() == 0) { this._entities_by_type.remove(entity.getClass()); } } // remove from model list Model model = this.getEntityModel(entity); ArrayList<Entity> model_list = this.getEntitiesByModel(model); if (model_list != null) { model_list.remove(entity); if (model_list.size() == 0) { this._entities_by_model.remove(model); } } return (entity); }
/** remove every entities which uses the given model (can be null) */ public Collection<Entity> removeEntitiesByModel(Model model) { ArrayList<Entity> entities = this.getEntitiesByModel(model); if (entities == null || entities.size() == 0) { Logger.get() .log( Logger.Level.DEBUG, "Tried to remove entity with model: " + model + " but no entities with this model where found."); return (null); } for (Entity entity : entities) { this._entities.remove(entity.getWorldID()); this._entities_by_type.remove(entity.getClass()); } this._entities_by_model.remove(model); return (entities); }
public ArrayList<Entity> getEntitiesByType(Entity entity) { return (this.getEntitiesByType(entity.getClass())); }