Game.Simulation.LoanUpdateSystem
Assembly:
Namespace: Game.Simulation
Type: LoanUpdateSystem
Base: GameSystemBase
Summary:
LoanUpdateSystem runs periodically to update the city's outstanding loan state. It schedules a Burst-compiled IJob (LoanUpdateJob) that reads the city's Loan, Creditworthiness, PlayerMoney and CityModifier buffers, computes interest/targets using economy parameters and LoanSystem helpers, enqueues statistics events and trigger actions (for example UnpaidLoan) when conditions are met, and coordinates with CityStatisticsSystem and TriggerSystem to write results and action buffers. The system is gated by an EconomyParameterData singleton query (RequireForUpdate).
Fields
-
public static readonly int kUpdatesPerDay
This constant equals 32 and is used to calculate how frequently loan updates should occur relative to the engine's internal frame/tick scale. -
private CityStatisticsSystem m_CityStatisticsSystem
Reference to the CityStatisticsSystem used to obtain a statistics event queue for the job and to register the scheduled job as a writer. -
private CitySystem m_CitySystem
Reference used to obtain the current city Entity (m_City) that the job operates on. -
private TriggerSystem m_TriggerSystem
Reference used to create a TriggerAction buffer into which the job enqueues trigger actions (e.g., UnpaidLoan). -
private SimulationSystem m_SimulationSystem
Reference to obtain the current simulation frame index (frameIndex), used to decide if a loan is overdue. -
private EntityQuery m_EconomyParametersQuery
An EntityQuery used to fetch the EconomyParameterData singleton required by this system (used in RequireForUpdate). -
private TypeHandle __TypeHandle
Compiler-generated helper that holds ComponentLookup/BufferLookup handles for the job. It is assigned in OnCreateForCompiler.
Properties
- None (the system exposes no public properties).
Constructors
public LoanUpdateSystem()
Default constructor (preserved). The system performs most initialization in OnCreate / OnCreateForCompiler.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the update interval in engine ticks: 262144 / kUpdatesPerDay. This value controls how often the system will run relative to the engine's update timeline. -
[Preserve] protected override void OnCreate()
Initializes references to required systems (CityStatisticsSystem, CitySystem, TriggerSystem, SimulationSystem), creates the EntityQuery for EconomyParameterData, and calls RequireForUpdate on that query so the system only runs when economy parameters are present. -
[Preserve] protected override void OnUpdate()
Builds and schedules the LoanUpdateJob: - Obtains a NativeQueue
and its dependency from CityStatisticsSystem.GetStatisticsEventQueue(out deps). - Fills a LoanUpdateJob struct with ComponentLookup/BufferLookup handles (via InternalCompilerInterface.GetComponentLookup / GetBufferLookup), the city Entity, economy parameters singleton, simulation frame index and a TriggerAction buffer from TriggerSystem.CreateActionBuffer().
- Schedules the job with IJobExtensions.Schedule combining existing dependencies.
-
Registers the scheduled dependency with CityStatisticsSystem.AddWriter and TriggerSystem.AddActionBufferWriter so those systems are aware of the writer dependencies.
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Compiler-generated stub that sets up any required EntityQuery builders for the system. In this class it currently disposes an empty EntityQueryBuilder; used by the generated OnCreateForCompiler path. -
protected override void OnCreateForCompiler()
Called by the compiled code path to assign queries and assign the TypeHandle's component/buffer lookups using the system state reference. -
private struct TypeHandle
Compiler-generated nested struct holding ComponentLookup, ComponentLookup , ComponentLookup and BufferLookup (all read-only). Contains __AssignHandles(ref SystemState state) to initialize those lookups from the SystemState. -
[BurstCompile] private struct LoanUpdateJob : IJob
The job executed by the system. Key members and behavior: - ReadOnly ComponentLookup
m_Loans - ReadOnly ComponentLookup
m_Creditworthinesses - ReadOnly ComponentLookup
m_PlayerMoneys - ReadOnly BufferLookup
m_CityEffects - NativeQueue
m_StatisticsEventQueue (writer) - NativeQueue
m_TriggerBuffer (writer) - EconomyParameterData m_EconomyParameters (by value)
- Entity m_City (the city entity to read components from)
- uint m_SimulationFrameIndex (the frame index)
- Execute() behavior:
- Reads current Loan for the city. If loan.m_Amount > 0:
- Computes targetInterest via LoanSystem.GetTargetInterest(loan.m_Amount, creditworthiness, city effects, economy param min/max interest).
- Rounds the interest-per-update: Mathf.RoundToInt((float)loan.m_Amount * targetInterest / (float)kUpdatesPerDay); (note: the result is computed but not stored in this code sample — original system may use it elsewhere or side-effect removed by compiler generation)
- Reads PlayerMoney for the city. If the loan hasn't been modified for more than 262144 frames and playerMoney.money > 0, enqueues a TriggerAction(TriggerType.UnpaidLoan, Entity.Null, loan.m_Amount) to m_TriggerBuffer.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical initialization performed by this system:
m_CityStatisticsSystem = World.GetOrCreateSystemManaged<CityStatisticsSystem>();
m_CitySystem = World.GetOrCreateSystemManaged<CitySystem>();
m_TriggerSystem = World.GetOrCreateSystemManaged<TriggerSystem>();
m_SimulationSystem = World.GetOrCreateSystemManaged<SimulationSystem>();
m_EconomyParametersQuery = EntityManager.CreateEntityQuery(ComponentType.ReadOnly<EconomyParameterData>());
RequireForUpdate(m_EconomyParametersQuery);
}
// OnUpdate schedules a burst job that reads loans and may enqueue UnpaidLoan triggers.
// The system ensures dependencies are combined and registered with the statistics and trigger systems.
Notes and implementation details: - The system is generated to use ComponentLookup/BufferLookup handles and InternalCompilerInterface helpers — these are part of the compiled ECS integration and may appear different when authoring hand-written systems. - The magic number 262144 is used both as a threshold for "loan last modified" detection and (together with kUpdatesPerDay) to compute update intervals; treat it as a fixed frame-scale constant in this codebase. - LoanUpdateJob uses NativeQueue writers obtained from other systems. OnUpdate ensures job dependencies are combined so writer semantics are honored.