|
|
@ -106,6 +106,7 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
final TerrainQuad newQuad = q; |
|
|
|
final TerrainQuad newQuad = q; |
|
|
|
// back on the OpenGL thread:
|
|
|
|
// back on the OpenGL thread:
|
|
|
|
getControl(UpdateControl.class).enqueue(new Callable() { |
|
|
|
getControl(UpdateControl.class).enqueue(new Callable() { |
|
|
|
|
|
|
|
|
|
|
|
public Object call() throws Exception { |
|
|
|
public Object call() throws Exception { |
|
|
|
attachQuadAt(newQuad, quadrant, temp); |
|
|
|
attachQuadAt(newQuad, quadrant, temp); |
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -123,14 +124,15 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int getQuadrant(int quadIndex) { |
|
|
|
private int getQuadrant(int quadIndex) { |
|
|
|
if (quadIndex == 9) |
|
|
|
if (quadIndex == 9) { |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
else if (quadIndex == 5) |
|
|
|
} else if (quadIndex == 5) { |
|
|
|
return 2; |
|
|
|
return 2; |
|
|
|
else if (quadIndex == 10) |
|
|
|
} else if (quadIndex == 10) { |
|
|
|
return 3; |
|
|
|
return 3; |
|
|
|
else if (quadIndex == 6) |
|
|
|
} else if (quadIndex == 6) { |
|
|
|
return 4; |
|
|
|
return 4; |
|
|
|
|
|
|
|
} |
|
|
|
return 0; // error
|
|
|
|
return 0; // error
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -190,6 +192,7 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
for (TerrainGridListener l : this.listeners.values()) { |
|
|
|
for (TerrainGridListener l : this.listeners.values()) { |
|
|
|
l.gridMoved(camCell); |
|
|
|
l.gridMoved(camCell); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
updatePhysics(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -205,6 +208,7 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
for (TerrainGridListener l : this.listeners.values()) { |
|
|
|
for (TerrainGridListener l : this.listeners.values()) { |
|
|
|
l.gridMoved(camCell); |
|
|
|
l.gridMoved(camCell); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
updatePhysics(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
super.update(locations); |
|
|
|
super.update(locations); |
|
|
@ -234,8 +238,8 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
q.setQuadrant((short) quadrant); |
|
|
|
q.setQuadrant((short) quadrant); |
|
|
|
this.attachChild(q); |
|
|
|
this.attachChild(q); |
|
|
|
|
|
|
|
|
|
|
|
Vector3f loc = cam.mult(this.quadSize-1).subtract(quarterSize, 0, quarterSize);// quadrant location handled TerrainQuad automatically now
|
|
|
|
Vector3f loc = cam.mult(this.quadSize - 1).subtract(quarterSize, 0, quarterSize);// quadrant location handled TerrainQuad automatically now
|
|
|
|
q.setLocalTranslation(loc ); |
|
|
|
q.setLocalTranslation(loc); |
|
|
|
|
|
|
|
|
|
|
|
if (quadControls != null) { |
|
|
|
if (quadControls != null) { |
|
|
|
quadControls[quadrant - 1].setEnabled(false); |
|
|
|
quadControls[quadrant - 1].setEnabled(false); |
|
|
@ -250,7 +254,7 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
updateModelBound(); |
|
|
|
updateModelBound(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void updateChildrens(Vector3f cam) { |
|
|
|
public void updatePhysics() { |
|
|
|
RigidBodyControl control = getControl(RigidBodyControl.class); |
|
|
|
RigidBodyControl control = getControl(RigidBodyControl.class); |
|
|
|
if (control != null) { |
|
|
|
if (control != null) { |
|
|
|
this.space = control.getPhysicsSpace(); |
|
|
|
this.space = control.getPhysicsSpace(); |
|
|
@ -261,22 +265,29 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
for (int i = 0; i < 4; i++) { |
|
|
|
for (int i = 0; i < 4; i++) { |
|
|
|
int collisionGroupsCollideWith = control.getCollideWithGroups(); |
|
|
|
int collisionGroupsCollideWith = control.getCollideWithGroups(); |
|
|
|
int collisionGroups = control.getCollisionGroup(); |
|
|
|
int collisionGroups = control.getCollisionGroup(); |
|
|
|
quadControls[i] = new RigidBodyControl(new HeightfieldCollisionShape(new float[quadSize * quadSize], getLocalScale()), 0); |
|
|
|
TerrainQuad q = getQuad(i + 1); |
|
|
|
|
|
|
|
quadControls[i] = new RigidBodyControl(new HeightfieldCollisionShape(q == null ? new float[quadSize * quadSize] : q.getHeightMap(), getLocalScale()), 0); |
|
|
|
quadControls[i].setCollideWithGroups(collisionGroupsCollideWith); |
|
|
|
quadControls[i].setCollideWithGroups(collisionGroupsCollideWith); |
|
|
|
quadControls[i].setCollisionGroup(collisionGroups); |
|
|
|
quadControls[i].setCollisionGroup(collisionGroups); |
|
|
|
//quadControls[i].setPhysicsSpace(space);
|
|
|
|
//quadControls[i].setPhysicsSpace(space);
|
|
|
|
//this.addControl(quadControls[i]);
|
|
|
|
//this.addControl(quadControls[i]);
|
|
|
|
//space.add(quadControls[i]);
|
|
|
|
if (q != null) { |
|
|
|
|
|
|
|
getQuad(i + 1).addControl(quadControls[i]); |
|
|
|
|
|
|
|
space.add(quadControls[i]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateChildrens(Vector3f cam) { |
|
|
|
//TerrainQuad q1 = cache.get(cam.add(quadIndex[9]));
|
|
|
|
//TerrainQuad q1 = cache.get(cam.add(quadIndex[9]));
|
|
|
|
//TerrainQuad q2 = cache.get(cam.add(quadIndex[5]));
|
|
|
|
//TerrainQuad q2 = cache.get(cam.add(quadIndex[5]));
|
|
|
|
//TerrainQuad q3 = cache.get(cam.add(quadIndex[10]));
|
|
|
|
//TerrainQuad q3 = cache.get(cam.add(quadIndex[10]));
|
|
|
|
//TerrainQuad q4 = cache.get(cam.add(quadIndex[6]));
|
|
|
|
//TerrainQuad q4 = cache.get(cam.add(quadIndex[6]));
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// what does this block do?
|
|
|
|
// LRU cache is used, so elements that need to remain
|
|
|
|
|
|
|
|
// should be touched.
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
|
|
int dx = 0; |
|
|
|
int dx = 0; |
|
|
|
int dy = 0; |
|
|
|
int dy = 0; |
|
|
@ -309,25 +320,26 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
if (executor == null) |
|
|
|
if (executor == null) { |
|
|
|
executor = createExecutorService(); |
|
|
|
executor = createExecutorService(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
executor.submit(new UpdateQuadCache(cam)); |
|
|
|
executor.submit(new UpdateQuadCache(cam)); |
|
|
|
|
|
|
|
|
|
|
|
/* if (q1 == null || q2 == null || q3 == null || q4 == null) { |
|
|
|
/* if (q1 == null || q2 == null || q3 == null || q4 == null) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
executor.submit(new UpdateQuadCache(cam, true)).get(); // BLOCKING
|
|
|
|
executor.submit(new UpdateQuadCache(cam, true)).get(); // BLOCKING
|
|
|
|
q1 = cache.get(cam.add(quadIndex[9])); |
|
|
|
q1 = cache.get(cam.add(quadIndex[9])); |
|
|
|
q2 = cache.get(cam.add(quadIndex[5])); |
|
|
|
q2 = cache.get(cam.add(quadIndex[5])); |
|
|
|
q3 = cache.get(cam.add(quadIndex[10])); |
|
|
|
q3 = cache.get(cam.add(quadIndex[10])); |
|
|
|
q4 = cache.get(cam.add(quadIndex[6])); |
|
|
|
q4 = cache.get(cam.add(quadIndex[6])); |
|
|
|
} catch (InterruptedException ex) { |
|
|
|
} catch (InterruptedException ex) { |
|
|
|
Logger.getLogger(TerrainGrid.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
Logger.getLogger(TerrainGrid.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} catch (ExecutionException ex) { |
|
|
|
} catch (ExecutionException ex) { |
|
|
|
Logger.getLogger(TerrainGrid.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
Logger.getLogger(TerrainGrid.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
executor.execute(new UpdateQuadCache(cam)); |
|
|
|
executor.execute(new UpdateQuadCache(cam)); |
|
|
@ -342,7 +354,7 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
attachQuadAt(q2, 2, cam); // quadIndex[5]
|
|
|
|
attachQuadAt(q2, 2, cam); // quadIndex[5]
|
|
|
|
attachQuadAt(q3, 3, cam); // quadIndex[10]
|
|
|
|
attachQuadAt(q3, 3, cam); // quadIndex[10]
|
|
|
|
attachQuadAt(q4, 4, cam); // quadIndex[6]
|
|
|
|
attachQuadAt(q4, 4, cam); // quadIndex[6]
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
this.currentCell = cam; |
|
|
|
this.currentCell = cam; |
|
|
|
// this.updateModelBound();
|
|
|
|
// this.updateModelBound();
|
|
|
|
} |
|
|
|
} |
|
|
@ -371,12 +383,51 @@ public class TerrainGrid extends TerrainQuad { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void adjustHeight(List<Vector2f> xz, List<Float> height) { |
|
|
|
public void adjustHeight(List<Vector2f> xz, List<Float> height) { |
|
|
|
Vector3f currentGridLocation = getCurrentCell().mult( getLocalScale() ).multLocal( quadSize-1 ); |
|
|
|
Vector3f currentGridLocation = getCurrentCell().mult(getLocalScale()).multLocal(quadSize - 1); |
|
|
|
for ( Vector2f vect : xz ) |
|
|
|
for (Vector2f vect : xz) { |
|
|
|
{ |
|
|
|
|
|
|
|
vect.x -= currentGridLocation.x; |
|
|
|
vect.x -= currentGridLocation.x; |
|
|
|
vect.y -= currentGridLocation.z; |
|
|
|
vect.y -= currentGridLocation.z; |
|
|
|
} |
|
|
|
} |
|
|
|
super.adjustHeight( xz, height ); |
|
|
|
super.adjustHeight(xz, height); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected TerrainQuad findDownQuad() { |
|
|
|
|
|
|
|
if (quadrant == 1) { |
|
|
|
|
|
|
|
return cache.get(currentCell.add(quadIndex[13])); |
|
|
|
|
|
|
|
} else if (quadrant == 3) { |
|
|
|
|
|
|
|
return cache.get(currentCell.add(quadIndex[14])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected TerrainQuad findLeftQuad() { |
|
|
|
|
|
|
|
if (quadrant == 1) { |
|
|
|
|
|
|
|
return cache.get(currentCell.add(quadIndex[8])); |
|
|
|
|
|
|
|
} else if (quadrant == 2) { |
|
|
|
|
|
|
|
return cache.get(currentCell.add(quadIndex[4])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected TerrainQuad findRightQuad() { |
|
|
|
|
|
|
|
if (quadrant == 3) { |
|
|
|
|
|
|
|
return cache.get(currentCell.add(quadIndex[11])); |
|
|
|
|
|
|
|
} else if (quadrant == 4) { |
|
|
|
|
|
|
|
return cache.get(currentCell.add(quadIndex[7])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected TerrainQuad findTopQuad() { |
|
|
|
|
|
|
|
if (quadrant == 2) { |
|
|
|
|
|
|
|
return cache.get(currentCell.add(quadIndex[1])); |
|
|
|
|
|
|
|
} else if (quadrant == 4) { |
|
|
|
|
|
|
|
return cache.get(currentCell.add(quadIndex[2])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|