Game.Net.TrackTypes
Assembly: Game
Namespace: Game.Net
Type: enum
Base: System.Enum (underlying type: System.Byte)
Summary: TrackTypes is a bitmask (Flags) enumeration used to represent one or more types of rail-based tracks/vehicles (train, tram, subway). The enum uses a byte as the underlying storage so multiple track types can be combined into a single byte for efficient storage and network serialization.
Fields
-
None = 0
Represents no track type selected. -
Train = 1
Bit 0 (0b001). Represents train tracks/vehicles. -
Tram = 2
Bit 1 (0b010). Represents tram tracks/vehicles. -
Subway = 4
Bit 2 (0b100). Represents subway tracks/vehicles.
(As a [Flags] enum, these values can be combined using bitwise operations, e.g., Train | Tram.)
Properties
- None — this is a plain enum and does not define properties. Use bitwise operations to query combined flags.
Constructors
- None — enums do not have user-defined constructors.
Methods
- None — no methods are defined on this enum type. Use standard Enum methods (Enum.HasFlag, Enum.GetValues, etc.) or bitwise operations for flag handling.
Usage Example
// Combine flags
TrackTypes types = TrackTypes.Train | TrackTypes.Tram;
// Check for a specific flag (preferred: bitwise check for performance)
bool hasTrain = (types & TrackTypes.Train) != 0;
// Add a flag
types |= TrackTypes.Subway;
// Remove a flag
types &= ~TrackTypes.Tram;
// Serialize to a single byte (suitable for network or file storage)
byte serialized = (byte)types;
// Deserialize from a byte
TrackTypes deserialized = (TrackTypes)serialized;
// Iterate individual flags
foreach (TrackTypes t in Enum.GetValues(typeof(TrackTypes)))
{
if (t == TrackTypes.None) continue;
if ((deserialized & t) != 0)
{
// handle t
}
}
Notes: - Because this enum is marked with [Flags], prefer bitwise comparisons ((value & Flag) != 0) rather than Enum.HasFlag when performance and allocations matter (HasFlag may cause boxing). - Casting to/from byte is useful for compact storage or network transmission since the underlying type is byte.