Skip to content

Game.Areas.AreaResourceSystem

Assembly:
Namespace: Game.Areas

Type: class

Base: GameSystemBase

Summary: AreaResourceSystem is an ECS system responsible for tracking and updating natural and map feature resources inside area entities (forests, ore, oil, fertile land, fish, etc.). It collects updated areas (from brushes, object updates, and explicit Updated components), schedules jobs to find affected areas, aggregates items to update, and runs parallel jobs to recalculate extractor data, wood resources and MapFeatureElement buffers. The system integrates with several other game systems (object search, area search, natural resource, groundwater, terrain and water systems) and uses Unity Jobs, Burst and specialized quad-tree iterators to efficiently sample world data and objects.


Fields

  • private Game.Objects.UpdateCollectSystem m_ObjectUpdateCollectSystem
    {{ YOUR_INFO }}
    Reference to the system that accumulates updated object bounds. Used to get bounds of objects that changed to find which areas intersect those updates.

  • private SearchSystem m_AreaSearchSystem
    {{ YOUR_INFO }}
    Search/quad-tree system for area entities. Used to iterate areas overlapping brush bounds or updated bounds.

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    {{ YOUR_INFO }}
    Static object search tree used to find trees and other objects inside area triangles during resource counting.

  • private NaturalResourceSystem m_NaturalResourceSystem
    {{ YOUR_INFO }}
    Provides access to natural resource textures/cell data (ore, oil, fertility, fish) used when calculating extracted resources and renewals.

  • private GroundWaterSystem m_GroundWaterSystem
    {{ YOUR_INFO }}
    Provides per-cell groundwater data used when computing map feature metrics.

  • private CitySystem m_CitySystem
    {{ YOUR_INFO }}
    Used to read city modifiers (ore/oil modifiers) that affect resource amounts for a given city.

  • private TerrainSystem m_TerrainSystem
    {{ YOUR_INFO }}
    Used to read CPU terrain height data for buildability calculations.

  • private WaterSystem m_WaterSystem
    {{ YOUR_INFO }}
    Used to read water surface data (depth) for buildability calculations.

  • private EntityQuery m_UpdatedAreaQuery
    {{ YOUR_INFO }}
    ECS query selecting area entities with Updated + (Extractor or MapFeatureElement) and excluding Deleted. Used to include explicitly-updated areas in the update list.

  • private EntityQuery m_MapTileQuery
    {{ YOUR_INFO }}
    ECS query selecting MapFeatureElement entities that are not Native/Deleted/Updated (map tile entities). Optionally included when city modifiers changed.

  • private EntityQuery m_BrushQuery
    {{ YOUR_INFO }}
    Query selecting brushes that have been applied; used to find areas overlapping painting operations.

  • private NativeArray<float2> m_LastCityModifiers
    {{ YOUR_INFO }}
    Stores previous city modifier values for ore and oil to detect changes and optionally force updates for map tiles when modifiers changed.

  • private TypeHandle __TypeHandle
    {{ YOUR_INFO }}
    Container for ComponentLookup/BufferLookup/EntityTypeHandle used by jobs. Assigned in OnCreateForCompiler / __AssignHandles.

  • private EntityQuery __query_596039173_0
    {{ YOUR_INFO }}
    Internal query used to read AreasConfigurationData singleton (e.g. buildable land slope bounds).

  • (Many nested private job structs and iterators, e.g. FindUpdatedAreasWithBrushesJob, FindUpdatedAreasWithBoundsJob, CollectUpdatedAreasJob, UpdateAreaResourcesJob, TreeIterator, WoodIterator)
    {{ YOUR_INFO }}
    These nested types implement the actual work: finding areas overlapping brushes/bounds via quad tree iteration, collecting unique list of areas to update (including map tile forced updates when city modifiers change), and performing the parallel per-area resource calculations. They use BufferLookup/ComponentLookup and native containers and are Burst compiled for performance.


Properties

  • (No public properties in this class)

{{ YOUR_INFO }}
AreaResourceSystem exposes no public properties. Interaction is via ECS components and queries, and via the public static helper CalculateBuildable.


Constructors

  • public AreaResourceSystem()
    {{ YOUR_INFO }}
    Default constructor. The system initializes internal fields in OnCreate and OnCreateForCompiler. No special runtime parameters.

