Search in sources :

Example 1 with Task

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();
}
Also used : CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) Task(io.xol.chunkstories.api.workers.Task) TaskExecutor(io.xol.chunkstories.api.workers.TaskExecutor) Heightmap(io.xol.chunkstories.api.world.heightmap.Heightmap) ChunkHolder(io.xol.chunkstories.api.world.chunk.ChunkHolder) SimpleFence(io.xol.chunkstories.util.concurrency.SimpleFence)

Example 2 with Task

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;
}
Also used : Task(io.xol.chunkstories.api.workers.Task)

Example 3 with Task

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();
}
Also used : Task(io.xol.chunkstories.api.workers.Task)

Example 4 with Task

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);
    }
}
Also used : Task(io.xol.chunkstories.api.workers.Task)

Example 5 with 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();
}
Also used : Task(io.xol.chunkstories.api.workers.Task)

Aggregations

Task (io.xol.chunkstories.api.workers.Task)7 TaskExecutor (io.xol.chunkstories.api.workers.TaskExecutor)1 ChunkHolder (io.xol.chunkstories.api.world.chunk.ChunkHolder)1 Heightmap (io.xol.chunkstories.api.world.heightmap.Heightmap)1 CompoundFence (io.xol.chunkstories.util.concurrency.CompoundFence)1 SimpleFence (io.xol.chunkstories.util.concurrency.SimpleFence)1 TrivialFence (io.xol.chunkstories.util.concurrency.TrivialFence)1 WorldTool (io.xol.chunkstories.world.WorldTool)1 ClientChunk (io.xol.chunkstories.world.chunk.ClientChunk)1