From fa5708850ec8b4d7d9795501d1bba7b83aa5a30b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 22 Nov 2013 01:33:30 +0200 Subject: [PATCH] Automatically adjust the secondary_axis flag when elevations are changed --- source/libr2c2/terrain.cpp | 10 ++++++++-- source/libr2c2/terrain.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/libr2c2/terrain.cpp b/source/libr2c2/terrain.cpp index 5a31774..072a6e5 100644 --- a/source/libr2c2/terrain.cpp +++ b/source/libr2c2/terrain.cpp @@ -97,7 +97,7 @@ void Terrain::set_node_elevation(const NodeCoordinates &c, float elev, bool join Tile &tile = tiles[x+y*width]; if(tile.nodes[i].elevation==ref) { - tile.nodes[i].elevation = elev; + tile.set_node_elevation(i, elev); signal_tile_changed.emit(x, y); } } @@ -105,7 +105,7 @@ void Terrain::set_node_elevation(const NodeCoordinates &c, float elev, bool join } else { - tiles[c.x+c.y*width].nodes[c.i].elevation = elev; + tiles[c.x+c.y*width].set_node_elevation(c.i, elev); signal_tile_changed.emit(c.x, c.y); } } @@ -186,6 +186,12 @@ Terrain::Tile::Tile(): secondary_axis(false) { } +void Terrain::Tile::set_node_elevation(unsigned i, float e) +{ + nodes[i].elevation = e; + secondary_axis = ((nodes[1].elevation+nodes[2].elevation) < (nodes[0].elevation+nodes[3].elevation)); +} + void Terrain::Tile::save(list &st) const { bool flat = true; diff --git a/source/libr2c2/terrain.h b/source/libr2c2/terrain.h index 837119e..fb3328e 100644 --- a/source/libr2c2/terrain.h +++ b/source/libr2c2/terrain.h @@ -69,6 +69,7 @@ public: Tile(); + void set_node_elevation(unsigned, float); void save(std::list &) const; }; -- 2.45.2