Search in sources :

Example 1 with TrivialFence

use of io.xol.chunkstories.util.concurrency.TrivialFence in project chunkstories by Hugobros3.

the class VertexBufferGL method uploadData.

/* (non-Javadoc)
	 * @see io.xol.engine.graphics.geometry.VertexBuffer#uploadData(io.xol.chunkstories.renderer.buffers.ByteBufferPool.RecyclableByteBuffer)
	 */
@Override
public Fence uploadData(RecyclableByteBuffer dataToUpload) {
    if (glID == -2)
        throw new RuntimeException("Illegal operation : Attempted to upload data to a destroyed VerticesObject !");
    // Queue for immediate upload
    if (Client.getInstance().getGameWindow().isMainGLWindow()) {
        Object replacing = waitingToUploadMainThread;
        waitingToUploadMainThread = dataToUpload;
        if (replacing != null && replacing != dataToUpload && replacing instanceof RecyclableByteBuffer) {
            // System.out.println("Watch out, uploading two RecyclableByteBuffer in a row, the first one is getting recycled early to prevent locks");
            RecyclableByteBuffer rcb = (RecyclableByteBuffer) replacing;
            rcb.recycle();
        }
        dataSize = dataToUpload.accessByteBuffer().limit();
        return new TrivialFence();
    }
    // This is a deffered call
    return setAsyncDataPendingUpload(dataToUpload);
// pendingAsyncUpload = dataToUpload;
// return false;
}
Also used : TrivialFence(io.xol.chunkstories.util.concurrency.TrivialFence) RecyclableByteBuffer(io.xol.chunkstories.api.rendering.vertex.RecyclableByteBuffer)

Example 2 with TrivialFence

use of io.xol.chunkstories.util.concurrency.TrivialFence in project chunkstories by Hugobros3.

the class ChunkLightBaker method requestLightningUpdate.

@Override
public Fence requestLightningUpdate() {
    unbakedUpdates.incrementAndGet();
    if (world instanceof WorldTool) {
        WorldTool tool = (WorldTool) world;
        if (!tool.isLightningEnabled()) {
            // System.out.println("too soon");
            return new TrivialFence();
        }
    }
    Task fence;
    taskLock.lock();
    if (task == null || task.isDone() || task.isCancelled()) {
        task = new TaskLightChunk(chunk, true);
        chunk.getWorld().getGameContext().tasks().scheduleTask(task);
    }
    fence = task;
    taskLock.unlock();
    return fence;
}
Also used : TrivialFence(io.xol.chunkstories.util.concurrency.TrivialFence) Task(io.xol.chunkstories.api.workers.Task) WorldTool(io.xol.chunkstories.world.WorldTool)

Aggregations

TrivialFence (io.xol.chunkstories.util.concurrency.TrivialFence)2 RecyclableByteBuffer (io.xol.chunkstories.api.rendering.vertex.RecyclableByteBuffer)1 Task (io.xol.chunkstories.api.workers.Task)1 WorldTool (io.xol.chunkstories.world.WorldTool)1