gdx-tilemap3d/src/main/java/ca/blarg/gdx/tilemap3d/TileMapUpdater.java
Gered 620dc275d1 better way of checking if a chunk needs VBO creation
old way had some concurrency issues on slower hardware
2014-03-16 11:14:34 -04:00

61 lines
1.2 KiB
Java

package ca.blarg.gdx.tilemap3d;
public class TileMapUpdater implements Runnable {
final TileMap tileMap;
boolean waitingForVboCreation;
TileChunk chunkNeedingVboCreation;
float progress;
boolean isRunning;
public TileMapUpdater(TileMap tileMap) {
this.tileMap = tileMap;
}
public float currentProgress() {
return progress;
}
public boolean isUpdating() {
return isRunning;
}
public TileChunk getChunkNeedingVboCreation() {
return chunkNeedingVboCreation;
}
public boolean isWaitingForVboCreation() {
return waitingForVboCreation;
}
public synchronized void signalDoneVboCreation() {
waitingForVboCreation = false;
}
@Override
public void run() {
isRunning = true;
chunkNeedingVboCreation = null;
TileChunk[] chunks = tileMap.getChunks();
for (int i = 0; i < tileMap.chunks.length; ++i) {
progress = (float)i / (float)(chunks.length - 1);
TileChunk chunk = chunks[i];
tileMap.vertexGenerator.generateVertices(chunk);
chunkNeedingVboCreation = chunk;
waitingForVboCreation = true;
// wait for the render thread to take care of VBO creation and single to us that it's done
while (waitingForVboCreation)
Thread.yield();
chunkNeedingVboCreation = null;
}
progress = 1.0f;
isRunning = false;
}
}