Game.Rendering.AreaRenderSystem
Assembly:
Assembly-CSharp (typical game assembly)
Namespace:
Game.Rendering
Type:
class
Base:
GameSystemBase
Summary:
AreaRenderSystem is responsible for rendering area-related overlays in the game (area name meshes, city boundary mesh, and batched area visualizations). It collects data from AreaBufferSystem and AreaBatchSystem, builds indirect-draw argument buffers, and issues GPU-instanced draws (Graphics.RenderMeshIndirect) per camera. The system registers a callback with RenderPipelineManager.beginContextRendering to perform its rendering outside the usual system Update loop.
Fields
-
private RenderingSystem m_RenderingSystem
Reference to the global RenderingSystem (used to check rendering flags such as hideOverlay and renderer priorities). -
private AreaBufferSystem m_AreaBufferSystem
Reference to the AreaBufferSystem which provides per-area compute/graphics buffers and "name" meshes/materials. -
private AreaBatchSystem m_AreaBatchSystem
Reference to the AreaBatchSystem that provides batched area instance buffers, colors and visibility indices. -
private CityBoundaryMeshSystem m_CityBoundaryMeshSystem
Reference to the system providing the city boundary mesh and material. -
private ToolSystem m_ToolSystem
Reference to the active ToolSystem to determine whether the currently active tool requires area visuals. -
private int m_AreaTriangleBuffer
Shader property ID for the triangle instance buffer ("colossal_AreaTriangleBuffer"). -
private int m_AreaBatchBuffer
Shader property ID for the per-batch instance buffer ("colossal_AreaBatchBuffer"). -
private int m_AreaBatchColors
Shader property ID for the batch colors buffer ("colossal_AreaBatchColors"). -
private int m_VisibleIndices
Shader property ID for visible indices buffer ("colossal_VisibleIndices"). -
private Mesh m_AreaMesh
A small Mesh used as the instance geometry for area triangle volumes. Created on demand via CreateMesh(). -
private GraphicsBuffer m_ArgsBuffer
GraphicsBuffer used to store indirect draw arguments (GraphicsBuffer.Target.IndirectArguments) for multiple draws. -
private List<GraphicsBuffer.IndirectDrawIndexedArgs> m_ArgsArray
Temporary managed list of indirect draw argument structures that are uploaded to m_ArgsBuffer before rendering.
Properties
- None (this system exposes no public properties)
Constructors
public AreaRenderSystem()
Default constructor. The system is attributed with [Preserve] on lifecycle methods; instantiation is handled by the game's world/system management.
Methods
-
protected override void OnCreate() : System.Void
Initializes references to other systems (RenderingSystem, AreaBufferSystem, AreaBatchSystem, CityBoundaryMeshSystem, ToolSystem), fetches shader property IDs (colossal_*), and registers the Render method with RenderPipelineManager.beginContextRendering so area rendering is invoked each frame/context rendering. -
protected override void OnDestroy() : System.Void
Unregisters the Render callback and cleans up resources: destroys m_AreaMesh (if created) and releases m_ArgsBuffer (if allocated). Calls base.OnDestroy(). -
protected override void OnUpdate() : System.Void
Empty override — this system does its work in the Render callback rather than in Update. -
private unsafe void Render(ScriptableRenderContext context, List<Camera> cameras) : System.Void
Main rendering routine. Steps (high level): - Early-out when nothing to draw.
- If overlays are enabled, draw "name" meshes for each AreaType (using Graphics.DrawMesh per-submesh and per-camera).
- Draw city boundary mesh per-camera (if available).
- If the active tool requires area visuals, enqueue area buffers for indirect rendering.
- Iterate AreaBatchSystem batches and enqueue them for indirect rendering, setting buffer bindings (instance data, colors, visible indices) on the material.
- Ensure m_AreaMesh exists (CreateMesh) and ensure m_ArgsBuffer is allocated/large enough for the number of indirect draws.
- Build a list of GraphicsBuffer.IndirectDrawIndexedArgs entries (m_ArgsArray) for each indirect draw and upload them to m_ArgsBuffer.
- Issue Graphics.RenderMeshIndirect calls per camera using RenderParams (sets material, worldBounds, camera, rendererPriority).
-
Notes: preview cameras are skipped for batch rendering; uses per-camera RenderParams to render in the correct context; handles resizing/recreating the indirect args buffer as needed.
-
private static Mesh CreateMesh() : Mesh
Creates and returns a small Mesh (named "Area triangle volume") with 6 vertices and 24 indices representing a triangle-volume primitive used as instance geometry for area rendering. This mesh is created lazily the first time an indirect draw needs it.
Usage Example
// Ensure the AreaRenderSystem is created/available in your mod/system initialization:
var areaRender = World.GetOrCreateSystemManaged<Game.Rendering.AreaRenderSystem>();
// The system registers its render callback automatically in OnCreate,
// so no further setup is required to get area overlays drawn.