Added collidable areas which can trigger a script, started work on AI, fixed position secured, updated engine

This commit is contained in:
Light2
2013-12-02 23:58:22 +01:00
parent 6857bd562b
commit 30e1e1c8ec
19 changed files with 574 additions and 26 deletions
+38 -1
View File
@@ -69,6 +69,7 @@ import resources.objects.cell.CellObject;
import resources.objects.creature.CreatureObject;
import resources.objects.player.PlayerObject;
import resources.common.*;
import resources.common.collidables.AbstractCollidable;
import toxi.geom.Line3D;
import toxi.geom.Ray3D;
import toxi.geom.Vec3D;
@@ -91,6 +92,9 @@ import wblut.math.WB_M44;
public class SimulationService implements INetworkDispatch {
Map<String, QuadTree<SWGObject>> quadTrees;
Map<String, QuadTree<AbstractCollidable>> collidableQuadTrees;
private NGECore core;
private Map<String, MeshVisitor> cellMeshes = new ConcurrentHashMap<String, MeshVisitor>();
@@ -98,9 +102,11 @@ public class SimulationService implements INetworkDispatch {
this.core = core;
TerrainService terrainService = core.terrainService;
quadTrees = new ConcurrentHashMap<String, QuadTree<SWGObject>>();
collidableQuadTrees = new ConcurrentHashMap<String, QuadTree<AbstractCollidable>>();
for (int i = 0; i < core.terrainService.getPlanetList().size(); i++) {
quadTrees.put(terrainService.getPlanetList().get(i).getName(), new QuadTree<SWGObject>(-8192, -8192, 8192, 8192));
collidableQuadTrees.put(terrainService.getPlanetList().get(i).getName(), new QuadTree<AbstractCollidable>(-8192, -8192, 8192, 8192));
}
core.commandService.registerCommand("opencontainer");
@@ -146,6 +152,18 @@ public class SimulationService implements INetworkDispatch {
}
}
public void addCollidable(AbstractCollidable collidable, float x, float y) {
collidableQuadTrees.get(collidable.getPlanet().getName()).put(x, y, collidable);
}
public void removeCollidable(AbstractCollidable collidable, float x, float y) {
collidableQuadTrees.get(collidable.getPlanet().getName()).remove(x, y, collidable);
}
public List<AbstractCollidable> getCollidables(Planet planet, float x, float y, float range) {
return collidableQuadTrees.get(planet.getName()).get(x, y, range);
}
public void add(SWGObject object, int x, int y) {
object.setIsInQuadtree(true);
core.objectService.loadServerTemplate(object);
@@ -275,7 +293,7 @@ public class SimulationService implements INetworkDispatch {
}
}
checkForCollidables(object);
}
@@ -326,6 +344,8 @@ public class SimulationService implements INetworkDispatch {
object.setOrientation(newOrientation);
object.setMovementCounter(dataTransform.getMovementCounter());
object.notifyObservers(utm, false);
checkForCollidables(object);
}
@@ -466,6 +486,14 @@ public class SimulationService implements INetworkDispatch {
if(object.getGroupId() != 0)
core.groupService.handleGroupDisband(object);
Point3D objectPos = object.getWorldPosition();
List<AbstractCollidable> collidables = getCollidables(object.getPlanet(), objectPos.x, objectPos.z, 512);
for(AbstractCollidable collidable : collidables) {
collidables.remove(object);
}
if (ghost != null) {
String objectShortName = object.getCustomName();
@@ -917,5 +945,14 @@ public class SimulationService implements INetworkDispatch {
}
}
public void checkForCollidables(SWGObject object) {
Point3D objectPos = object.getWorldPosition();
List<AbstractCollidable> collidables = getCollidables(object.getPlanet(), objectPos.x, objectPos.z, 256);
for(AbstractCollidable collidable : collidables) {
collidable.doCollisionCheck(object);
}
}
}