Refactored loading a bit to fix an issue where objects "steal" fixed client object ids before the client object can be loaded,fixed 2 errors

This commit is contained in:
Light2
2014-03-28 18:22:21 +01:00
parent 1cd2a139db
commit 932302d1e9
5 changed files with 56 additions and 22 deletions
+31 -15
View File
@@ -113,6 +113,7 @@ public class ObjectService implements INetworkDispatch {
private Map<String, PyObject> serverTemplates = new ConcurrentHashMap<String, PyObject>();
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
protected final Object objectMutex = new Object();
private List<Runnable> loadServerTemplateTasks = Collections.synchronizedList(new ArrayList<Runnable>());
public ObjectService(final NGECore core) {
this.core = core;
@@ -168,17 +169,24 @@ public class ObjectService implements INetworkDispatch {
}
});
loadServerTemplate(building);
core.simulationService.add(building, building.getPosition().x, building.getPosition().z);
}
}
public SWGObject createObject(String Template, long objectID, Planet planet, Point3D position, Quaternion orientation, String customServerTemplate) {
return createObject(Template, objectID, planet, position, orientation, customServerTemplate, false);
public void loadServerTemplates() {
System.out.println("Loading server templates...");
for(Runnable r : loadServerTemplateTasks) {
r.run();
}
loadServerTemplateTasks.clear();
System.out.println("Finished loading server templates...");
}
public SWGObject createObject(String Template, long objectID, Planet planet, Point3D position, Quaternion orientation, String customServerTemplate, boolean overrideSnapshot) {
public SWGObject createObject(String Template, long objectID, Planet planet, Point3D position, Quaternion orientation, String customServerTemplate) {
return createObject(Template, objectID, planet, position, orientation, customServerTemplate, false, true);
}
public SWGObject createObject(String Template, long objectID, Planet planet, Point3D position, Quaternion orientation, String customServerTemplate, boolean overrideSnapshot, boolean loadServerTemplate) {
SWGObject object = null;
CrcStringTableVisitor crcTable;
try {
@@ -266,7 +274,12 @@ public class ObjectService implements INetworkDispatch {
if(!core.getObjectIdODB().contains(objectID, Long.class, ObjectId.class)) {
core.getObjectIdODB().put(new ObjectId(objectID), Long.class, ObjectId.class);
}
loadServerTemplate(object);
if(loadServerTemplate)
loadServerTemplate(object);
else {
final SWGObject pointer = object;
loadServerTemplateTasks.add(() -> loadServerTemplate(pointer));
}
objectList.put(objectID, object);
@@ -331,6 +344,7 @@ public class ObjectService implements INetworkDispatch {
} catch (IOException e) {
System.out.println("!IO error " + template.toString());
}
object.setAttachment("hasLoadedServerTemplate", new Boolean(true));
}
public SWGObject createObject(String Template, Planet planet) {
@@ -705,7 +719,7 @@ public class ObjectService implements INetworkDispatch {
// This is done for buildouts; uncertain about snapshot objects so it's commented for now
//long objectId = Delta.createBuffer(8).putInt(chunk.id).putInt(0xF986FFFF).flip().getLong(); // Not sure what extension they add to 4-byte-only snapshot objectIds. With buildouts they add 0xFFFF86F9. This is demonstated in the packet sent to the server when you /target client-spawned objects
int objectId = chunk.id;
SWGObject obj = createObject(visitor.getName(chunk.nameId), objectId, planet, new Point3D(chunk.xPosition, chunk.yPosition, chunk.zPosition), new Quaternion(chunk.orientationW, chunk.orientationX, chunk.orientationY, chunk.orientationZ));
SWGObject obj = createObject(visitor.getName(chunk.nameId), objectId, planet, new Point3D(chunk.xPosition, chunk.yPosition, chunk.zPosition), new Quaternion(chunk.orientationW, chunk.orientationX, chunk.orientationY, chunk.orientationZ), null, false, false);
if(obj != null) {
obj.setContainerPermissions(WorldPermissions.WORLD_PERMISSIONS);
obj.setisInSnapshot(true);
@@ -891,7 +905,7 @@ public class ObjectService implements INetworkDispatch {
if(objectId != 0 && containerId == 0) {
if(portalCRC != 0) {
containers.add(objectId);
object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz), null, true);
object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz), null, true, false);
object.setAttachment("childObjects", null);
if (!duplicate.containsValue(objectId)) {
((BuildingObject) object).createTransaction(core.getBuildingODB().getEnvironment());
@@ -899,7 +913,7 @@ public class ObjectService implements INetworkDispatch {
((BuildingObject) object).getTransaction().commitSync();
}
} else {
object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz));
object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz), null, false, false);
}
if(object == null)
continue;
@@ -908,7 +922,7 @@ public class ObjectService implements INetworkDispatch {
object.setAttachment("bigSpawnRange", new Boolean(true));
quadtreeObjects.add(object);
} else if(containerId != 0) {
object = createObject(template, 0, planet, new Point3D(px, py, pz), new Quaternion(qw, qx, qy, qz));
object = createObject(template, 0, planet, new Point3D(px, py, pz), new Quaternion(qw, qx, qy, qz), null, false, false);
if(containers.contains(containerId)) {
object.setContainerPermissions(WorldPermissions.WORLD_PERMISSIONS);
object.setisInSnapshot(false);
@@ -926,20 +940,22 @@ public class ObjectService implements INetworkDispatch {
parent.add(object);
}
} else {
object = createObject(template, 0, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz));
object = createObject(template, 0, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz), null, false, false);
object.setContainerPermissions(WorldPermissions.WORLD_PERMISSIONS);
quadtreeObjects.add(object);
}
//System.out.println("Spawning: " + template + " at: X:" + object.getPosition().x + " Y: " + object.getPosition().y + " Z: " + object.getPosition().z);
if(object != null)
object.setAttachment("isBuildout", new Boolean(true));
}
}
for(SWGObject obj : quadtreeObjects) {
// this might load stuff before snapshots of other planets are finished
/*for(SWGObject obj : quadtreeObjects) {
core.simulationService.add(obj, obj.getPosition().x, obj.getPosition().z);
}
}*/
}