Skip to content

Game.AreaBorderRenderSystem

Assembly: Assembly-CSharp
Namespace: Game.Rendering

Type: class

Base: GameSystemBase

Summary:
AreaBorderRenderSystem is an ECS-based rendering system that draws area borders and area nodes as overlays. It queries Area entities (and related markers like Temp, Warning, Error, MapTile, Lot) and schedules a Burst-compiled job (AreaBorderRenderJob) to collect directed border segments and node positions, then issues draw calls into an OverlayRenderSystem buffer. The system respects editor vs in-game modes, per-prefab geometry flags (e.g., HiddenIngame), rendering settings (hover/error/warning/owner colors), dashed vs solid edges, and avoids double-drawing shared borders by building a hashset of directed edges. It uses Unity's Job/Chunk APIs for performance and coordinates with OverlayRenderSystem by obtaining and registering a buffer writer for the scheduled job.


Fields

  • private OverlayRenderSystem m_OverlayRenderSystem
    Holds the overlay renderer system used to draw lines/circles/dashed-lines. Obtained from the World in OnCreate.

  • private ToolSystem m_ToolSystem
    Reference to the ToolSystem used to determine editor vs ingame action mode (affects styling).

  • private EntityQuery m_AreaBorderQuery
    EntityQuery used to select Area entities (with optional Temp/Error/Warning) and exclude Hidden/Deleted for the update.

  • private EntityQuery m_RenderingSettingsQuery
    Query to obtain RenderingSettingsData singleton so colors can be overridden by settings.

  • private TypeHandle __TypeHandle
    Container for precomputed ComponentTypeHandle / BufferTypeHandle / ComponentLookup instances used to build the job's handles. Assigned in OnCreateForCompiler.

  • private struct Border
    Represents a directed edge between two float3 positions used to avoid drawing shared borders twice. Implements IEquatable. Equality compares both start and end positions; hashcode uses start position's hash.

  • private struct AreaBorderRenderJob
    A Burst-compiled IJob that:

  • Receives component/buffer handles, a list of archetype chunks, editor-mode flag and an OverlayRenderSystem buffer wrapper.
  • In Execute, counts nodes to preallocate hash sets, builds a NativeParallelHashSet of borders (directed edges), then iterates chunks to draw edges and nodes that are not present in the border set.
  • Implements AddBorders(ArchetypeChunk, NativeParallelHashSet) to insert directed edges for each area's node loop, and DrawBorders(ArchetypeChunk, NativeParallelHashSet, NativeParallelHashSet) to issue overlay draw calls (DrawEdge/DrawNode) respecting dashed/single-node cases, lot/edge shading, area flags (Slave/CounterClockwise/Complete), temp flags and geometry flags.
  • Uses helper draw methods DrawNode and DrawEdge that call OverlayRenderSystem.Buffer methods: DrawCircle, DrawLine, DrawDashedLine.

  • private struct TypeHandle
    Holds read-only ComponentTypeHandle/BufferTypeHandle/ComponentLookup used by the job:

  • Area, Lot, MapTile, Temp, Warning, Error, PrefabRef component handles
  • Node buffer type handle
  • ComponentLookup It has __AssignHandles(ref SystemState) to populate handles.

Properties

  • (none)

