Class ProvinceSystem
Single source of truth for all province data Owns the 8-byte ProvinceState array for deterministic simulation Manages province ownership, development, terrain, and flags Performance: Structure of Arrays design, Burst-compatible, zero allocations
public class ProvinceSystem : MonoBehaviour
- Inheritance
-
objectProvinceSystem
Properties
Capacity
public int Capacity { get; }
Property Value
- int
IsInitialized
public bool IsInitialized { get; }
Property Value
- bool
ProvinceCount
public int ProvinceCount { get; }
Property Value
- int
Methods
AddHistoricalEvent(ushort, HistoricalEvent)
public void AddHistoricalEvent(ushort provinceId, HistoricalEvent evt)
Parameters
provinceIdushortevtHistoricalEvent
AddProvince(ushort, ushort)
Add a single province to the system (for runtime colonization)
public void AddProvince(ushort provinceId, ushort terrainType)
Parameters
provinceIdushortterrainTypeushort
ApplyInitialStates(ProvinceInitialStateLoadResult)
Apply initial states (ownership, terrain) from JSON5 data to already-registered provinces Called after InitializeFromDefinitions to set ownership for provinces that have history files
public void ApplyInitialStates(ProvinceInitialStateLoadResult loadResult)
Parameters
loadResultProvinceInitialStateLoadResult
ApplyResolvedInitialStates(NativeArray<ProvinceInitialState>)
public void ApplyResolvedInitialStates(NativeArray<ProvinceInitialState> initialStates)
Parameters
initialStatesNativeArray<ProvinceInitialState>
Dispose()
public void Dispose()
GetAllProvinceIds(Allocator)
public NativeArray<ushort> GetAllProvinceIds(Allocator allocator = Allocator.TempJob)
Parameters
allocatorAllocator
Returns
- NativeArray<ushort>
GetCountryProvinces(ushort, Allocator)
public NativeArray<ushort> GetCountryProvinces(ushort countryId, Allocator allocator = Allocator.TempJob)
Parameters
countryIdushortallocatorAllocator
Returns
- NativeArray<ushort>
GetCountryProvinces(ushort, NativeList<ushort>)
public void GetCountryProvinces(ushort countryId, NativeList<ushort> resultBuffer)
Parameters
countryIdushortresultBufferNativeList<ushort>
GetHistoryStats()
public HistoryDatabaseStats GetHistoryStats()
Returns
GetHistorySummary(ushort)
public ProvinceHistorySummary GetHistorySummary(ushort provinceId)
Parameters
provinceIdushort
Returns
GetNativeData()
Get read-only native province data for Burst jobs. Returns a struct with read-only views of province data.
public NativeProvinceData GetNativeData()
Returns
GetProvinceController(ushort)
public ushort GetProvinceController(ushort provinceId)
Parameters
provinceIdushort
Returns
- ushort
GetProvinceCountForCountry(ushort)
public int GetProvinceCountForCountry(ushort countryId)
Parameters
countryIdushort
Returns
- int
GetProvinceOwner(ushort)
public ushort GetProvinceOwner(ushort provinceId)
Parameters
provinceIdushort
Returns
- ushort
GetProvinceState(ushort)
public ProvinceState GetProvinceState(ushort provinceId)
Parameters
provinceIdushort
Returns
GetProvinceTerrain(ushort)
public ushort GetProvinceTerrain(ushort provinceId)
Parameters
provinceIdushort
Returns
- ushort
GetRecentHistory(ushort, int)
public List<HistoricalEvent> GetRecentHistory(ushort provinceId, int maxEvents = 10)
Parameters
provinceIdushortmaxEventsint
Returns
- List<HistoricalEvent>
GetStateChecksum()
Calculate checksum of all province states for network sync verification. Used by CommandProcessor for desync detection.
public uint GetStateChecksum()
Returns
- uint
GetUIReadBuffer()
Get read-only snapshot buffer for UI access (zero-blocking reads) UI should NEVER write to this buffer - it's one frame behind simulation
public NativeArray<ProvinceState> GetUIReadBuffer()
Returns
HasProvince(ushort)
public bool HasProvince(ushort provinceId)
Parameters
provinceIdushort
Returns
- bool
Initialize(EventBus)
Initialize the province system with event bus
public void Initialize(EventBus eventBus)
Parameters
eventBusEventBus
InitializeEmpty()
Initialize empty province system for map-only mode No province data loaded - just renders the map texture
public void InitializeEmpty()
InitializeFromDefinitions(List<DefinitionEntry>)
Initialize provinces from definition.csv only (no history data) Creates provinces with default state (no owner, no development)
public void InitializeFromDefinitions(List<DefinitionLoader.DefinitionEntry> definitions)
Parameters
definitionsList<DefinitionLoader.DefinitionEntry>
InitializeFromProvinceStates(ProvinceInitialStateLoadResult)
Initialize provinces from JSON5 + Burst loaded province states
public void InitializeFromProvinceStates(ProvinceInitialStateLoadResult loadResult)
Parameters
loadResultProvinceInitialStateLoadResult
LoadProvinceInitialStates(string)
public void LoadProvinceInitialStates(string dataDirectory)
Parameters
dataDirectorystring
LoadProvinceInitialStatesForLinking(string)
public ProvinceInitialStateLoadResult LoadProvinceInitialStatesForLinking(string dataDirectory)
Parameters
dataDirectorystring
Returns
LoadState(BinaryReader)
Load ProvinceSystem state from binary reader Restores: capacity, province states, id mappings Note: Must be called AFTER Initialize() but BEFORE any province operations
public void LoadState(BinaryReader reader)
Parameters
readerBinaryReader
SaveState(BinaryWriter)
Save ProvinceSystem state to binary writer Serializes: capacity, province states, id mappings
public void SaveState(BinaryWriter writer)
Parameters
writerBinaryWriter
SetProvinceOwner(ushort, ushort)
public void SetProvinceOwner(ushort provinceId, ushort newOwner)
Parameters
provinceIdushortnewOwnerushort
SetProvinceState(ushort, ProvinceState)
public void SetProvinceState(ushort provinceId, ProvinceState state)
Parameters
provinceIdushortstateProvinceState
SetProvinceTerrain(ushort, ushort)
public void SetProvinceTerrain(ushort provinceId, ushort terrain)
Parameters
provinceIdushortterrainushort
SwapBuffers()
Called by TimeManager after simulation tick completes Swaps write/read buffers so UI sees latest completed tick
Uses DIRTY TRACKING for efficient partial copies:
- Only copies provinces that were modified since last swap
- O(dirty count) instead of O(total provinces)
- Scales to 100k+ provinces without performance issues
public void SwapBuffers()
SyncBuffersAfterLoad()
Synchronize buffers after scenario loading Ensures both buffers have identical data to prevent first-tick empty buffer bug
public void SyncBuffersAfterLoad()