After some testing Region seems OK

This commit is contained in:
Kayne Ruse
2013-09-19 22:52:26 +10:00
parent 9b64c67068
commit 9cbbfe77b7
3 changed files with 10 additions and 9 deletions
+5 -4
View File
@@ -59,9 +59,6 @@ bool Region::NewTileR(Tile const& tile) {
} }
Tile Region::GetTileR(int tx, int ty, int tw, int th, int minDepth) { Tile Region::GetTileR(int tx, int ty, int tw, int th, int minDepth) {
//find the first tile at this location, with the specified minimum depth
//since neither the Region or Tile classes store the tile sizes,
//this function takes the sizes as arguments
std::set<Tile>::iterator ptr = tiles.begin(); std::set<Tile>::iterator ptr = tiles.begin();
while(ptr != tiles.end()) { while(ptr != tiles.end()) {
//skip the tiles that are too deep //skip the tiles that are too deep
@@ -80,13 +77,17 @@ Tile Region::GetTileR(int tx, int ty, int tw, int th, int minDepth) {
if (ptr != tiles.end()) { if (ptr != tiles.end()) {
return *ptr; return *ptr;
} }
return {0,0,0,-1}; //value = -1 is a crappy error code return {0,0,0,-1}; //TODO: value = -1 is a crappy error code
} }
bool Region::DeleteTileR(Tile const& tile) { bool Region::DeleteTileR(Tile const& tile) {
if (!InBoundsR(tile.x, tile.y)) { if (!InBoundsR(tile.x, tile.y)) {
throw(std::runtime_error("Deleted tile location out of bounds")); throw(std::runtime_error("Deleted tile location out of bounds"));
} }
//sentinel
if (tile.value == -1) {
return 0;
}
return tiles.erase(tile); return tiles.erase(tile);
} }
+1 -1
View File
@@ -89,7 +89,7 @@ public:
friend bool operator>(Region const& lhs, Region const& rhs); friend bool operator>(Region const& lhs, Region const& rhs);
friend bool operator==(Region const& lhs, Region const& rhs); friend bool operator==(Region const& lhs, Region const& rhs);
private: public: //TMP
int const x; int const x;
int const y; int const y;
int const width; int const width;
+4 -4
View File
@@ -29,10 +29,10 @@ struct Tile {
Tile() = default; Tile() = default;
Tile(int i, int j, int k, int l) : x(i), y(j), depth(k), value(l) {} Tile(int i, int j, int k, int l) : x(i), y(j), depth(k), value(l) {}
friend bool operator<(Tile const& lhs, Tile const& rhs);
friend bool operator>(Tile const& lhs, Tile const& rhs);
friend bool operator==(Tile const& lhs, Tile const& rhs);
}; };
bool operator<(Tile const& lhs, Tile const& rhs);
bool operator>(Tile const& lhs, Tile const& rhs);
bool operator==(Tile const& lhs, Tile const& rhs);
#endif #endif