}
public synchronized boolean updateWorld() {
if (observer != null && observer.hasGraphChanged()) {
NodeModeler nodeModeler = (NodeModeler) engine.getNodeClass().getCurrentModeler();
EdgeModeler edgeModeler = (EdgeModeler) engine.getEdgeClass().getCurrentModeler();
Octree octree = engine.getOctree();
//Stats
int removedNodes = 0;
int addedNodes = 0;
int removedEdges = 0;
int addedEdges = 0;
for (int i = 0; i < nodes.length; i++) {
NodeModel node = nodes[i];
if (node != null && node.getNode().getStoreId() == -1) {
//Removed
octree.removeNode(node);
nodes[i] = null;
removedNodes++;
}
}
for (Node node : graph.getNodes()) {
int id = node.getStoreId();
if (id >= nodes.length || nodes[id] == null) {
growNodes(id);
NodeModel model = nodeModeler.initModel(node);
octree.addNode(model);
nodes[id] = model;
addedNodes++;
}
}
for (int i = 0; i < edges.length; i++) {
EdgeModel edge = edges[i];
if (edge != null && edge.getEdge().getStoreId() == -1) {
//Removed
NodeModel sourceModel = nodes[edge.getEdge().getSource().getStoreId()];
NodeModel targetModel = nodes[edge.getEdge().getTarget().getStoreId()];
if (sourceModel != null) {
sourceModel.removeEdge(edge);
}
if (targetModel != null) {
targetModel.removeEdge(edge);
}
edges[i] = null;
removedEdges++;
}
}
float minWeight = Float.MAX_VALUE;
float maxWeight = Float.MIN_VALUE;
for (Edge edge : graph.getEdges()) {
int id = edge.getStoreId();
if (id >= edges.length || edges[id] == null) {
growEdges(id);
NodeModel sourceModel = nodes[edge.getSource().getStoreId()];
NodeModel targetModel = nodes[edge.getTarget().getStoreId()];
EdgeModel model = edgeModeler.initModel(edge, sourceModel, targetModel);
sourceModel.addEdge(model);
targetModel.addEdge(model);
edges[id] = model;
addedEdges++;
}