Skip to content

Commit

Permalink
add way to specialize WorkerState and Ray creation
Browse files Browse the repository at this point in the history
TODO: add PluginAPI
  • Loading branch information
Maximilian Stiede committed Mar 6, 2023
1 parent 6c89994 commit abd7168
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.function.BiConsumer;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

/**
* A tile based renderer. Simply call {@code submitTiles} to submit a frame's worth of tiles to the work queue.
Expand Down Expand Up @@ -57,6 +58,9 @@ public void setPostRender(BooleanSupplier callback) {
postRender = callback;
}

protected Supplier<WorkerState> workerStateFactory = WorkerState::new;
protected Supplier<Ray> rayFactory = Ray::new;

/**
* Create and submit tiles to the rendering pool.
* Await for these tiles to finish rendering with {@code manager.pool.awaitEmpty()}.
Expand All @@ -69,8 +73,8 @@ protected void submitTiles(DefaultRenderManager manager, BiConsumer<WorkerState,

cachedTiles.forEach(tile ->
manager.pool.submit(worker -> {
WorkerState state = new WorkerState();
state.ray = new Ray();
WorkerState state = workerStateFactory.get();
state.ray = rayFactory.get();
state.ray.setNormal(0, 0, -1);
state.random = worker.random;

Expand Down

0 comments on commit abd7168

Please sign in to comment.