package electrosphere.entity; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; /** * * @author satellite */ public class EntityManager { static ConcurrentHashMap entityIdMap = new ConcurrentHashMap(); static CopyOnWriteArrayList entityList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList drawableList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList moveableList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList lightList = new CopyOnWriteArrayList(); public EntityManager(){ } public void registerEntity(Entity e){ entityIdMap.put(e.getId(), e); entityList.add(e); } public void registerDrawableEntity(Entity e){ drawableList.add(e); } public CopyOnWriteArrayList getDrawable(){ return drawableList; } public void registerMoveableEntity(Entity e){ moveableList.add(e); } public CopyOnWriteArrayList getMoveable(){ return moveableList; } public void registerLightEntity(Entity e){ lightList.add(e); } public CopyOnWriteArrayList getLights(){ return lightList; } public void deregisterEntity(Entity e){ if(lightList.contains(e)){ lightList.remove(e); } if(moveableList.contains(e)){ moveableList.remove(e); } if(drawableList.contains(e)){ drawableList.remove(e); EntityUtils.cleanUpDrawableEntity(e); } if(entityList.contains(e)){ entityList.remove(e); } } public void overrideEntityId(Entity e, int id){ if(entityIdMap.contains(e.getId())){ entityIdMap.remove(e.getId()); } e.setId(id); entityIdMap.put(e.getId(), e); } public Entity getEntityFromId(int id){ return (Entity)entityIdMap.get(id); } }