async model processing
This commit is contained in:
@@ -28,15 +28,30 @@ public class ModelBakerySubsystem {
|
|||||||
private final AtomicInteger blockIdCount = new AtomicInteger();
|
private final AtomicInteger blockIdCount = new AtomicInteger();
|
||||||
private final ConcurrentLinkedDeque<Integer> blockIdQueue = new ConcurrentLinkedDeque<>();//TODO: replace with custom DS
|
private final ConcurrentLinkedDeque<Integer> blockIdQueue = new ConcurrentLinkedDeque<>();//TODO: replace with custom DS
|
||||||
|
|
||||||
|
private final Thread processingThread;
|
||||||
|
private volatile boolean isRunning = true;
|
||||||
public ModelBakerySubsystem(Mapper mapper) {
|
public ModelBakerySubsystem(Mapper mapper) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.factory = new ModelFactory(mapper, this.storage);
|
this.factory = new ModelFactory(mapper, this.storage);
|
||||||
|
this.processingThread = new Thread(()->{
|
||||||
|
while (this.isRunning) {
|
||||||
|
this.factory.processAllThings();
|
||||||
|
try {
|
||||||
|
Thread.sleep(50);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, "Model factory processor");
|
||||||
|
this.processingThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick(long totalBudget) {
|
public void tick(long totalBudget) {
|
||||||
if (this.blockIdCount.get() != 0) {
|
long start = System.nanoTime();
|
||||||
|
this.factory.tickAndProcessUploads();
|
||||||
//Always do 1 iteration minimum
|
//Always do 1 iteration minimum
|
||||||
Integer i = this.blockIdQueue.poll();
|
Integer i = this.blockIdQueue.poll();
|
||||||
|
if (i != null) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
if (i != null) {
|
if (i != null) {
|
||||||
int fbBinding = glGetInteger(GL_FRAMEBUFFER_BINDING);
|
int fbBinding = glGetInteger(GL_FRAMEBUFFER_BINDING);
|
||||||
@@ -44,7 +59,7 @@ public class ModelBakerySubsystem {
|
|||||||
do {
|
do {
|
||||||
this.factory.addEntry(i);
|
this.factory.addEntry(i);
|
||||||
j++;
|
j++;
|
||||||
if (24<j)//budget<(System.nanoTime() - start)+1000
|
if (4<j&&(totalBudget<(System.nanoTime() - start)+50_000))//20<j||
|
||||||
break;
|
break;
|
||||||
i = this.blockIdQueue.poll();
|
i = this.blockIdQueue.poll();
|
||||||
} while (i != null);
|
} while (i != null);
|
||||||
@@ -54,13 +69,17 @@ public class ModelBakerySubsystem {
|
|||||||
this.blockIdCount.addAndGet(-j);
|
this.blockIdCount.addAndGet(-j);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.factory.processAllThings();
|
|
||||||
|
|
||||||
this.factory.tickAndProcessUploads();
|
|
||||||
//TimingStatistics.modelProcess.stop();
|
//TimingStatistics.modelProcess.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
this.isRunning = false;
|
||||||
|
try {
|
||||||
|
this.processingThread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
this.factory.free();
|
this.factory.free();
|
||||||
this.storage.free();
|
this.storage.free();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,9 +364,12 @@ public class ModelFactory {
|
|||||||
this.idMappings[blockId] = possibleDuplicate;
|
this.idMappings[blockId] = possibleDuplicate;
|
||||||
modelId = possibleDuplicate;
|
modelId = possibleDuplicate;
|
||||||
//Remove from flight
|
//Remove from flight
|
||||||
|
this.blockStatesInFlightLock.lock();
|
||||||
if (!this.blockStatesInFlight.remove(blockId)) {
|
if (!this.blockStatesInFlight.remove(blockId)) {
|
||||||
|
this.blockStatesInFlightLock.unlock();
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
this.blockStatesInFlightLock.unlock();
|
||||||
return null;
|
return null;
|
||||||
} else {//Not a duplicate so create a new entry
|
} else {//Not a duplicate so create a new entry
|
||||||
modelId = this.modelTexture2id.size();
|
modelId = this.modelTexture2id.size();
|
||||||
@@ -928,7 +931,6 @@ public class ModelFactory {
|
|||||||
//TODO replace all of this with an atomic?
|
//TODO replace all of this with an atomic?
|
||||||
int size = this.blockStatesInFlight.size();
|
int size = this.blockStatesInFlight.size();
|
||||||
size += this.uploadResults.size();
|
size += this.uploadResults.size();
|
||||||
size += this.rawBakeResults.size();
|
|
||||||
size += this.biomeQueue.size();
|
size += this.biomeQueue.size();
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user