Skip to content

Game.BuildingLotRenderSystem

Assembly: Assembly-CSharp.dll
Namespace: Game.Rendering

Type: class

Base: GameSystemBase

Summary:
BuildingLotRenderSystem is an ECS system responsible for rendering overlay visuals for building lots, object collisions, net segments (elevated/airspace nets), and building terraform areas. It uses Burst-compiled jobs (IJobChunk and IJob) to iterate entity chunks and draw geometry (lines, dashed lines, circles, Bezier curves) into an OverlayRenderSystem.Buffer. The system respects editor vs runtime modes, rendering settings (hover / error / warning / owner colors), and entity temporary flags (Temp, Warning, Error) to decide which overlays to draw.


Fields

  • private ToolSystem m_ToolSystem
    Handles access to the current tool, selection and editor state. Used to determine whether editor mode is active and which entity is selected for terraform drawing.

  • private OverlayRenderSystem m_OverlayRenderSystem
    Reference to the overlay rendering system. The system obtains a drawing buffer from this system and writes overlay primitives into that buffer.

  • private EntityQuery m_LotQuery
    EntityQuery used to select entities representing lots/objects/nets that may need overlay rendering (Temp + one of Building/Extension/AssetStamp/Taxiway/Tree) and excluding Hidden/Deleted/Overridden. Also used to find entities flagged with Error or Warning.

  • private EntityQuery m_RenderingSettingsQuery
    EntityQuery used to fetch a singleton RenderingSettingsData if present (allows overriding default overlay colors).

  • private TypeHandle __TypeHandle
    Container struct that holds ComponentTypeHandle / ComponentLookup / BufferLookup instances used when scheduling jobs. Assigned on system creation for efficient job scheduling and access.

Properties

  • None (no public properties defined).

Constructors

  • public BuildingLotRenderSystem()
    Default constructor. Nothing special — the system initializes references in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes the system: obtains ToolSystem and OverlayRenderSystem instances, and constructs the m_LotQuery and m_RenderingSettingsQuery entity queries. Also prepares component lookups via __TypeHandle in OnCreateForCompiler.

  • protected override void OnUpdate()
    Main update method. Behavior:

  • Determines selected entity (editor selection) via ToolSystem.
  • Checks if there are entities matching m_LotQuery (lots to render).
  • Builds a RenderingSettingsData with defaults, replaced by the singleton if present.
  • Obtains an OverlayRenderSystem.Buffer and its job dependency.
  • If there are lots to render, schedules a Burst-compiled BuildingLotRenderJob (IJobChunk) that draws lot outlines, object collisions, and net overlays using component lookups and flags.
  • If a single entity is selected (editor), schedules a BuildingTerraformRenderJob (IJob) to draw terraform preview/area for the selected building prefab.
  • Adds the buffer writer dependency to the overlay system after scheduling.

  • protected override void OnCreateForCompiler()
    Internal helper executed at compile-time / system creation to assign query and type handle references (__AssignQueries and __AssignHandles).

  • private void __AssignQueries(ref SystemState state)
    Internal method for query assignment (called by OnCreateForCompiler). Present for compiler compatibility; typically sets up any EntityQueryBuilder usage.

  • private struct TypeHandle
    Holds ComponentTypeHandle, ComponentLookup, and BufferLookup instances used by jobs. Has an __AssignHandles(ref SystemState) method to initialize those handles from a SystemState.

  • private struct BuildingLotRenderJob : IJobChunk
    Burst-compiled job that iterates chunks matching the lot query. Key behaviors:

  • Reads component arrays: Transform, PrefabRef, Composition, Edge/EdgeGeometry, Node geometry types, Temp, Warning, Error, Owner, etc.
  • Uses ComponentLookup for prefab data: BuildingData, BuildingExtensionData, AssetStampData, ObjectGeometryData, NetCompositionData.
  • Uses BufferLookup for ServiceUpgradeBuilding to handle building extensions that reference other buildings.
  • Decides drawing color and alpha based on Error/Warning/Temp flags, editor mode and zones visibility.
  • Draws nets (DrawNets): handles elevated/airspace nets and draws segments / node segments when net elevation > 0.
  • Draws objects (DrawObjects): for building extensions, asset stamps, buildings and generic objects — draws lots or collision outlines depending on object flags (ExclusiveGround, Standing, Circular, etc.).
  • Uses overlay buffer methods: DrawLine, DrawDashedLine, DrawCircle, DrawDashedCurve, DrawLine with styles/widths to render overlays.
  • Honors TempFlags for create/delete/select/modify/replace/parent and Hidden flag to skip or change drawing (e.g., owner color when Parent flag present).

  • private struct BuildingTerraformRenderJob : IJob
    Burst-compiled job that draws terraform preview regions for a selected building prefab:

  • Uses ComponentLookup to read Transform, PrefabRef, ObjectGeometryData, BuildingTerraformData.
  • Uses BufferLookup to read AdditionalBuildingTerraformElement for extra terraform shapes.
  • Draws circular or rectangular terraform areas and a set of flat/smooth area outlines using magenta color into OverlayRenderSystem.Buffer.

  • Several private helper methods inside BuildingLotRenderJob:

  • DrawNets(in ArchetypeChunk, NativeArray, NativeArray, Color lotColor, bool checkTempFlags) — handles net overlay drawing.
  • DrawSegment(Color color, Segment segment) — draws dashed curves on segment halves with appropriate alpha depending on editor/zones visibility.
  • DrawObjects(in ArchetypeChunk, NativeArray, NativeArray, Color lotColor, bool checkTempFlags) — determines what each prefab should draw (lot, collision).
  • DrawLot(Color color, int2 lotSize, ObjectGeometryData objectGeometryData, float3 position, quaternion rotation) — draws lot outline (rectangle or circle) and editor orientation marker.
  • DrawCollision(Color color, ObjectGeometryData objectGeometryData, float3 position, quaternion rotation, float size) — draws collision outline as dashed Bezier curves (for circular) or dashed lines for rectangular bounds.

