Game.Prefabs.MaintenanceDepotData
Assembly: Game
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ICombineData
Summary:
Represents prefab data for a maintenance depot used by the simulation. Contains the maintenance type(s) the depot services, the vehicle capacity (integer count of vehicles it can hold), and a vehicle efficiency value (float). Implements combination logic to merge data from multiple sources and custom binary serialization/deserialization for saving/loading prefab state.
Fields
-
public MaintenanceType m_MaintenanceType
Bitfield/flags enum describing which maintenance types this depot services. In Combine, the flags are merged with a bitwise OR. When serialized, the enum is written as a single byte (cast to byte), so values must fit into a byte to preserve all bits. -
public int m_VehicleCapacity
Integer capacity for how many vehicles the depot can hold. Combine adds capacities together (m_VehicleCapacity += other.m_VehicleCapacity). Written to the serializer as a 32-bit integer and read back in the same order. -
public float m_VehicleEfficiency
Float representing vehicle efficiency provided by the depot (usage depends on simulation). Combine adds efficiencies (m_VehicleEfficiency += other.m_VehicleEfficiency). Serialized as a single-precision float.
Properties
- None
Constructors
public MaintenanceDepotData()
Default value-type constructor (struct). Fields will be initialized to default CLR values (m_MaintenanceType = 0, m_VehicleCapacity = 0, m_VehicleEfficiency = 0f) unless explicitly assigned.
Methods
public void Combine(MaintenanceDepotData otherData)
Merges another MaintenanceDepotData into this instance:- m_MaintenanceType |= otherData.m_MaintenanceType (bitwise OR to combine flags)
- m_VehicleCapacity += otherData.m_VehicleCapacity
-
m_VehicleEfficiency += otherData.m_VehicleEfficiency This method implements ICombineData
and is used to aggregate prefab/component data from multiple sources. -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the data to a writer in the following order: - m_VehicleCapacity (int)
- m_VehicleEfficiency (float)
-
m_MaintenanceType cast to byte Note: the enum is stored as a byte, so only the lowest 8 bits are preserved.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data from a reader in the same order as Serialize: - reads into m_VehicleCapacity (int)
- reads into m_VehicleEfficiency (float)
- reads a byte and casts it to MaintenanceType for m_MaintenanceType
Usage Example
// Create two depot data instances and combine them
var depotA = new MaintenanceDepotData {
m_MaintenanceType = MaintenanceType.Road | MaintenanceType.Tram,
m_VehicleCapacity = 5,
m_VehicleEfficiency = 1.25f
};
var depotB = new MaintenanceDepotData {
m_MaintenanceType = MaintenanceType.Bus,
m_VehicleCapacity = 3,
m_VehicleEfficiency = 0.75f
};
depotA.Combine(depotB);
// depotA now has combined flags (Road|Tram|Bus), capacity 8, efficiency 2.0f
// Serialization (pseudocode — actual writer implementation provided by engine)
TWriter writer = /* obtain writer from engine */;
depotA.Serialize(writer);
// Deserialization
TReader reader = /* obtain reader */;
var loadedDepot = new MaintenanceDepotData();
loadedDepot.Deserialize(reader);
Notes: - The serialization order must be preserved between Serialize and Deserialize. - Casting MaintenanceType to a byte limits stored flags to 8 bits; ensure the enum values used fit in a byte, or serialization may truncate flags.