Fixed terrain painting not updating has_painting

This commit is contained in:
Michaël Lemaire 2015-09-21 19:37:17 +02:00
parent ec69975146
commit c51d6d2d35
5 changed files with 52 additions and 30 deletions

View file

@ -140,7 +140,7 @@ void PaintedGrid::clearPainting()
brush_data->clear();
}
void PaintedGrid::applyBrush(const PaintedGridBrush &brush, double x, double y, double force)
void PaintedGrid::applyBrush(const PaintedGridBrush &brush, double x, double y, double force, bool commit)
{
int xstart, xend, ystart, yend;
@ -165,6 +165,11 @@ void PaintedGrid::applyBrush(const PaintedGridBrush &brush, double x, double y,
}
}
}
if (commit)
{
endBrushStroke();
}
}
void PaintedGrid::endBrushStroke()

View file

@ -62,17 +62,17 @@ public:
/**
* Clear all painting and reset the initial value everywhere.
*/
void clearPainting();
virtual void clearPainting();
/**
* Apply a brush stroke at a grid location (locating the brush center).
*/
void applyBrush(const PaintedGridBrush &brush, double x, double y, double force);
virtual void applyBrush(const PaintedGridBrush &brush, double x, double y, double force, bool commit=false);
/**
* Commit previous brush strokes.
*/
void endBrushStroke();
virtual void endBrushStroke();
/**
* Virtual method that can be reimplemented to provide the initial value at a grid location.

View file

@ -22,32 +22,46 @@ double TerrainHeightMap::getInitialValue(double x, double y) const
return terrain->getInterpolatedHeight(x, y, false, false);
}
void TerrainHeightMap::brushElevation(const PaintedGridBrush &brush, double x, double y, double value)
void TerrainHeightMap::brushElevation(const PaintedGridBrush &brush, double x, double y, double value, bool commit)
{
PaintedGridBrushRaiseLower sbrush(brush);
applyBrush(sbrush, x, y, value / terrain->height);
applyBrush(sbrush, x, y, value / terrain->height, commit);
}
void TerrainHeightMap::brushFlatten(const PaintedGridBrush &brush, double x, double y, double height, double force)
void TerrainHeightMap::brushFlatten(const PaintedGridBrush &brush, double x, double y, double height, double force, bool commit)
{
PaintedGridBrushFlatten sbrush(brush, height);
applyBrush(sbrush, x, y, force / terrain->height);
applyBrush(sbrush, x, y, force / terrain->height, commit);
}
void TerrainHeightMap::brushSmooth(const PaintedGridBrush &brush, double x, double y, double value)
void TerrainHeightMap::brushSmooth(const PaintedGridBrush &brush, double x, double y, double value, bool commit)
{
PaintedGridBrushSmooth sbrush(brush);
applyBrush(sbrush, x, y, value / terrain->height);
applyBrush(sbrush, x, y, value / terrain->height, commit);
}
void TerrainHeightMap::brushAddNoise(const PaintedGridBrush &brush, double x, double y, NoiseGenerator* generator, double value)
void TerrainHeightMap::brushAddNoise(const PaintedGridBrush &brush, double x, double y, NoiseGenerator* generator, double value, bool commit)
{
PaintedGridBrushAddNoise sbrush(brush, generator);
applyBrush(sbrush, x, y, value / terrain->height);
applyBrush(sbrush, x, y, value / terrain->height, commit);
}
void TerrainHeightMap::brushReset(const PaintedGridBrush &brush, double x, double y, double value)
void TerrainHeightMap::brushReset(const PaintedGridBrush &brush, double x, double y, double value, bool commit)
{
PaintedGridBrushReset sbrush(brush);
applyBrush(sbrush, x, y, value / terrain->height);
applyBrush(sbrush, x, y, value / terrain->height, commit);
}
void TerrainHeightMap::clearPainting()
{
PaintedGrid::clearPainting();
terrain->validate();
}
void TerrainHeightMap::endBrushStroke()
{
PaintedGrid::endBrushStroke();
terrain->validate();
}

View file

@ -19,11 +19,14 @@ public:
virtual double getInitialValue(double x, double y) const override;
void brushElevation(const PaintedGridBrush &brush, double x, double y, double value);
void brushSmooth(const PaintedGridBrush &brush, double x, double y, double value);
void brushAddNoise(const PaintedGridBrush &brush, double x, double y, NoiseGenerator* generator, double value);
void brushReset(const PaintedGridBrush &brush, double x, double y, double value);
void brushFlatten(const PaintedGridBrush &brush, double x, double y, double height, double force);
void brushElevation(const PaintedGridBrush &brush, double x, double y, double value, bool commit=false);
void brushSmooth(const PaintedGridBrush &brush, double x, double y, double value, bool commit=false);
void brushAddNoise(const PaintedGridBrush &brush, double x, double y, NoiseGenerator* generator, double value, bool commit=false);
void brushReset(const PaintedGridBrush &brush, double x, double y, double value, bool commit=false);
void brushFlatten(const PaintedGridBrush &brush, double x, double y, double height, double force, bool commit=false);
virtual void clearPainting() override;
virtual void endBrushStroke() override;
private:
TerrainDefinition* terrain;

View file

@ -113,24 +113,24 @@ TEST_F(TerrainPainting_Test, brush_flatten)
/* Test flattening center at 0.5 */
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0);
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0, true);
_checkBrushResult(terrain, &brush, 0.5, 0.5, 0.5, 0.25, 0.0, 0.0, 0);
/* Test brush strength */
terrain->height_map->clearPainting();
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01);
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01, true);
_checkBrushResult(terrain, &brush, 0.005, 0.005, 0.005, 0.0025, 0.0, 0.0, 0);
/* Test cumulative effect */
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01);
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01, true);
_checkBrushResult(terrain, &brush, 0.00995, 0.00995, 0.00995, 0.0049875, 0.0, 0.0, 0);
/* Test with height modifier */
terrain->height = 10.0;
terrain->height_map->clearPainting();
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0);
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0, true);
_checkBrushResult(terrain, &brush, 0.05, 0.05, 0.05, 0.025, 0.0, 0.0, 0);
}
@ -144,29 +144,29 @@ TEST_F(TerrainPainting_Test, brush_reset)
/* Test resetting at center */
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0);
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0, true);
_checkBrushResult(terrain, &brush, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 0);
terrain->height_map->brushReset(brush, 0.0, 0.0, 1.0);
terrain->height_map->brushReset(brush, 0.0, 0.0, 1.0, true);
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.5, 2.0, 1.0, 0);
/* Test brush strength */
terrain->height_map->clearPainting();
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0);
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0, true);
_checkBrushResult(terrain, &brush, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 0);
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1);
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1, true);
_checkBrushResult(terrain, &brush, 1.9, 1.9, 1.9, 1.95, 2.0, 1.0, 0);
/* Test cumulative effect */
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1);
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1, true);
_checkBrushResult(terrain, &brush, 1.81, 1.81, 1.81, 1.9025, 2.0, 1.0, 0);
/* Test with height modifier */
terrain->height = 10.0;
terrain->height_map->clearPainting();
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0);
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0, true);
_checkBrushResult(terrain, &brush, 1.1, 1.1, 1.1, 1.1, 1.1, 1.0, 0);
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1);
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1, true);
_checkBrushResult(terrain, &brush, 1.099, 1.099, 1.099, 1.0995, 1.1, 1.0, 0);
}