Usage Example

// Example snippet similar to the system's OnUpdate illustrating how overlay buffer + jobs are used.
// Place in a custom system derived from GameSystemBase (conceptual example).

[Preserve]
protected override void OnUpdate()
{
    // Get the currently selected entity when in editor mode
    Entity selected = m_ToolSystem.actionMode.IsEditor() ? m_ToolSystem.selected : Entity.Null;

    // Get overlay buffer & dependency from overlay render system
    JobHandle overlayDeps;
    OverlayRenderSystem.Buffer overlayBuffer = m_OverlayRenderSystem.GetBuffer(out overlayDeps);
    base.Dependency = JobHandle.CombineDependencies(base.Dependency, overlayDeps);

    // Prepare and schedule the lot rendering job (IJobChunk)
    var lotJob = new BuildingLotRenderJob
    {
        m_TransformType = InternalCompilerInterface.GetComponentTypeHandle<Game.Objects.Transform>(isReadOnly: true),
        // ... assign other handles/lookups via TypeHandle fields ...
        m_EditorMode = m_ToolSystem.actionMode.IsEditor(),
        m_ZonesVisible = (m_ToolSystem.activeTool != null && m_ToolSystem.activeTool.requireZones),
        m_RenderingSettingsData = renderingSettingsData,
        m_OverlayBuffer = overlayBuffer
    };
    base.Dependency = JobChunkExtensions.Schedule(lotJob, m_LotQuery, base.Dependency);

    // If an entity is selected, schedule terraform job (IJob)
    if (selected != Entity.Null)
    {
        var terraformJob = new BuildingTerraformRenderJob
        {
            m_TransformData = InternalCompilerInterface.GetComponentLookup<Game.Objects.Transform>(isReadOnly: true),
            m_PrefabRefData = InternalCompilerInterface.GetComponentLookup<PrefabRef>(isReadOnly: true),
            m_PrefabObjectGeometryData = InternalCompilerInterface.GetComponentLookup<ObjectGeometryData>(isReadOnly: true),
            m_PrefabBuildingTerraformData = InternalCompilerInterface.GetComponentLookup<BuildingTerraformData>(isReadOnly: true),
            m_PrefabAdditionalTerraform = InternalCompilerInterface.GetBufferLookup<AdditionalBuildingTerraformElement>(isReadOnly: true),
            m_Selected = selected,
            m_OverlayBuffer = overlayBuffer
        };
        base.Dependency = terraformJob.Schedule(base.Dependency);
    }

    // Let overlay system know we wrote to the buffer
    m_OverlayRenderSystem.AddBufferWriter(base.Dependency);
}

Notes and modder tips: - The system targets ECS and uses ComponentTypeHandle / ComponentLookup / BufferLookup; when integrating or copying code into a custom system, ensure handles are assigned via SystemState or the appropriate API (InternalCompilerInterface in the decompiled code). - Colors and opacity are taken from RenderingSettingsData if present; you can provide your own singleton to change overlay appearance. - The system is careful to skip drawing for Hidden/Deleted/Overridden entities and to respect TempFlags (so tools and temporary entity states are visualized correctly).