Game.Rendering.OverlayInfomodeSystem
Assembly: Assembly-CSharp
Namespace: Game.Rendering
Type: class
Base: GameSystemBase
Summary:
OverlayInfomodeSystem is responsible for producing and updating the in-game overlay (infoview / heatmap) textures used by terrain and water render systems. It gathers various cell-map data (ground water, pollution, wind, natural resources, land value, population, availability info, telecom coverage, etc.), schedules Burst-compiled Unity.Jobs to write the heatmap pixel data into Texture2D raw buffers, and binds those textures to the TerrainRenderSystem and WaterRenderSystem. The system contains many nested job structs (ClearJob, GroundWaterJob, GroundPollutionJob, NoisePollutionJob, AirPollutionJob, WindJob, TelecomCoverageJob, FertilityJob, OreJob, OilJob, FishJob, LandValueJob, PopulationJob, AttractionJob, CustomerJob, WorkplaceJob, ServiceJob, GroundWaterPollutionJob) that convert underlying grid data into RGBA or half4 texture buffers. It also manages texture reinitialization when heatmap sizes change and coordinates JobHandle dependencies with the data systems it reads from.
Fields
-
private TerrainRenderSystem m_TerrainRenderSystem
Reference to the TerrainRenderSystem used to set override overlay map and extra maps for terrain rendering. -
private WaterRenderSystem m_WaterRenderSystem
Reference to the WaterRenderSystem used to set override overlay map, flow/extra maps and pollution mask for water rendering. -
private GroundWaterSystem m_GroundWaterSystem
Reference to the system that supplies ground water cell-map data. -
private GroundPollutionSystem m_GroundPollutionSystem
Reference to the system providing ground pollution data. -
private NoisePollutionSystem m_NoisePollutionSystem
Reference to the system providing noise pollution data. -
private AirPollutionSystem m_AirPollutionSystem
Reference to the system providing air pollution data. -
private WindSystem m_WindSystem
Reference to the wind system (used to build a float16/half4 wind texture). -
private CitySystem m_CitySystem
Reference to CitySystem, used (for example) to get the current city Entity when computing resource maps. -
private TelecomPreviewSystem m_TelecomCoverageSystem
Reference to telecom coverage preview system (used for telecom heatmap). -
private NaturalResourceSystem m_NaturalResourceSystem
Reference to natural resource data (ore, oil, fish, fertility). -
private LandValueSystem m_LandValueSystem
Reference to land value grid data. -
private PopulationToGridSystem m_PopulationToGridSystem
Reference to population grid data. -
private AvailabilityInfoToGridSystem m_AvailabilityInfoToGridSystem
Reference to availability/attraction/customer/workplace/service grid data. -
private ToolSystem m_ToolSystem
Reference to the ToolSystem (used to check whether an infoview is active). -
private EntityQuery m_InfomodeQuery
EntityQuery used to find InfomodeActive + InfoviewHeatmapData entities (active heatmaps). -
private EntityQuery m_HappinessParameterQuery
EntityQuery used to fetch CitizenHappinessParameterData singleton (used for multipliers for pollution/noise heatmaps). -
private Texture2D m_TerrainTexture
Texture2D used as the overlay/heatmap texture for terrain. -
private Texture2D m_WaterTexture
Texture2D used as the overlay texture for water maps. -
private Texture2D m_WindTexture
Texture2D (R16G16B16A16_SFloat) used as wind vector data (half4) overlay for terrain and water extra map. -
private JobHandle m_Dependency
Last scheduled JobHandle dependency used internally to manage async jobs and ensure Apply/ApplyTexture calls are done after jobs complete. -
private TypeHandle __TypeHandle
Internal cached type handles / buffer lookups used for reading components/buffers in jobs or OnUpdate.
Properties
- None (no public properties exposed by this system)
Constructors
public OverlayInfomodeSystem()
Default constructor. System initialization logic is performed in OnCreate. The constructor itself is present but empty.
Methods
-
protected override void OnCreate()
Initializes references to dependent systems (terrain, water, pollution, wind, city, natural resource, etc.), creates the overlay Texture2D instances (m_TerrainTexture, m_WaterTexture, m_WindTexture) and sets up the entity queries used to find active infoview heatmaps and happiness parameters. Textures are created with HideAndDontSave and Clamp wrap mode. This is where the system obtains World-managed systems it needs. -
protected override void OnDestroy()
Cleans up textures by calling CoreUtils.Destroy on the created Texture2D objects and forwards to base.OnDestroy(). -
public void ApplyOverlay()
Checks whether the render systems currently have the overlay textures assigned and, if so, completes the dependency JobHandle and calls Texture2D.Apply() on the corresponding textures (m_TerrainTexture, m_WindTexture, m_WaterTexture). This forces GPU upload of modified raw texture data after the scheduled jobs have completed. -
private NativeArray<byte> GetTerrainTextureData<T>(CellMapData<T> cellMapData) where T : struct, ISerializable
Convenience overload that forwards to GetTerrainTextureData(int2) using the CellMapData texture size. -
private NativeArray<byte> GetTerrainTextureData(int2 size)
Ensures m_TerrainTexture matches requested size (reinitializes if necessary), clears or assigns the terrain overlay in the TerrainRenderSystem, and schedules the ClearJob to zero the texture buffer when setting a new terrain overlay. Returns the raw byte buffer of the terrain texture (RGBA32 raw data). -
private NativeArray<byte> GetWaterTextureData<T>(CellMapData<T> cellMapData) where T : struct, ISerializable
Convenience overload that forwards to GetWaterTextureData(int2) using the CellMapData texture size. -
private NativeArray<byte> GetWaterTextureData(int2 size)
Ensures m_WaterTexture matches requested size (reinitializes if necessary), clears or assigns the water overlay in the WaterRenderSystem, and schedules the ClearJob to zero the texture buffer when setting a new water overlay. Returns the raw byte buffer of the water texture (RGBA32 raw data). -
protected override void OnUpdate()
Main update loop: clears overlay bindings first, then queries for active InfoviewHeatmapData entries. For each active heatmap it: - selects the appropriate nested job struct to produce pixel data for that heatmap type,
- requests read-only CellMapData
from the corresponding data system (receiving a JobHandle dependency), - calls GetTerrainTextureData / GetWaterTextureData to obtain the texture buffer(s) and schedule ClearJob if needed,
- schedules the data job (with JobHandle.CombineDependencies) to write into the texture buffer,
- registers the job handle as a reader on the data system (e.g. m_GroundWaterSystem.AddReader(jobHandle)),
-
stores the last dependency and updates base.Dependency. Specific behaviors: some heatmaps write both terrain and water textures (air/noise/oil/telecom etc.) by scheduling the job twice with the water flag set; wind uses a half4 wind texture and sets overlayExtramap and arrow masks; water flow and water pollution configure water render overlayExtramap and pollution mask directly without jobs.
-
private void __AssignQueries(ref SystemState state)
Internal compiler-generated method—currently empty in this build but used at OnCreateForCompiler to ensure queries/handles are assigned for the ahead-of-time compiled version. -
protected override void OnCreateForCompiler()
Called by the compiler-managed lifecycle path: calls __AssignQueries and assigns component/buffer handles via __TypeHandle.__AssignHandles. -
private struct TypeHandle
Holds ComponentTypeHandle / BufferLookup fields for InfoviewHeatmapData, InfomodeActive and CityModifier buffer lookup and an __AssignHandles(...) method to initialize them from SystemState. This is used to fetch internal ComponentTypeHandles and buffer lookups in OnCreateForCompiler and OnUpdate. -
Nested job structs (Burst compiled) — these are private structs implementing IJob; each converts a specific grid/cell-map to texture data:
- ClearJob — clears a NativeArray
(sets all bytes to zero). - GroundWaterJob — writes ground water amount into the appropriate RGBA channel.
- GroundPollutionJob — writes ground pollution scaled by a multiplier into channel.
- NoisePollutionJob — writes noise pollution (terrain and water) with multiplier and optional water channel index.
- AirPollutionJob — writes air pollution similarly to noise.
- WindJob — writes wind vectors into a NativeArray
(m_WindTexture). - TelecomCoverageJob — writes telecom coverage quality into channel(s).
- FertilityJob — writes fertility (natural resource) into channel.
- OreJob — writes ore resource amount adjusted by city modifiers into channel.
- OilJob — writes oil resource amount (supports water & terrain channels) and applies city modifiers if present.
- FishJob — writes fish resource into water channel.
- LandValueJob — writes land value scaled into channel.
- PopulationJob — writes population density into channel.
- AttractionJob, CustomerJob, WorkplaceJob, ServiceJob — write availability/usage info components into channels.
- GroundWaterPollutionJob — writes ground water pollution fraction into channel.
Each job reads the corresponding CellMapData
and writes bytes (0–255) into the RGBA texture buffer using channel indices derived from InfomodeActive indices.
Usage Example
// Example: Force a texture upload for the overlay after the system has scheduled jobs.
// This could be called from UI/tool code once you've enabled an infoview or after
// modifying underlying data. Obtain the system from the World and call ApplyOverlay.
var overlaySystem = World.GetExistingSystemManaged<Game.Rendering.OverlayInfomodeSystem>();
if (overlaySystem != null)
{
// Ensure any scheduled jobs are completed and the textures uploaded to GPU.
overlaySystem.ApplyOverlay();
}
// Typical system override example (for a derived/custom system)
[UnityEngine.Scripting.Preserve]
protected override void OnCreate()
{
base.OnCreate();
// The OverlayInfomodeSystem is initialized by the world — no extra setup required here.
}
Notes / Implementation details:
- The system uses raw Texture2D.GetRawTextureData to fill pixel buffers from jobs; ApplyOverlay() must be called (or the system will call Texture.Apply internally) after jobs complete to upload to GPU.
- Several heatmaps write both a terrain texture and a separate water texture; some use an "extra map" (overlayExtramap) or the wind float texture to show vector arrows.
- JobHandle dependencies are combined with data-system provided handles and registered back to those systems via AddReader so that the data systems know that this system is reading their buffers.
- The system relies on InfoviewHeatmapData / InfomodeActive components to indicate which heatmaps/channels to populate.