@@ -20,11 +20,17 @@ client/server synchronization.
2020
2121## Visuals
2222
23- Visuals are the analog to Renderers in vanilla Minecraft. Each Entity/BlockEntity/Effect that is rendered will have a
24- corresponding Visual. This way, Visuals can maintain state independent of the client representation of the game object,
23+ Visuals are the analog to Renderers in vanilla Minecraft. Each game object that is rendered will have a
24+ corresponding Visual object. This way, Visuals can maintain state independent of the client representation of the game
25+ object,
2526and update in parallel to other Visuals of the same type.
2627
27- Statefulness and parallelism are the core motivation behind this abstraction.
28+ Statefulness and parallelism are the core motivations behind this abstraction.
29+
30+ ::: danger IMPLEMENTATION CONTRACT
31+ Your Visual _ must_ be in a correct state upon construction, where all created Instances are be at their expected
32+ position. The most common bug when implementing Visuals is having your instances appear at the render origin.
33+ :::
2834
2935## Instances
3036
@@ -37,6 +43,11 @@ instance shader.
3743
3844Users of Flywheel are encouraged to only update Instances when necessary.
3945
46+ ::: warning
47+ Ensure you ` .delete() ` all Instances you create when your Visual is deleted. Failure to do so will result in orphaned
48+ instances that continue to be rendered.
49+ :::
50+
4051## Render Origin
4152
4253The render origin is an integer coordinate in world space which serves as the origin for rendering.
@@ -46,3 +57,25 @@ Such an approach is not viable for Flywheel, as that would require every instanc
4657Flywheel maintains a render origin that is nearby, but not necessarily exactly at, the camera position. As the camera
4758moves in the level Flywheel will update the render origin once it gets too far away. All instances are deleted and all
4859visuals are recreated when the render origin updates.
60+
61+ ::: tip
62+ To map from world space to render space, subtract the render origin from the world space position. e.g.
63+
64+ ``` java
65+ BlockPos renderSpacePos = worldSpacePos. subtract(visualizationContext. renderOrigin());
66+ ```
67+
68+ :::
69+
70+ ## Plans
71+
72+ Plans are Flywheel's way to expose the thread pool to Visuals. Plans are created once, and executed many times.
73+ When executed, Plans receive a generic context object, a reference to the Executor they're running on, and a Runnable
74+ to call when all the work in the Plan is complete. This simple abstraction allows for incredibly complex composition
75+ of tasks and allows for easy parallelization of work.
76+
77+ Implementing ` DynamicVisual ` and ` TickableVisual ` requires you to construct Plans that will be executed every frame or
78+ tick, respectively.
79+
80+ _ Most_ Visuals will not need the full complexity of Plans, so the Flywheel lib provides ` Simple ` counterparts to both
81+ interfaces.
0 commit comments