5 #ifndef MERCATOR_TERRAIN_H 6 #define MERCATOR_TERRAIN_H 11 #include <wfmath/axisbox.h> 12 #include <wfmath/point.h> 18 #include <unordered_map> 41 typedef WFMath::AxisBox<2>
Rect;
57 static const unsigned int DEFAULT = 0x0000;
59 static const unsigned int SHADED = 0x0001;
64 const unsigned int m_options;
66 const unsigned int m_res;
68 const float m_spacing;
71 Pointstore m_basePoints;
73 Segmentstore m_segments;
75 Shaderstore m_shaders;
84 std::unordered_map<long, std::tuple<const TerrainMod *, Rect>> m_terrainMods;
92 std::unordered_map<const Area *, Rect> m_terrainAreas;
100 bool isShaded()
const {
101 return ((m_options & SHADED) == SHADED);
107 explicit Terrain(
unsigned int options = DEFAULT,
108 unsigned int resolution = defaultResolution);
111 float get(
float x,
float z)
const;
112 bool getHeight(
float x,
float z,
float&)
const;
176 bool hasMod(
long id)
const;
209 void processSegments(
const WFMath::AxisBox<2>& area,
const std::function<
void(
Segment&,
int,
int)>& func)
const;
213 return std::lround(std::floor(pos / m_spacing));
224 #endif // MERCATOR_TERRAIN_H Rect updateMod(long id, const TerrainMod *mod)
Updates the terrain with a mod.
Definition: Terrain.cpp:343
void removeShader(const Shader *t, int id)
remove a Shader from the list for this terrain.
Definition: Terrain.cpp:91
std::map< int, Pointcolumn > Pointstore
STL map to store sparse array of BasePoint columns.
Definition: Terrain.h:49
bool getHeightAndNormal(float x, float z, float &, WFMath::Vector< 3 > &) const
Get an accurate height and normal vector at a given coordinate x,z.
Definition: Terrain.cpp:205
void setBasePoint(int x, int z, const BasePoint &y)
Set the BasePoint value at a given base point coordinate.
Definition: Terrain.cpp:252
Terrain(unsigned int options=DEFAULT, unsigned int resolution=defaultResolution)
Construct a new Terrain object with optional options and resolution.
Definition: Terrain.cpp:37
static const unsigned int DEFAULT
value provided for no flags set.
Definition: Terrain.h:57
const Segmentstore & getTerrain() const
Accessor for 2D sparse array of Segment pointers.
Definition: Terrain.h:147
Rect updateArea(const Area *a)
Updates the terrain affected by an area.
Definition: Terrain.cpp:480
~Terrain()
Destroy Terrain object, deleting contained objects.
Definition: Terrain.cpp:48
void setBasePoint(int x, int y, float z)
Set the height of the basepoint at x,y to z.
Definition: Terrain.h:119
std::map< int, Segment * > Segmentcolumn
STL map to store sparse array of Segment pointers.
Definition: Terrain.h:46
Segment * getSegmentAtIndex(int x, int z) const
Get a pointer to the segment at index x,y.
Definition: Terrain.cpp:310
WFMath::AxisBox< 2 > Rect
Bounding box.
Definition: Terrain.h:41
static constexpr float defaultLevel
Height value used when no data is available.
Definition: Terrain.h:105
void addArea(const Area *a)
Add an area modifier to the terrain.
Definition: Terrain.cpp:446
void addShader(const Shader *t, int id)
Add a new Shader to the list for this terrain.
Definition: Terrain.cpp:66
const Pointstore & getPoints() const
Accessor for 2D sparse array of BasePoint objects.
Definition: Terrain.h:152
std::map< int, const Shader * > Shaderstore
STL map to store sparse array of Shader pointers.
Definition: Terrain.h:54
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:36
const Shaderstore & getShaders() const
Accessor for list of Shader pointers.
Definition: Terrain.h:157
Base class for Shader objects which create surface data for use when rendering terrain.
Definition: Shader.h:24
float getSpacing() const
Accessor for base point spacing.
Definition: Terrain.h:142
bool getBasePoint(int x, int z, BasePoint &y) const
Get the BasePoint at a given base point coordinate.
Definition: Terrain.cpp:226
bool hasMod(long id) const
Checks if a mod with the supplied id has been registered with the terrain.
Definition: Terrain.cpp:427
Point on the fundamental grid that is used as the basis for terrain.
Definition: BasePoint.h:19
std::map< int, Segmentcolumn > Segmentstore
STL map to store sparse array of Segment pointer columns.
Definition: Terrain.h:51
Class storing centrally all data about an instance of some terrain.
Definition: Terrain.h:38
std::map< int, BasePoint > Pointcolumn
STL map to store sparse array of BasePoints.
Definition: Terrain.h:44
void processSegments(const WFMath::AxisBox< 2 > &area, const std::function< void(Segment &, int, int)> &func) const
Definition: Terrain.cpp:323
static const unsigned int SHADED
set if shaders are going to be used on this terrain.
Definition: Terrain.h:59
int getResolution() const
Accessor for base point resolution.
Definition: Terrain.h:137
void removeArea(const Area *a)
Remove an area modifier from the terrain.
Definition: Terrain.cpp:563
Region of terrain surface which is modified.
Definition: Area.h:28
bool hasArea(const Area *a) const
Checks if the supplied area has been registered with the terrain.
Definition: Terrain.cpp:584
Segment * getSegmentAtPos(float x, float z) const
Get a pointer to the segment which contains the coord x,y.
Definition: Terrain.h:216
Base class for modifiers to the procedurally generated terrain.
Definition: TerrainMod.h:20
int posToIndex(float pos) const
Converts the supplied position into a segment index.
Definition: Terrain.h:212