|
|
@ -114,7 +114,8 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
protected Vector3f[] quadIndex; |
|
|
|
protected Vector3f[] quadIndex; |
|
|
|
protected Set<TerrainGridListener> listeners = new HashSet<TerrainGridListener>(); |
|
|
|
protected Set<TerrainGridListener> listeners = new HashSet<TerrainGridListener>(); |
|
|
|
protected Material material; |
|
|
|
protected Material material; |
|
|
|
protected LRUCache<Vector3f, TerrainQuad> cache = new LRUCache<Vector3f, TerrainQuad>(16); |
|
|
|
//cache needs to be 1 row (4 cells) larger than what we care is cached
|
|
|
|
|
|
|
|
protected LRUCache<Vector3f, TerrainQuad> cache = new LRUCache<Vector3f, TerrainQuad>(20); |
|
|
|
protected int cellsLoaded = 0; |
|
|
|
protected int cellsLoaded = 0; |
|
|
|
protected int[] gridOffset; |
|
|
|
protected int[] gridOffset; |
|
|
|
protected boolean runOnce = false; |
|
|
|
protected boolean runOnce = false; |
|
|
@ -159,16 +160,28 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
} |
|
|
|
} |
|
|
|
cache.put(quadCell, q); |
|
|
|
cache.put(quadCell, q); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final int quadrant = getQuadrant(quadIdx); |
|
|
|
|
|
|
|
final TerrainQuad newQuad = q; |
|
|
|
|
|
|
|
|
|
|
|
if (isCenter(quadIdx)) { |
|
|
|
if (isCenter(quadIdx)) { |
|
|
|
// if it should be attached as a child right now, attach it
|
|
|
|
// if it should be attached as a child right now, attach it
|
|
|
|
final int quadrant = getQuadrant(quadIdx); |
|
|
|
|
|
|
|
final TerrainQuad newQuad = q; |
|
|
|
|
|
|
|
// back on the OpenGL thread:
|
|
|
|
|
|
|
|
getControl(UpdateControl.class).enqueue(new Callable() { |
|
|
|
getControl(UpdateControl.class).enqueue(new Callable() { |
|
|
|
|
|
|
|
// back on the OpenGL thread:
|
|
|
|
public Object call() throws Exception { |
|
|
|
public Object call() throws Exception { |
|
|
|
attachQuadAt(newQuad, quadrant, quadCell); |
|
|
|
if (newQuad.getParent() != null) { |
|
|
|
//newQuad.resetCachedNeighbours();
|
|
|
|
attachQuadAt(newQuad, quadrant, quadCell, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
attachQuadAt(newQuad, quadrant, quadCell, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
getControl(UpdateControl.class).enqueue(new Callable() { |
|
|
|
|
|
|
|
public Object call() throws Exception { |
|
|
|
|
|
|
|
removeQuad(newQuad); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -292,30 +305,34 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
return gridTileLoader; |
|
|
|
return gridTileLoader; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void removeQuad(int idx) { |
|
|
|
protected void removeQuad(TerrainQuad q) { |
|
|
|
if (this.getQuad(idx) != null) { |
|
|
|
if (q != null && ( (q.getQuadrant() > 0 && q.getQuadrant()<5) || q.getParent() != null) ) { |
|
|
|
for (TerrainGridListener l : listeners) { |
|
|
|
for (TerrainGridListener l : listeners) { |
|
|
|
l.tileDetached(getTileCell(this.getQuad(idx).getWorldTranslation()), this.getQuad(idx)); |
|
|
|
l.tileDetached(getTileCell(q.getWorldTranslation()), q); |
|
|
|
} |
|
|
|
} |
|
|
|
this.detachChild(this.getQuad(idx)); |
|
|
|
q.setQuadrant((short)0); |
|
|
|
|
|
|
|
this.detachChild(q); |
|
|
|
cellsLoaded++; // For gridoffset calc., maybe the run() method is a better location for this.
|
|
|
|
cellsLoaded++; // For gridoffset calc., maybe the run() method is a better location for this.
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Runs on the rendering thread |
|
|
|
* Runs on the rendering thread |
|
|
|
|
|
|
|
* @param shifted quads are still attached to the parent and don't need to re-load |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void attachQuadAt(TerrainQuad q, int quadrant, Vector3f quadCell) { |
|
|
|
protected void attachQuadAt(TerrainQuad q, int quadrant, Vector3f quadCell, boolean shifted) { |
|
|
|
this.removeQuad(quadrant); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
q.setQuadrant((short) quadrant); |
|
|
|
q.setQuadrant((short) quadrant); |
|
|
|
this.attachChild(q); |
|
|
|
if (!shifted) |
|
|
|
|
|
|
|
this.attachChild(q); |
|
|
|
|
|
|
|
|
|
|
|
Vector3f loc = quadCell.mult(this.quadSize - 1).subtract(quarterSize, 0, quarterSize);// quadrant location handled TerrainQuad automatically now
|
|
|
|
Vector3f loc = quadCell.mult(this.quadSize - 1).subtract(quarterSize, 0, quarterSize);// quadrant location handled TerrainQuad automatically now
|
|
|
|
q.setLocalTranslation(loc); |
|
|
|
q.setLocalTranslation(loc); |
|
|
|
|
|
|
|
|
|
|
|
for (TerrainGridListener l : listeners) { |
|
|
|
if (!shifted) { |
|
|
|
l.tileAttached(quadCell, q); |
|
|
|
for (TerrainGridListener l : listeners) { |
|
|
|
|
|
|
|
l.tileAttached(quadCell, q); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
updateModelBound(); |
|
|
|
updateModelBound(); |
|
|
|
|
|
|
|
|
|
|
@ -374,6 +391,7 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
cache.get(camCell.add(quadIndex[i * 4 + j])); |
|
|
|
cache.get(camCell.add(quadIndex[i * 4 + j])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|