Table of Contents

Class Terrain<TTemplate>

Namespace
AlphaFramework.World.Terrains
Assembly
AlphaFramework.World.dll

This class contains a height-map-based Terrain including texturing and pathfinding data.

public sealed class Terrain<TTemplate> : ITerrain where TTemplate : Template<TTemplate>

Type Parameters

TTemplate

The specific type of Template<TSelf> to use for storing information about terrain types.

Inheritance
Terrain<TTemplate>
Implements
Inherited Members
Extension Methods

Remarks

The positive X-axis points towards east (the direction from which light sources in the sky rise), the negative X-axis points towards west (the direction in which light sources in the sky set), the positive Y-axis points towards north and the negative Y-axis points towards south.

Constructors

Terrain()

Base-constructor for XML serialization. Do not call manually!

public Terrain()

Terrain(TerrainSize)

Creates a new terrain. It is completely flat and has only one texture initially.

public Terrain(TerrainSize size)

Parameters

size TerrainSize

The size of the terrain to create.

Fields

Templates

The TTemplates available for usage in this ITerrain.

public readonly TTemplate?[] Templates

Field Value

TTemplate[]

Properties

Center

The world coordinates of the center of the terrain.

[Browsable(false)]
public Vector2 Center { get; }

Property Value

Vector2

DataLoaded

Was the minimum necessary data for the terrain (HeightMap and TextureMap) loaded already?

[Browsable(false)]
public bool DataLoaded { get; }

Property Value

bool

HeightMap

Direct access to the internal height-map array. Handle with care; clone when necessary!

[Browsable(false)]
public ByteGrid? HeightMap { get; set; }

Property Value

ByteGrid

Remarks

Is not serialized/stored, is loaded by LoadHeightMap(Stream).

Exceptions

InvalidOperationException

The height-map size is incorrect.

OcclusionIntervalMap

Direct access to the internal occlusion interval map array. Handle with care; clone when necessary!

[Browsable(false)]
public ByteVector4Grid? OcclusionIntervalMap { get; set; }

Property Value

ByteVector4Grid

Remarks

Is not serialized/stored, is loaded by LoadOcclusionIntervalMap(Stream).

Exceptions

InvalidOperationException

The size is incorrect.

OcclusionIntervalMapOutdated

Indicates that the data stored in OcclusionIntervalMap is outdated and should be recalculated using OcclusionIntervalMapGenerator.

public bool OcclusionIntervalMapOutdated { get; set; }

Property Value

bool

Size

The size of the terrain.

public TerrainSize Size { get; set; }

Property Value

TerrainSize

TemplateNames

Used for XML serialization.

[Browsable(false)]
public string[]? TemplateNames { get; set; }

Property Value

string[]
See Also

TextureMap

Direct access to the internal height-map array. Handle with care; clone when necessary!

[Browsable(false)]
public NibbleGrid? TextureMap { get; set; }

Property Value

NibbleGrid

Remarks

Is not serialized/stored, is loaded by LoadTextureMap(string).

Exceptions

InvalidOperationException

The height-map size is incorrect.

Methods

GetTerrainIndex(Vector2)

Determines the TTemplate effective at specific coordinates.

public byte GetTerrainIndex(Vector2 coordinates)

Parameters

coordinates Vector2

The world coordinates to check.

Returns

byte

Exceptions

InvalidOperationException

The terrain data was not loaded yet.

LoadHeightMap(Stream)

Loads data for HeightMap from a stream.

[LuaHide]
public void LoadHeightMap(Stream stream)

Parameters

stream Stream

The stream to read the height-map from.

Exceptions

IOException

The height-map size is incorrect.

LoadHeightMap(string)

Loads data for HeightMap from a file.

public void LoadHeightMap(string path)

Parameters

path string

The path of the PNG file to load the height-map from.

Exceptions

IOException

The texture-map size is incorrect.

LoadOcclusionIntervalMap(Stream)

Loads data for OcclusionIntervalMap from a stream.

[LuaHide]
public void LoadOcclusionIntervalMap(Stream stream)

Parameters

stream Stream

The stream to read the occlusion interval map from.

Exceptions

IOException

The occlusion interval map size is incorrect.

LoadOcclusionIntervalMap(string)

Loads data for OcclusionIntervalMap from a file.

public void LoadOcclusionIntervalMap(string path)

Parameters

path string

The path of the PNG file to load the occlusion interval map from.

Exceptions

IOException

The texture-map size is incorrect.

LoadTextureMap(Stream)

Loads data for TextureMap from a stream.

[LuaHide]
public void LoadTextureMap(Stream stream)

Parameters

stream Stream

The stream to read the texture-map from.

Exceptions

IOException

The texture-map size is incorrect.

LoadTextureMap(string)

Loads data for TextureMap from a file.

public void LoadTextureMap(string path)

Parameters

path string

The path of the PNG file to load the texture-map from.

Exceptions

IOException

The texture-map size is incorrect.

MarkUntraversableSlopes(bool[,], int)

Marks untraversable slopes in a pathfinding "obstruction map".

[LuaHide]
public void MarkUntraversableSlopes(bool[,] obstructionMap, int maxTraversableSlope)

Parameters

obstructionMap bool[,]

The existing pathfinding "obstruction map" to mark the untraversable slopes in.

maxTraversableSlope int

The maximum slope to consider traversable.

ToEngineCoords(Vector2)

Converts a position in world coordinates to the engine entity space coordinate system.

public DoubleVector3 ToEngineCoords(Vector2 coordinates)

Parameters

coordinates Vector2

The coordinates of the point in engine world space to get information for.

Returns

DoubleVector3