z_mirror/PipeVisualizer

git clone https://git.raiguard.me/z_mirror/PipeVisualizer

Caleb HeuerActually write out a plan and get some details downf27292f

main
3.9 KiB103 linesraw

Goal

Visualize pipe connections with lines and arrows, and visualize "complex" (non-pipe) entities with colored boxes.

Constraints

  • Minimal UPS impact
    • Spread visualization over multiple ticks
    • Scale rate of visualization by number of active visualizations
    • Minimize creation and destruction of LuaRendering objects
  • Update in real-time as entities are modified
    • Fluid system IDs will need to be migrated
    • This might need to be done over multiple ticks as well - consider simply removing and re-iterating the affected systems
  • Two visualization modes
    • System: Given a starting entity, walk the fluid system and visualize each entity's connections to this system.
    • Overlay: Visualize all systems on all visible entities.

Definitions

  • Simple entity: Entity of type pipe, pipe-to-ground, or infinity-pipe.
  • Complex entity: All other entity types.

Visualzation

Simple entities

Simple entities are visualized with a sprite representing the entity's connections. This sprite is determined by binary encoding the directions of that entity's connection. The color is simply the fluid system's assigned color.

Complex entities

Complex entities are visualized with a translucent box matched to their bounding box.

Box color depends on the current color setting:

  • By fluid: Fluid prototype order (lower is better)
  • By system: Generated color index (lower is better)

We are unable to style the entity boxes well because LuaRendering cannot scale sprites like GUI styles can. Potential solution would be to add this draw mode to LuaRendering.

Connection arrows

Connection arrows represent the flow_direction for a given connection. They are drawn for every connection on complex entities, and non-I/O connections for simple entities. The arrow is positioned halfway between the position and target_position for the connection.

Underground connections

Underground connections are visualized by drawing a dashed line between the two entities. Because the PipeConnection does not contain the target owner's connection position, the engine will need to assemble the entity data for the target owner before the visualization can occur.

There are several potential options for doing this:

  • Create N sprites for N tiles between the entities (current method, slow!)
  • Determine max possible underground connection length in data-final-fixes and create sprites for each length (best non-c++ solution, could be slow with certain modpacks)
  • Create separate sprites for connection lengths up to an arbitrary constant (say, 100) and ignore ones longer than that (easiest, fastest, but could be bad in certain mods)
  • Add sprite tiling support to LuaRendering (hardest, best solution)

Iteration

Entities are iterated over time to eliminate long hangs. The rate of visualization will be scaled based on the number of players currently visualizing.

Specific fluid system

Pressing H on a fluid-connectable entity will visualize all of the entities in that fluid system.

if mode is overlay then return
for neighbour in entity
  push entity to queue for iteration

Overlay

Pressing Shift + H will visualize all of the entities visible to the player at max zoom level. As the player moves, entities are searched and added to the queue to be visualized.

Rendering architecture

Renderer module contains methods for drawing all of the requisite components:

  • Simple entity connection lines
  • Complex entity box
  • Connection arrows
  • Underground connection dashes
  • Update color of primary entity object and/or a fluid system's connection objects

LuaRendering performance is at its worst when creating and destroying objects. To migitate this, create a shared cache of render objects and re-use as many as possible. Cache can be implemented as a queue for O(1) appending and removing.

All required render objects are sprites, so it should be unnecessary to store the object's type.

1# Goal
2
3Visualize pipe connections with lines and arrows, and visualize "complex"
4(non-pipe) entities with colored boxes.
5
6# Constraints
7
8- Minimal UPS impact
9  - Spread visualization over multiple ticks
10  - Scale rate of visualization by number of active visualizations
11  - Minimize creation and destruction of LuaRendering objects
12- Update in real-time as entities are modified
13  - Fluid system IDs will need to be migrated
14  - This might need to be done over multiple ticks as well - consider simply removing and re-iterating the affected systems
15- Two visualization modes
16  - System: Given a starting entity, walk the fluid system and visualize each entity's connections to this system.
17  - Overlay: Visualize all systems on all visible entities.
18
19# Definitions
20
21- **Simple entity:** Entity of type `pipe`, `pipe-to-ground`, or `infinity-pipe`.
22- **Complex entity:** All other entity types.
23
24# Visualzation
25
26## Simple entities
27
28Simple entities are visualized with a sprite representing the entity's
29connections. This sprite is determined by binary encoding the directions of
30that entity's connection. The color is simply the fluid system's assigned
31color.
32
33## Complex entities
34
35Complex entities are visualized with a translucent box matched to their
36bounding box.
37
38Box color depends on the current color setting:
39- By fluid: Fluid prototype order (lower is better)
40- By system: Generated color index (lower is better)
41
42We are unable to style the entity boxes well because LuaRendering cannot scale
43sprites like GUI styles can. Potential solution would be to add this draw mode
44to LuaRendering.
45
46## Connection arrows
47
48Connection arrows represent the `flow_direction` for a given connection. They
49are drawn for every connection on complex entities, and non-I/O connections for
50simple entities. The arrow is positioned halfway between the `position` and
51`target_position` for the connection.
52
53## Underground connections
54
55Underground connections are visualized by drawing a dashed line between the two
56entities. Because the PipeConnection does not contain the target owner's
57connection position, the engine will need to assemble the entity data for the
58target owner before the visualization can occur.
59
60There are several potential options for doing this:
61- Create N sprites for N tiles between the entities (current method, slow!)
62- Determine max possible underground connection length in data-final-fixes and create sprites for each length (best non-c++ solution, could be slow with certain modpacks)
63- Create separate sprites for connection lengths up to an arbitrary constant (say, 100) and ignore ones longer than that (easiest, fastest, but could be bad in certain mods)
64- Add sprite tiling support to LuaRendering (hardest, best solution)
65
66# Iteration
67
68Entities are iterated over time to eliminate long hangs. The rate of
69visualization will be scaled based on the number of players currently
70visualizing.
71
72## Specific fluid system
73
74Pressing `H` on a fluid-connectable entity will visualize all of the entities
75in that fluid system.
76
77```
78if mode is overlay then return
79for neighbour in entity
80  push entity to queue for iteration
81```
82
83## Overlay
84
85Pressing `Shift + H` will visualize all of the entities visible to the player
86at max zoom level. As the player moves, entities are searched and added to the
87queue to be visualized.
88
89# Rendering architecture
90
91`Renderer` module contains methods for drawing all of the requisite components:
92- Simple entity connection lines
93- Complex entity box
94- Connection arrows
95- Underground connection dashes
96- Update color of primary entity object and/or a fluid system's connection objects
97
98LuaRendering performance is at its worst when creating and destroying objects.
99To migitate this, create a shared cache of render objects and re-use as many as
100possible. Cache can be implemented as a queue for O(1) appending and removing.
101
102All required render objects are sprites, so it should be unnecessary to store
103the object's type.