Constructors

  • public AreaBorderRenderSystem()
    Default constructor (empty). The system does most initialization in OnCreate / OnCreateForCompiler.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes the system: gets OverlayRenderSystem and ToolSystem from the World, builds the m_AreaBorderQuery (All: Area, Any: Temp|Error|Warning, None: Hidden|Deleted) and the m_RenderingSettingsQuery (RenderingSettingsData). Calls RequireForUpdate(m_AreaBorderQuery) so the system runs only when matching entities exist.

  • [Preserve] protected override void OnUpdate()
    Per-frame update:

  • Builds a RenderingSettingsData instance with default colors and overrides it from the m_RenderingSettingsQuery singleton if present.
  • Collects archetype chunks for m_AreaBorderQuery asynchronously into a NativeList.
  • Prepares and schedules an AreaBorderRenderJob, passing component handles obtained via InternalCompilerInterface.GetComponentTypeHandle / GetBufferTypeHandle / GetComponentLookup, the chunks, editor-mode flag (from m_ToolSystem.actionMode.IsEditor()), and the overlay buffer from m_OverlayRenderSystem.GetBuffer(out dependencies).
  • Ensures proper dependency combining, disposes the chunk list after the job, and registers the overlay buffer writer via m_OverlayRenderSystem.AddBufferWriter(jobHandle). Sets base.Dependency to the returned job handle.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler helper; in this decompiled code it creates and disposes an EntityQueryBuilder(Allocator.Temp). Present to satisfy internal codegen; real query handles are set up in OnCreate.

  • protected override void OnCreateForCompiler()
    Called by generated code path to assign query handles and type handles before runtime: calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef).

  • private void __AssignQueries(ref SystemState state)
    (duplicate compiler helper method in file) See above; present to satisfy codegen. (One is annotated AggressiveInlining.)

  • private void AddBorders(ArchetypeChunk chunk, NativeParallelHashSet<Border> borderMap) (inside AreaBorderRenderJob)
    Collects directed edges from Area entity node buffers into borderMap. Skips slave areas and areas whose prefab geometry is hidden in game (unless editor mode). Respects AreaFlags.CounterClockwise and AreaFlags.Complete to produce correct directed segments.

  • private void DrawBorders(ArchetypeChunk chunk, NativeParallelHashSet<Border> borderMap, NativeParallelHashSet<float3> nodeMap) (inside AreaBorderRenderJob)
    Iterates areas in a chunk and issues draw calls for edges/nodes if they are not present in borderMap (so outermost/unique edges are drawn). Applies styling decisions: dashed lines for in-game MapTile edges, half-bright edges for Lot boundaries, special colors for Error/Warning/Hovered/Owner, and only draws nodes once using nodeMap.

  • private void DrawNode(Color color, float3 position, AreaGeometryData geometryData, OverlayRenderSystem.StyleFlags styleFlags) (inside AreaBorderRenderJob)
    Wrapper to draw a node as a circle using geometryData.m_SnapDistance * 0.3f.

  • private void DrawEdge(Color color, float3 startPos, float3 endPos, AreaGeometryData geometryData, bool dashedLines, OverlayRenderSystem.StyleFlags styleFlags) (inside AreaBorderRenderJob)
    Wrapper to draw either a dashed or solid line segment; dashed line parameters are derived from segment length and geometryData.m_SnapDistance.

Usage Example

// AreaBorderRenderSystem already obtains systems and sets up queries in OnCreate.
// Example: how the system initializes overlay and tool system (similar to real code)
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_OverlayRenderSystem = base.World.GetOrCreateSystemManaged<OverlayRenderSystem>();
    m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();

    // Build the query used to drive updates
    m_AreaBorderQuery = GetEntityQuery(new EntityQueryDesc
    {
        All = new ComponentType[1] { ComponentType.ReadOnly<Area>() },
        Any = new ComponentType[3]
        {
            ComponentType.ReadOnly<Temp>(),
            ComponentType.ReadOnly<Error>(),
            ComponentType.ReadOnly<Warning>()
        },
        None = new ComponentType[2]
        {
            ComponentType.ReadOnly<Hidden>(),
            ComponentType.ReadOnly<Deleted>()
        }
    });

    m_RenderingSettingsQuery = GetEntityQuery(ComponentType.ReadOnly<RenderingSettingsData>());

    RequireForUpdate(m_AreaBorderQuery);
}

If you need, I can also: - Generate API-style docs for the nested AreaBorderRenderJob and Border types. - Produce a short diagram or sequence explaining how borders are collected and then drawn (useful when debugging overlay duplicates).