82 lines
2.0 KiB
Java
82 lines
2.0 KiB
Java
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<Entity> entityList = new CopyOnWriteArrayList();
|
|
static CopyOnWriteArrayList<Entity> drawableList = new CopyOnWriteArrayList();
|
|
static CopyOnWriteArrayList<Entity> moveableList = new CopyOnWriteArrayList();
|
|
static CopyOnWriteArrayList<Entity> 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<Entity> getDrawable(){
|
|
return drawableList;
|
|
}
|
|
|
|
public void registerMoveableEntity(Entity e){
|
|
moveableList.add(e);
|
|
}
|
|
|
|
public CopyOnWriteArrayList<Entity> getMoveable(){
|
|
return moveableList;
|
|
}
|
|
|
|
public void registerLightEntity(Entity e){
|
|
lightList.add(e);
|
|
}
|
|
|
|
public CopyOnWriteArrayList<Entity> 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);
|
|
}
|
|
|
|
}
|