Skip to content

Game.TrainBogieLane

Assembly:
Game (in-game assembly for vehicle types)

Namespace:
Game.Vehicles

Type:
struct

Base:
Game.Pathfind.ISerializable (implements ISerializable)

Summary:
Represents a single bogie (wheelset) position on a train lane for pathing/vehicle simulation. Stores a reference to the lane Entity, a packed curve/position value (float4) used by the navigation/path system, and lane flags describing lane characteristics. Implements custom serialization/deserialization with backward-compatibility for older save versions.


Fields

  • public Entity m_Lane
    Reference to the lane entity this bogie is currently on/targeting. Used to identify which navigation lane segment the bogie belongs to.

  • public float4 m_CurvePosition
    Packed curve/position information along the lane. The struct usually stores specific swizzled components (e.g., .xxxy, .xxxx) when constructed from other navigation structures—this is a float4 because newer navigation improvements include additional data in the extra component. In older versions a float3 was stored and is remapped during deserialization.

  • public TrainLaneFlags m_LaneFlags
    Flags describing lane properties (TrainLaneFlags is an enum). Serialized as a uint.

Properties

  • (none)

Constructors

  • public TrainBogieLane(TrainBogieCache cache)
    Constructs a TrainBogieLane from a TrainBogieCache. Copies lane Entity and lane flags, and sets m_CurvePosition to cache.m_CurvePosition.xxxy (swizzled packing used by the cache).

  • public TrainBogieLane(Entity lane, float4 curvePosition, TrainLaneFlags laneFlags)
    Direct constructor accepting the lane Entity, full float4 curvePosition, and lane flags.

  • public TrainBogieLane(TrainNavigationLane navLane)
    Constructs from a TrainNavigationLane: copies navLane.m_Lane, uses navLane.m_CurvePosition.xxxy for m_CurvePosition, and navLane.m_Flags for m_LaneFlags.

  • public TrainBogieLane(PathElement pathElement)
    Constructs from a PathElement: sets m_Lane = pathElement.m_Target and m_CurvePosition = pathElement.m_TargetDelta.xxxx. Lane flags are initialized to 0.

  • public TrainBogieLane(Entity lane, float curvePosition)
    Convenience constructor accepting a single float curvePosition — stored into m_CurvePosition (the float is broadcast/assigned to the float4). Lane flags are initialized to 0.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the instance in the following order:
  • Writes the lane Entity.
  • Writes the full float4 m_CurvePosition.
  • Writes m_LaneFlags as a uint. This is the routine used when saving the instance into the game's serialization stream.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the instance reading the same data in the expected order, with backward compatibility:

  • Reads the lane Entity.
  • If reader.context.version >= Version.tramNavigationImprovement, reads a float4 into m_CurvePosition. Otherwise reads an older float3 form and remaps it to a float4 via value.xyyz to recreate m_CurvePosition.
  • Reads a uint and casts it to TrainLaneFlags for m_LaneFlags. This method ensures older saved data (which stored curve position as a float3) can be read and converted to the newer float4 layout.

Usage Example

// Create from an Entity + float curve position
Entity laneEntity = /* obtain lane entity */;
float curvePos = 0.5f;
var bogie = new TrainBogieLane(laneEntity, curvePos);

// Create from a TrainBogieCache (typical internal usage)
TrainBogieCache cache = /* obtained from simulation */;
var bogieFromCache = new TrainBogieLane(cache);

// Serialize (pseudo-code, assuming writer implements IWriter)
void Save<TWriter>(TWriter writer, TrainBogieLane b) where TWriter : IWriter
{
    b.Serialize(writer);
}

// Deserialize (pseudo-code)
TrainBogieLane Load<TReader>(TReader reader) where TReader : IReader
{
    TrainBogieLane b = default;
    b.Deserialize(reader);
    return b;
}

Notes: - The code relies on Unity.Mathematics float4 swizzling patterns when constructing from other navigation types (.xxxy, .xxxx), and deserialization handles older formats by remapping a stored float3 into the newer float4 layout. - m_LaneFlags is serialized as a uint; treat it as TrainLaneFlags in code.