public SWGObject deleteObject(long objId) { synchronized (objectMap) { SWGObject obj = objectMap.remove(objId); database.remove(objId); if (obj == null) return null; obj.clearAware(); objectAwareness.remove(obj); Log.i("ObjectManager", "Deleted object %d [%s]", obj.getObjectId(), obj.getTemplate()); return obj; } }
private void loadObjects() { long startLoad = System.nanoTime(); Log.i("ObjectManager", "Loading objects from ObjectDatabase..."); System.out.println("ObjectManager: Loading objects from ObjectDatabase..."); database.load(); database.traverse( new Traverser<SWGObject>() { @Override public void process(SWGObject obj) { loadObject(obj); if (obj.getObjectId() >= maxObjectId) { maxObjectId = obj.getObjectId() + 1; } } }); double loadTime = (System.nanoTime() - startLoad) / 1E6; Log.i("ObjectManager", "Finished loading %d objects. Time: %fms", database.size(), loadTime); System.out.printf( "ObjectManager: Finished loading %d objects. Time: %fms%n", database.size(), loadTime); }
public SWGObject createObject( SWGObject parent, String template, Location l, boolean addToDatabase) { synchronized (objectMap) { long objectId = getNextObjectId(); SWGObject obj = ObjectCreator.createObjectFromTemplate(objectId, template); if (obj == null) { System.err.println("ObjectManager: Unable to create object with template " + template); return null; } obj.setLocation(l); objectMap.put(objectId, obj); if (parent != null) { parent.addObject(obj); } if (addToDatabase) { database.put(objectId, obj); } Log.i("ObjectManager", "Created object %d [%s]", obj.getObjectId(), obj.getTemplate()); new ObjectCreatedIntent(obj).broadcast(); return obj; } }