Class GridDumpTerrain
- Namespace
- Valheim.Testing
- Assembly
- Valheim.Testing.dll
Terrain read from an evenly spaced grid of samples, such as a CSV world dump.
Nodes sit at OriginX + i * Spacing, OriginZ + j * Spacing; the covered area is the closed
rectangle from the origin to MaxX/MaxZ, so the last row and column are inside.
- Height, river weight and river width: at a node, the node's value unchanged (a query within 1e-4 of a cell of a node is that node); between nodes, bilinear between the four surrounding nodes. Bilinear is an approximation of the dumped world between its samples, not a replay.
- Biome: the nearest node's label, never an average. A node owns the half-open cell from half a spacing below it to half a spacing above it on each axis, so a query exactly halfway takes the node at larger x (or z).
- Outside the covered area every query throws System.ArgumentOutOfRangeException; there is no edge clamping or extrapolation. A missing biome or river layer throws System.NotSupportedException.
Immutable after construction and safe for concurrent readers.
public sealed class GridDumpTerrain : ITerrain
- Inheritance
-
objectGridDumpTerrain
- Implements
Constructors
GridDumpTerrain(string, float, float, float, int, int, float[], TerrainBiome[]?, float[]?, float[]?, float[]?)
Declares a grid directly. Arrays are row-major with x fastest (index = j * countX + i) and are copied.
River weight and width are given together or not at all. A biome layer must name a biome at every node.
public GridDumpTerrain(string provenance, float originX, float originZ, float spacing, int countX, int countZ, float[] heights, TerrainBiome[]? biomes = null, float[]? riverWeights = null, float[]? riverWidths = null, float[]? baseHeights = null)
Parameters
provenancestringoriginXfloatoriginZfloatspacingfloatcountXintcountZintheightsfloat[]biomesTerrainBiome[]riverWeightsfloat[]riverWidthsfloat[]baseHeightsfloat[]
Properties
CountX
Number of nodes along x; at least two.
public int CountX { get; }
Property Value
- int
CountZ
Number of nodes along z; at least two.
public int CountZ { get; }
Property Value
- int
HasBaseHeight
Whether the dump includes Valheim's unitless GetBaseHeight samples, distinct from metre-valued height.
public bool HasBaseHeight { get; }
Property Value
- bool
HasBiome
Whether biome samples were supplied; otherwise GetBiome(float, float) throws.
public bool HasBiome { get; }
Property Value
- bool
HasRiver
Whether both river layers were supplied; otherwise GetRiverWeight(float, float, out float, out float) throws.
public bool HasRiver { get; }
Property Value
- bool
MaxX
Inclusive x coordinate of the last column.
public float MaxX { get; }
Property Value
- float
MaxZ
Inclusive z coordinate of the last row.
public float MaxZ { get; }
Property Value
- float
OriginX
Horizontal x coordinate of the first grid column, in metres.
public float OriginX { get; }
Property Value
- float
OriginZ
Horizontal z coordinate of the first grid row, in metres.
public float OriginZ { get; }
Property Value
- float
Provenance
The caller's source label, included in out-of-range and missing-layer errors.
public string Provenance { get; }
Property Value
- string
Spacing
Distance between adjacent nodes on either horizontal axis, in metres.
public float Spacing { get; }
Property Value
- float
Methods
Contains(float, float)
Whether a query at this coordinate is answered rather than refused.
public bool Contains(float x, float z)
Parameters
xfloatzfloat
Returns
- bool
GetBaseHeight(float, float)
Valheim's unitless generator base-height value as ValheimCLI's world dump exports it, not a ground elevation in metres. At nodes this is the dumped value; between nodes it is bilinear and only an approximation.
public float GetBaseHeight(float x, float z)
Parameters
xfloatzfloat
Returns
- float
GetBiome(float, float)
Returns the nearest node's biome; ties choose the node at larger x or z. A missing layer or outside coordinate throws.
public TerrainBiome GetBiome(float x, float z)
Parameters
xfloatzfloat
Returns
GetHeight(float, float)
Returns exact node height or bilinear height between nodes, in metres; outside the grid throws.
public float GetHeight(float x, float z)
Parameters
xfloatzfloat
Returns
- float
GetRiverWeight(float, float, out float, out float)
Returns exact node river facts or bilinear facts between nodes. A missing layer or outside coordinate throws.
public void GetRiverWeight(float x, float z, out float weight, out float width)
Parameters
xfloatzfloatweightfloatwidthfloat
IsSampleNode(float, float)
Whether both coordinates land on stored nodes (within the reader's 1e-4-cell snap tolerance).
public bool IsSampleNode(float x, float z)
Parameters
xfloatzfloat
Returns
- bool
Load(string)
Reads a CSV grid file; the provenance is the file name without its directory.
public static GridDumpTerrain Load(string path)
Parameters
pathstring
Returns
Read(TextReader, string)
Reads a CSV grid: a header row, then one row per node. Columns are found by name (case-insensitive, any
order): x, z and height are required; biome is optional; river and
river_width are optional but only together; base_height is an optional unitless generator
value, not metre-valued ground height. Other columns are ignored. Rows may come in any order but must cover every node of one evenly spaced grid exactly once,
with the same spacing on x and z. Numbers use the invariant culture. Empty lines are skipped. This reads
ValheimCLI's world-dump output (x,z,height,biome,river,river_width,base_height) as is.
Every refusal throws System.IO.InvalidDataException naming the line.
public static GridDumpTerrain Read(TextReader reader, string provenance)
Parameters
readerTextReaderprovenancestring