Skip to content

Game.Triggers.ChirpLikeCountSystem

Assembly: Game
Namespace: Game.Triggers

Type: class ChirpLikeCountSystem

Base: GameSystemBase

Summary:
ChirpLikeCountSystem is an ECS system that periodically updates the like counts of Chirp components. It schedules a Burst-compiled IJobChunk (LikeCountUpdateJob) that iterates over chunks containing Chirp components (excluding Temp and Deleted). For each Chirp it uses a per-job RandomSeed and the current simulation frame to decide whether to advance the displayed likes toward the target likes. The update uses a time-based progression and a viral factor curve to determine how many likes should be applied over time. The system runs at a coarse frequency (GetUpdateInterval returns 64), and updates are scheduled in parallel using the Entities JobChunk scheduler.


Fields

  • private SimulationSystem m_SimulationSystem
    {{ The system caches a reference to the global SimulationSystem to read the current simulation frame (frameIndex). Assigned in OnCreate. }}

  • private EntityQuery m_ChirpQuery
    {{ EntityQuery used to select entities with the Chirp component while excluding Temp and Deleted tags. Required for update; used when scheduling the chunk job. }}

  • private TypeHandle __TypeHandle
    {{ Internal helper struct holding ComponentTypeHandle. Populated in OnCreateForCompiler so the job can obtain a ComponentTypeHandle for chunk iteration. }}

  • private struct LikeCountUpdateJob (nested)
    {{ Burst-compiled IJobChunk that performs the per-chunk updates. Holds a ComponentTypeHandle, a RandomSeed, and the current simulation frame. Iterates each Chirp in a chunk and, if conditions are met, increases its m_Likes toward m_TargetLikes using a progression formula that involves m_ContinuousFactor and m_ViralFactor. }}

  • private struct TypeHandle (nested)
    {{ Small helper that exposes a ComponentTypeHandle and an __AssignHandles method used to initialize that handle from a SystemState. }}

Properties

  • None
    {{ The system exposes no public properties. All state is maintained as private fields and through the scheduled job. }}

Constructors

  • public ChirpLikeCountSystem()
    {{ Default parameterless constructor. Marked with [Preserve] in the source to avoid stripping (the class also has Preserve attributes on lifecycle methods). Typical ECS system construction is handled by the World/System creation logic. }}

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    {{ Returns 64. This indicates the system is only considered for update every 64 frames (coarse-grained throttling). Useful to control CPU cost for frequently-occurring-but-low-priority updates like social interactions. }}

  • [Preserve] protected override void OnCreate()
    {{ Initializes the system: fetches the SimulationSystem instance from the World, constructs the entity query for Chirp components (read/write) excluding Temp and Deleted, and calls RequireForUpdate with that query so the system will not update unless Chirp entities exist. Also sets up other runtime state as needed. }}

  • [Preserve] protected override void OnUpdate()
    {{ Prepares and schedules the LikeCountUpdateJob:

  • Obtains a ComponentTypeHandle via the internal TypeHandle and the checked SystemState reference.
  • Generates a RandomSeed with RandomSeed.Next(), and reads the current simulation frame from m_SimulationSystem.frameIndex.
  • Schedules the job in parallel over m_ChirpQuery with the existing job dependency (base.Dependency). The job updates likes in parallel across chunks. base.Dependency is updated with the returned job handle. }}

  • private void __AssignQueries(ref SystemState state)
    {{ Compiler-generated helper that, in this decompiled form, creates an empty EntityQueryBuilder and disposes it. Present for compiler bookkeeping. Not intended for direct use. }}

  • protected override void OnCreateForCompiler()
    {{ Compilerhook used to ensure query and type handles are initialized for compilation/runtime safety:

  • Calls __AssignQueries to fulfill the compiler's expectation.
  • Calls __TypeHandle.__AssignHandles to get the ComponentTypeHandle from the SystemState. This is part of the generated glue between managed systems and the ECS runtime. }}

  • void LikeCountUpdateJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) (inside LikeCountUpdateJob)
    {{ Per-chunk job logic:

  • Initializes a Random from m_RandomSeed.GetRandom(0) (each job invocation uses the same seed index 0).
  • Gets the native Chirp array for the chunk using the ComponentTypeHandle.
  • For each Chirp in the chunk:
    • If reference.m_InactiveFrame > reference.m_CreationFrame and m_SimulationFrame <= reference.m_InactiveFrame and random.NextFloat() >= reference.m_ContinuousFactor, then update likes.
    • Compute num = (m_SimulationFrame - m_CreationFrame) / (m_InactiveFrame - m_CreationFrame) as normalized progress (0..1).
    • Compute progress-shaped value: math.lerp(0,1, 1 - pow(1 - num, m_ViralFactor)).
    • Set reference.m_Likes = max(reference.m_Likes, (uint)(reference.m_TargetLikes * progress-shaped-value)). This effectively increases displayed likes over time toward TargetLikes, shaped by ViralFactor (controls curve) while ContinuousFactor introduces a per-step chance to skip progression (stochastic continuation). }}

Implementation/algorithm notes: - The job is Burst-compiled and uses NativeArray access for performance. - Randomness is used to allow some chirps to continue getting likes stochastically based on m_ContinuousFactor — lower continuous factor means more likely to progress each job tick. - The viral progression uses 1 - (1 - num)^viralFactor inside a lerp to produce a non-linear growth curve: viralFactor > 1 yields accelerated early growth; viralFactor < 1 yields slower early growth. - The job clamps progression so likes never decrease (math.max with current m_Likes). - The system excludes Chirp entities marked Temp or Deleted so only active, persisted chirps are processed.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Typical initialization performed by the system:
    m_SimulationSystem = base.World.GetOrCreateSystemManaged<SimulationSystem>();
    m_ChirpQuery = GetEntityQuery(
        ComponentType.ReadWrite<Chirp>(),
        ComponentType.Exclude<Temp>(),
        ComponentType.Exclude<Deleted>());
    RequireForUpdate(m_ChirpQuery);
}

Notes and tips for modders: - If you add or modify fields in the Chirp component (m_TargetLikes, m_Likes, m_CreationFrame, m_InactiveFrame, m_ContinuousFactor, m_ViralFactor), ensure the job's behavior is updated accordingly and stay careful with types (uint vs int/float). - You can tune how often likes are progressed by changing GetUpdateInterval (smaller value = more frequent updates) but consider CPU impact for large numbers of Chirp entities. - Because the job is scheduled in parallel, do not introduce non-thread-safe operations inside the job body (no managed references, no UnityEngine API calls). Keep all per-chunk work Burst-friendly and deterministic where possible.