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;
68 const float m_spacing;
71 Pointstore m_basePoints;
73 Segmentstore m_segments;
75 Shaderstore m_shaders;
77 struct TerrainModEntry {
81 std::unique_ptr<TerrainMod> terrainMod;
96 std::map<long, TerrainModEntry> m_terrainMods;
98 struct TerrainAreaEntry {
102 std::unique_ptr<Area> terrainArea;
113 std::map<long, TerrainAreaEntry> m_terrainAreas;
136 bool isShaded()
const {
137 return ((m_options & SHADED) == SHADED);
149 explicit Terrain(
unsigned int options = DEFAULT,
150 int resolution = defaultResolution);
168 float get(
float x,
float z)
const;
185 bool getHeight(
float x,
float z,
float& h)
const;
297 Rect
updateMod(
long id, std::unique_ptr<TerrainMod> mod);
303 bool hasMod(
long id)
const;
311 Rect
updateArea(
long id, std::unique_ptr<Area> a);
314 const Area* getArea(
long id)
const;
328 void processSegments(
const WFMath::AxisBox<2>& area,
const std::function<
void(
Segment&,
int,
int)>& func)
const;
332 return (
int)std::lround(std::floor(pos / m_spacing));
343 #endif // MERCATOR_TERRAIN_H void removeShader(const Shader *t, int id)
remove a Shader from the list for this terrain.
std::map< int, Pointcolumn > Pointstore
STL map to store sparse array of BasePoint columns.
void setBasePoint(int x, int z, const BasePoint &y)
Set the BasePoint value at a given base point coordinate.
static const unsigned int DEFAULT
value provided for no flags set.
const Segmentstore & getTerrain() const
Accessor for 2D sparse array of Segment pointers.
~Terrain()
Destroy Terrain object, deleting contained objects.
void setBasePoint(int x, int y, float z)
Set the height of the basepoint at x,y to z.
Terrain(unsigned int options=DEFAULT, int resolution=defaultResolution)
Construct a new Terrain object with optional options and resolution.
Segment * getSegmentAtIndex(int x, int z) const
Get the Segment at a given index.
WFMath::AxisBox< 2 > Rect
Bounding box.
static constexpr float defaultLevel
Height value used when no data is available.
bool getHeightAndNormal(float x, float z, float &h, WFMath::Vector< 3 > &n) const
Get an accurate height and normal vector at a given coordinate x,z.
void addShader(const Shader *t, int id)
Add a new Shader to the list for this terrain.
const Pointstore & getPoints() const
Accessor for 2D sparse array of BasePoint objects.
std::map< int, const Shader * > Shaderstore
STL map to store sparse array of Shader pointers.
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
const Shaderstore & getShaders() const
Accessor for list of Shader pointers.
Base class for Shader objects which create surface data for use when rendering terrain.
float getSpacing() const
Accessor for base point spacing.
bool getBasePoint(int x, int z, BasePoint &y) const
Get the BasePoint at a given base point coordinate.
bool hasMod(long id) const
Checks if a mod with the supplied id has been registered with the terrain.
Point on the fundamental grid that is used as the basis for terrain.
std::map< int, Segmentcolumn > Segmentstore
STL map to store sparse array of Segment pointer columns.
Class storing centrally all data about an instance of some terrain.
std::map< int, BasePoint > Pointcolumn
STL map to store sparse array of BasePoints.
void processSegments(const WFMath::AxisBox< 2 > &area, const std::function< void(Segment &, int, int)> &func) const
Rect updateMod(long id, std::unique_ptr< TerrainMod > mod)
Updates the terrain with a mod.
static const unsigned int SHADED
set if shaders are going to be used on this terrain.
std::map< int, std::unique_ptr< Segment > > Segmentcolumn
STL map to store sparse array of Segments.
bool getHeight(float x, float z, float &h) const
Get an accurate height at a given coordinate x,z.
int getResolution() const
Accessor for base point resolution.
Region of terrain surface which is modified.
Rect updateArea(long id, std::unique_ptr< Area > a)
Updates the terrain affected by an area.
Segment * getSegmentAtPos(float x, float z) const
Get a pointer to the segment which contains the coord x,y.
Base class for modifiers to the procedurally generated terrain.
int posToIndex(float pos) const
Converts the supplied position into a segment index.