Skip to content

Game.Serialization.InstalledUpgradeSystem

Assembly:
Assembly-CSharp (main game assembly; the system class is defined in the game's managed assembly)

Namespace:
Game.Serialization

Type:
public class InstalledUpgradeSystem

Base:
GameSystemBase

Summary:
This ECS system collects installed "ServiceUpgrade" entities and records them into per-owner InstalledUpgrade buffers. It uses a Burst-compiled IJobChunk (InstalledUpgradeJob) to iterate matching chunks and, for each ServiceUpgrade entity, determines the owner and the upgrade's effective option mask. If the target building is destroyed or on fire, or the upgrade is an Extension that is disabled, the job forces the option mask to a disabled value (2). The job then appends an InstalledUpgrade entry (entity + option mask) into the owning entity's InstalledUpgrade dynamic buffer. The system requires the existence of ServiceUpgrade + Owner + Object components to run.


Fields

  • private EntityQuery m_Query
    This query matches entities with ComponentType.ReadOnly(), ComponentType.ReadOnly(), and ComponentType.ReadOnly(). It's created in OnCreate and used to schedule the InstalledUpgradeJob over all service-upgrade entities. The query is also passed to RequireForUpdate to ensure the system runs only when such entities exist.

  • private TypeHandle __TypeHandle
    Holds component and buffer type handles used by the job and system. The struct caches:

  • EntityTypeHandle
  • ComponentTypeHandle (read-only)
  • ComponentTypeHandle (read-only)
  • ComponentTypeHandle (read-only)
  • ComponentTypeHandle (read-only)
  • ComponentTypeHandle (read-only)
  • BufferLookup (read/write)
  • __TypeHandle.__AssignHandles(ref SystemState) populates these handles from the provided SystemState; these handles are then converted to runtime handles via InternalCompilerInterface.Get*TypeHandle calls before scheduling the job.

    Properties

    • None (the class does not expose public properties)

    Constructors

    • public InstalledUpgradeSystem()
      Default, parameterless constructor. Marked with [Preserve] to avoid stripping. No custom initialization occurs here; runtime initialization happens in OnCreate / OnCreateForCompiler.

    Methods

    • protected override void OnCreate()
      Creates the entity query used by the system:
    • m_Query = GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly(), ComponentType.ReadOnly());
    • Calls RequireForUpdate(m_Query) to avoid executing when no matching entities exist.

    • protected override void OnUpdate()
      Prepares an InstalledUpgradeJob instance by converting the cached __TypeHandle fields into runtime EntityTypeHandle/ComponentTypeHandle/BufferLookup instances via InternalCompilerInterface.Get* methods and base.CheckedStateRef. The method then schedules the job over m_Query using JobChunkExtensions.Schedule and assigns the returned handle into base.Dependency so the job is run respecting system dependencies.

    • protected override void OnCreateForCompiler()
      Called by the generated/compiler-specific initialization path. It calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to ensure the query and type handles are initialized for the compiler-generated runtime.

    • private void __AssignQueries(ref SystemState state)
      Currently contains a simple new EntityQueryBuilder(Allocator.Temp).Dispose(); placeholder — used in generated systems to ensure query creation on some build paths. Kept for compiler compatibility.

    • Nested / Job types (important runtime behavior)

      • InstalledUpgradeJob : IJobChunk (BurstCompile applied)
        Fields:
        • ReadOnly EntityTypeHandle m_EntityType
        • ReadOnly ComponentTypeHandle m_OwnerType
        • ReadOnly ComponentTypeHandle m_DestroyedType
        • ReadOnly ComponentTypeHandle m_OnFireType
        • ReadOnly ComponentTypeHandle m_BuildingType
        • ReadOnly ComponentTypeHandle m_ExtensionType
        • BufferLookup m_InstalledUpgrades

      Behavior: - For each archetype chunk, it obtains arrays for entity, owner, building and extension component data via chunk.GetNativeArray. - Checks whether the chunk contains Destroyed or OnFire tags and uses CollectionUtils.TryGet(...) to safely read Building or Extension components when present. - If a building exists and the chunk has Destroyed or OnFire, sets value.m_OptionMask = 2u. - If an extension exists and its flags include ExtensionFlags.Disabled, sets value.m_OptionMask = 2u. - Finally, for each upgrade in the chunk, it pushes a new InstalledUpgrade(upgradeEntity, optionMask) into the buffer for owner.m_Owner using m_InstalledUpgrades[ownerId].Add(...). - The job is Burst-compiled for performance and scheduled as a chunk job to run in parallel.

      Notes: - The system uses InternalCompilerInterface to adapt the cached type handles to runtime job handles. - The system is marked [CompilerGenerated] at the class level; some methods/fields exist to support the generated ECS code patterns.

      Usage Example

      [Preserve]
      protected override void OnCreate()
      {
          base.OnCreate();
          // Create the query used by this system to find ServiceUpgrade entities and require it for update.
          m_Query = GetEntityQuery(
              ComponentType.ReadOnly<ServiceUpgrade>(),
              ComponentType.ReadOnly<Owner>(),
              ComponentType.ReadOnly<Object>()
          );
          RequireForUpdate(m_Query);
      }
      

      Additional usage (reading InstalledUpgrade buffers from another system):

      // Example: read installed upgrades for an owner entity
      EntityQuery ownerQuery = GetEntityQuery(ComponentType.ReadOnly<Owner>(), ComponentType.ReadOnly<InstalledUpgrade>());
      var handles = world.EntityManager.GetBufferLookup<InstalledUpgrade>(false);
      Entities
          .WithName("ReadInstalledUpgrades")
          .WithReadOnly(handles)
          .ForEach((in Owner owner) =>
          {
              var upgrades = handles[owner.m_Owner];
              for (int i = 0; i < upgrades.Length; i++)
              {
                  InstalledUpgrade iu = upgrades[i];
                  // process iu.upgradeEntity and iu.optionMask
              }
          }).Schedule();
      

      If you want, I can also produce a short reference for the nested InstalledUpgradeJob fields and the TypeHandle.__AssignHandles method showing their exact mappings to component types.