Game.Routes.ValidationHelpers
Assembly: Assembly-CSharp (game code)
Namespace: Game.Routes
Type: public static class ValidationHelpers
Base: System.Object (static utility class)
Summary:
Utility helper methods used by the route validation systems to validate routes and stops in the routing/transport pipeline. The class contains methods that inspect route waypoints, segments, stop attachments and lane types and enqueue ErrorData entries into a provided NativeQueue when problems are detected (missing access, failed pathfinding, wrong lane types, etc.). These helpers rely on data provided by ValidationSystem.EntityData and various component data types (PrefabRef, RouteWaypoint, RouteSegment, RouteConnectionData, PlaceableObjectData, lane data, etc.). They are intended to run in jobs / systems that collect validation errors during editing or runtime.
Fields
- (none)
This is a static helper class and does not declare any fields.
Properties
- (none)
Constructors
- (none)
As a static class there are no public constructors. Methods are intended to be called directly.
Methods
public static void ValidateRoute(Entity entity, Temp temp, PrefabRef prefabRef, DynamicBuffer<RouteWaypoint> waypoints, DynamicBuffer<RouteSegment> segments, ValidationSystem.EntityData data, NativeQueue<ErrorData>.ParallelWriter errorQueue)
Validates a route entity's waypoints and segments. Key behaviors:- If the route's prefab has transport-line data, iterates waypoints and checks whether each connected stop supports passenger/cargo transport required by the transport line. If a mismatch is found, enqueues an ErrorData with ErrorType.NoPedestrianAccess or ErrorType.NoCargoAccess and severity Error.
- Determines whether the route is marked Complete (RouteFlags.Complete) via data.m_Route on the original temp entity; uses this to downgrade pathfinding failures to warnings for completed routes.
- For each route segment, if path information exists and its m_Distance is negative (indicating pathfinding failed), enqueues one or two ErrorData entries (for both neighbouring waypoints) with ErrorType.PathfindFailed and severity Error (or Warning if route is Complete).
- Uses float.NaN for m_Position and stores the waypoint temp entity in m_TempEntity so UI/inspection can reference the relevant waypoint.
Parameters:
- entity: route entity being validated.
- temp: Temp struct containing temporary/original entity references and flags.
- prefabRef: PrefabRef for the route entity.
- waypoints: DynamicBuffer
public static void ValidateStop(bool editorMode, Entity entity, Temp temp, Owner owner, Transform transform, PrefabRef prefabRef, Attached attached, ValidationSystem.EntityData data, NativeQueue<ErrorData>.ParallelWriter errorQueue)
Validates a transport stop (placeable net object). Key behaviors:- Only runs when temp.m_Flags indicates creation or modification (TempFlags.Create | TempFlags.Modify). Otherwise returns immediately.
- Reads PlaceableObjectData for the prefab (if present) and checks whether the object is a NetObject (PlacementFlags.NetObject). If not a net object, or if the stop is attached and already owned (attached.m_Parent != Entity.Null && owner.m_Owner != Entity.Null), the method returns (no validation needed).
- Retrieves RouteConnectionData for the prefab and calls FindStopLanes to determine whether there are lanes matching route connection and access connection types.
- If both route and access lanes are found (FindStopLanes returns bool2 with both true), returns (valid).
- Otherwise constructs an ErrorData: severity is Warning if editorMode, else Error. The ErrorType is chosen based on which lanes are missing and special-cases for road/track + pedestrian to emit NoRoadAccess/NoTrackAccess when appropriate; otherwise converts RouteConnectionType to ErrorType via RouteConnectionToError.
- Enqueues the ErrorData with m_TempEntity set to the stop entity and m_Position set to float.NaN.
Parameters:
- editorMode: whether validation is performed in editor mode (affects severity).
- entity: stop entity being validated.
- temp: Temp struct.
- owner: Owner component for ownership checks.
- transform: Transform component (not used by this method but included in signature).
- prefabRef: PrefabRef for the stop.
- attached: Attached component describing parent lane/segment entity.
- data: ValidationSystem.EntityData for component/buffer access.
- errorQueue: NativeQueue
private static ErrorType RouteConnectionToError(RouteConnectionType type)
Maps a RouteConnectionType enum to the corresponding ErrorType:- Road -> ErrorType.NoCarAccess
- Track -> ErrorType.NoTrainAccess
- Pedestrian -> ErrorType.NoPedestrianAccess
- Cargo -> ErrorType.NoCargoAccess
- default -> ErrorType.None
This is used to translate missing-route or missing-access connection types into presentation error types.
private static bool2 FindStopLanes(Attached attached, RouteConnectionData connectionData, ValidationSystem.EntityData data)
Checks the parent entity's sub-lanes buffer for lanes that satisfy the route and/or access connection requirements. Returns a bool2 where:- x indicates whether a lane matching the route connection type was found.
- y indicates whether a lane matching the access connection type was found.
Algorithm/notes: - If connection types are None, the corresponding bool is initialized true. - If the attached parent has no lanes buffer, returns the initialized bool2. - Iterates each SubLane in the parent's lanes buffer: - For road checks: if sub-lane has CarLane component, reads the car lane prefab and CarLaneData and checks road-type bitflags (m_RoadTypes) against connectionData.m_RouteRoadType / m_AccessRoadType to see if lane supports the required road types. - For track checks: similar logic with TrackLaneData and track-type bitflags. - For pedestrian checks: if a PedestrianLane component exists on sub-lane, it satisfies pedestrian requirement. - Accumulates results using bitwise boolean operations and short-circuits/returns as soon as both x and y are true. - Returns the bool2 result indicating which of route/access lane types were found.
Important details: - Uses math.any/math.all to test conditions efficiently. - Uses PrefabRef lookups to reach lane-specific data (CarLaneData, TrackLaneData) from sub-lane entities.
Usage Example
Example of how a validation system or job might call these helpers:
// Inside a validation system/job:
var errorQueueWriter = errorQueue.AsParallelWriter();
// Validate a route entity:
ValidationHelpers.ValidateRoute(routeEntity, temp, prefabRef, routeWaypointsBuffer, routeSegmentsBuffer, validationData, errorQueueWriter);
// Validate a stop (e.g., during create/modify):
ValidationHelpers.ValidateStop(editorMode, stopEntity, temp, owner, transform, prefabRef, attached, validationData, errorQueueWriter);
Notes and best practices:
- These helpers are designed to be called in the context of validation systems that have complete ValidationSystem.EntityData populated.
- They enqueue ErrorData entries using NativeQueue