Methods

  • protected override void OnCreate()
    {{ YOUR_INFO }}
    Initializes references to dependent systems, creates EntityQueries (updated areas, map tiles, brushes), allocates the m_LastCityModifiers buffer and sets RequireForUpdate(). This is where the system registers which other systems and data it needs to read.

  • public void PostDeserialize(Context context)
    {{ YOUR_INFO }}
    Implementation of IPostDeserialize. Adds Updated to all MapFeatureElement entities when saved data doesn't include fish resources (compatibility path). Used to force an update for older saves when loading.

  • protected override void OnGameLoaded(Context serializationContext)
    {{ YOUR_INFO }}
    Called after game load: initializes m_LastCityModifiers from the city entity's CityModifier buffer if available.

  • protected override void OnDestroy()
    {{ YOUR_INFO }}
    Disposes native memory (m_LastCityModifiers) and runs base cleanup.

  • protected override void OnUpdate()
    {{ YOUR_INFO }}
    Main update loop. Checks whether there are brushes, updated areas, or object updates to process. Builds NativeQueue/NativeList containers, schedules FindUpdatedAreas jobs (by brushes and by object-updated bounds), schedules CollectUpdatedAreasJob to build a deduplicated update list, and schedules UpdateAreaResourcesJob to recalculate extractor/map feature/wood resources for each area in the update list. Adds appropriate readers to other systems (search trees, natural resource, terrain, water) and chains job dependencies.

  • public static float CalculateBuildable(float3 worldPos, float2 cellSize, WaterSurfaceData m_WaterSurfaceData, TerrainHeightData terrainHeightData, Bounds1 buildableLandMaxSlope)
    {{ YOUR_INFO }}
    Static helper that returns a buildability factor (0..1) for a cell at worldPos/with cellSize. Samples water depth (via WaterUtils), samples terrain heights at cell edges, computes local slope via cross products and compares to buildableLandMaxSlope bounds to generate a saturated factor. Used when computing buildable area inside map feature triangles. This is safe to call from managed code where those data structures are available (e.g., during job setup or from other systems if they have the necessary readers).

  • private void __AssignQueries(ref SystemState state)
    {{ YOUR_INFO }}
    Internal method used by generated-on-compiler code to assign entity queries used by the system (e.g. AreasConfigurationData singleton). Called in OnCreateForCompiler.

  • protected override void OnCreateForCompiler()
    {{ YOUR_INFO }}
    Internal system creation path used to wire up query handles and TypeHandle lookups in the compiled code path. Calls __AssignQueries and __TypeHandle.__AssignHandles.

  • (Many nested private job Execute/utility methods)
    {{ YOUR_INFO }}
    The nested job structs implement their own Execute/Iterate logic (quad-tree iterators, buffer manipulation, resource sampling and aggregation). Highlights:

  • FindUpdatedAreasWithBrushesJob / FindUpdatedAreasWithBoundsJob: iterate area quad tree with brush/bounds to enqueue areas that intersect and have wood resources or map feature buffers.
  • CollectUpdatedAreasJob: builds a deduplicated, sorted list of entities to update, optionally includes map tile chunks when city modifiers changed.
  • UpdateAreaResourcesJob: per-area processing. For Extractor areas it calculates resource amounts & max concentration, for MapFeatureElement it calculates area resource totals, renewals, groundwater, and buildable area. Contains CalculateWoodResources and CalculateNaturalResources helpers and also uses TreeIterator/WoodIterator to find trees and wood amounts via the object quad tree.

Usage Example

// Example: calling the static helper to compute buildability for a map cell.
// This can be useful in a custom system or tool that needs to evaluate buildability.

public float QueryCellBuildable(AreaResourceSystem areaResourceSystem, float3 cellCenter, float2 cellSize)
{
    // Get required data from game systems (example obtains from world-managed systems).
    WaterSystem waterSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<Game.Areas.WaterSystem>();
    TerrainSystem terrainSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<Game.Areas.TerrainSystem>();

    // Read the water surface and terrain height data (these methods follow the system API used by AreaResourceSystem).
    WaterSurfaceData waterSurface = waterSystem.GetSurfaceData(out var _);
    TerrainHeightData terrainHeights = terrainSystem.GetHeightData();

    // Read buildable slope bounds from AreasConfigurationData singleton
    var query = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(AreasConfigurationData));
    Bounds1 buildableSlope = query.GetSingleton<AreasConfigurationData>().m_BuildableLandMaxSlope;

    // Compute buildable fraction (0..1)
    float buildable = AreaResourceSystem.CalculateBuildable(cellCenter, cellSize, waterSurface, terrainHeights, buildableSlope);
    return buildable;
}

{{ YOUR_INFO }}
Notes for modders: - AreaResourceSystem is heavily integrated with the game's ECS and other manager systems. To interact safely with it, use the same ComponentLookup/BufferLookup patterns or request access via EntityQueries and system APIs. - The jobs are Burst-compiled and expect proper read/write access rules. If you add new resource-affecting components, ensure queries and update triggers are updated accordingly. - CalculateBuildable is provided as a public static helper for computing local buildability from terrain and water data; it's safe to call from managed contexts that have up-to-date data readers.