Game.Simulation.Wind
Assembly:
Game (Cities: Skylines 2 game assembly)
Namespace:
Game.Simulation
Type:
struct
Base:
IStrideSerializable, ISerializable
Summary:
Represents a single wind sample stored in a grid (cell map). This struct holds a 2D wind vector (float2) and implements lightweight binary serialization and stride reporting so it can be stored in CellMapData or other serialized buffers. It also provides a static helper, SampleWind, to sample the wind field using bilinear interpolation from a CellMapData
Fields
public Unity.Mathematics.float2 m_Wind
Stores the wind vector for this cell. The vector is typically used in the horizontal plane (x,z in world space). This value is what gets written/read during serialization and what is sampled by SampleWind.
Properties
- (none)
This struct exposes no properties; it uses a public field for its data.
Constructors
- (implicit) default struct constructor
No explicit constructors are defined. The default parameterless constructor initializes m_Wind to (0,0).
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Wind field to the provided writer. Used by the game's serialization pipeline to persist the wind buffer. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the m_Wind field from the provided reader. Used by the game's deserialization pipeline to reconstruct wind data. -
public int GetStride(Context context)
Returns the byte stride required to store one Wind element in a raw buffer. Implementation returns UnsafeUtility.SizeOf(), ensuring the stride matches the underlying float2 size. -
public static Unity.Mathematics.float2 SampleWind(CellMapData<Wind> wind, Unity.Mathematics.float3 position)
Samples the wind field stored in a CellMapDataat the given world-space position. Implementation details: - Converts world position.xz into cell-space coordinates: position.xz / wind.m_CellSize.
- Offsets coordinates to map into texture indexing: + wind.m_TextureSize * 0.5f - 0.5f.
- Computes the four neighboring texel/cell integer indices (floor and +1), clamps them to valid range.
- Builds four linear buffer indices and fetches the m_Wind values for the four surrounding cells.
- Performs bilinear interpolation: first between left/right with float2.x then between top/bottom with float2.y.
- Returns the interpolated float2 wind vector in the same coordinate convention as m_Wind (horizontal plane).
Notes about CellMapData usage:
- The method expects the CellMapData
Usage Example
// Sample wind at a world position (x,y,z)
CellMapData<Wind> windMap = /* obtain the CellMapData<Wind> from simulation */;
float3 worldPos = new float3(100f, 0f, 200f);
float2 sampledWind = Wind.SampleWind(windMap, worldPos);
// Example: storing/reading a Wind value during custom serialization
Wind w;
w.m_Wind = new float2(1.0f, -0.3f);
// writer and reader types are provided by the game's serialization system
writer.Write(w.m_Wind);
reader.Read(out w.m_Wind);