diff --git a/src/definition/PaintedGrid.cpp b/src/definition/PaintedGrid.cpp index b76fd6a..4c8b154 100644 --- a/src/definition/PaintedGrid.cpp +++ b/src/definition/PaintedGrid.cpp @@ -119,6 +119,11 @@ double PaintedGrid::getFinalValue(double x, double y) const } } +bool PaintedGrid::hasPainting() const +{ + return merged_data->hasData() || brush_data->hasData(); +} + bool PaintedGrid::isPainted(int x, int y) const { return getDataPointer(brush_data, x, y, NULL, false) || getDataPointer(merged_data, x, y, NULL, false); diff --git a/src/definition/PaintedGrid.h b/src/definition/PaintedGrid.h index a593de8..a71a1a6 100644 --- a/src/definition/PaintedGrid.h +++ b/src/definition/PaintedGrid.h @@ -44,6 +44,11 @@ public: */ double getFinalValue(double x, double y) const; + /** + * Returns true if the grid has any painting. + */ + bool hasPainting() const; + /** * Returns true if a grid point is user-specified, false if it's the initial value. */ diff --git a/src/definition/PaintedGridData.h b/src/definition/PaintedGridData.h index fe55562..ab00a36 100644 --- a/src/definition/PaintedGridData.h +++ b/src/definition/PaintedGridData.h @@ -26,6 +26,8 @@ public: */ void clear(); + inline bool hasData() const {return rows_count > 0;} + private: typedef struct { diff --git a/src/definition/TerrainDefinition.cpp b/src/definition/TerrainDefinition.cpp index 0fa2bf1..c8888b5 100644 --- a/src/definition/TerrainDefinition.cpp +++ b/src/definition/TerrainDefinition.cpp @@ -12,6 +12,7 @@ TerrainDefinition::TerrainDefinition(DefinitionNode* parent): shadow_smoothing = 0.0; height_map = new TerrainHeightMap(this); + has_painting = false; addChild(height_map); water_height = new FloatNode(this, "water_height"); @@ -38,7 +39,8 @@ void TerrainDefinition::validate() _min_height *= height; _max_height *= height; - /* TODO Alter with heightmap min/max */ + /* TODO Alter limits with heightmap min/max */ + has_painting = height_map->hasPainting(); } void TerrainDefinition::copy(DefinitionNode* _destination) const @@ -79,7 +81,7 @@ double TerrainDefinition::getGridHeight(int x, int z, bool with_painting) { double h; - if (!with_painting || !height_map->getGridValue(x, z, &h)) + if (!with_painting || !has_painting || !height_map->getGridValue(x, z, &h)) { h = _height_noise->get2DTotal((double)x, (double)z); } @@ -91,7 +93,7 @@ double TerrainDefinition::getInterpolatedHeight(double x, double z, bool scaled, { double h; - if (!with_painting || !height_map->getInterpolatedValue(x, z, &h)) + if (!with_painting || !has_painting || !height_map->getInterpolatedValue(x, z, &h)) { h = _height_noise->get2DTotal(x, z); } diff --git a/src/definition/TerrainDefinition.h b/src/definition/TerrainDefinition.h index 65aa757..4a9a1d1 100644 --- a/src/definition/TerrainDefinition.h +++ b/src/definition/TerrainDefinition.h @@ -47,6 +47,7 @@ public: double shadow_smoothing; TerrainHeightMap* height_map; + bool has_painting; double _detail; NoiseGenerator* _height_noise; diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index 8e9d66e..83c59e8 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -63,6 +63,8 @@ SoftwareRenderer::~SoftwareRenderer() void SoftwareRenderer::prepare() { + scenery->validate(); + // Prepare sub renderers // TODO Don't recreate the renderer each time delete atmosphere_renderer;