use of io.xol.chunkstories.api.workers.Task in project chunkstories by Hugobros3.
the class ConverterWorkers method dropAll.
public void dropAll() {
CompoundFence readyAll = new CompoundFence();
CompoundFence doneAll = new CompoundFence();
SimpleFence atSignal = new SimpleFence();
for (int i = 0; i < workers.length; i++) {
SimpleFence ready = new SimpleFence();
readyAll.add(ready);
SimpleFence done = new SimpleFence();
doneAll.add(done);
scheduleTask(new Task() {
@Override
protected boolean task(TaskExecutor taskExecutor) {
ready.signal();
atSignal.traverse();
ConverterWorkerThread cwt = (ConverterWorkerThread) taskExecutor;
for (ChunkHolder holder : cwt.registeredCS_Holders) {
holder.unregisterUser(cwt);
cwt.chunksAquired--;
}
for (Heightmap summary : cwt.registeredCS_Summaries) summary.unregisterUser(cwt);
cwt.registeredCS_Summaries.clear();
cwt.registeredCS_Holders.clear();
done.signal();
return true;
}
});
}
readyAll.traverse();
atSignal.signal();
doneAll.traverse();
}
use of io.xol.chunkstories.api.workers.Task in project chunkstories by Hugobros3.
the class ChunkOcclusionUpdater method requestUpdate.
public Fence requestUpdate() {
unbakedUpdates.incrementAndGet();
Task fence;
taskLock.lock();
if (task == null || task.isDone() || task.isCancelled()) {
task = new TaskComputeChunkOcclusion(chunk);
chunk.getWorld().getGameContext().tasks().scheduleTask(task);
}
fence = task;
taskLock.unlock();
return fence;
}
use of io.xol.chunkstories.api.workers.Task in project chunkstories by Hugobros3.
the class WorkerThread method run.
public void run() {
while (true) {
// Aquire a work permit
pool.tasksCounter.acquireUninterruptibly();
// If one such permit was found to exist, assert a task is readily avaible
Task task = pool.tasksQueue.poll();
assert task != null;
// Only die task can break the loop
if (task == pool.DIE)
break;
boolean result = task.run(this);
pool.tasksRan++;
// Depending on the result we either reschedule the task or decrement the counter
if (result == false)
pool.rescheduleTask(task);
else
pool.tasksQueueSize.decrementAndGet();
}
death.signal();
cleanup();
}
use of io.xol.chunkstories.api.workers.Task in project chunkstories by Hugobros3.
the class WorkerThreadPool method dumpTasks.
public void dumpTasks() {
System.out.println("dumping tasks");
// Hardcoding a security because you can fill the queue faster than you can iterate it
int hardLimit = 500;
Iterator<Task> i = this.tasksQueue.iterator();
while (i.hasNext()) {
Task task = i.next();
hardLimit--;
if (hardLimit < 0)
return;
System.out.println(task);
}
}
use of io.xol.chunkstories.api.workers.Task in project chunkstories by Hugobros3.
the class ChunkRenderDataHolder method destroy.
/**
* Frees the ressources allocated to this ChunkRenderData
*/
public void destroy() {
noDrawDeleteConflicts.acquireUninterruptibly();
isDestroyed = true;
currentData = null;
// Deallocate the VBO
if (verticesObject != null)
verticesObject.destroy();
noDrawDeleteConflicts.release();
Task task = this.task;
if (task != null)
task.cancel();
}
Aggregations