summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/areastore.cpp6
-rw-r--r--src/util/areastore.h7
2 files changed, 8 insertions, 5 deletions
diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp
index 17addb3af..58f08a8c2 100644
--- a/src/util/areastore.cpp
+++ b/src/util/areastore.cpp
@@ -160,7 +160,8 @@ void AreaStore::getAreasForPos(std::vector<Area *> *result, v3s16 pos)
bool VectorAreaStore::insertArea(Area *a)
{
- a->id = getNextId();
+ if (a->id == U32_MAX)
+ a->id = getNextId();
std::pair<AreaMap::iterator, bool> res =
areas_map.insert(std::make_pair(a->id, *a));
if (!res.second)
@@ -232,7 +233,8 @@ static inline SpatialIndex::Point get_spatial_point(const v3s16 pos)
bool SpatialAreaStore::insertArea(Area *a)
{
- a->id = getNextId();
+ if (a->id == U32_MAX)
+ a->id = getNextId();
if (!areas_map.insert(std::make_pair(a->id, *a)).second)
// ID is not unique
return false;
diff --git a/src/util/areastore.h b/src/util/areastore.h
index ab6bd76a3..bebecfd78 100644
--- a/src/util/areastore.h
+++ b/src/util/areastore.h
@@ -38,9 +38,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct Area {
- Area() {}
+ Area() : id(U32_MAX) {}
Area(const v3s16 &mine, const v3s16 &maxe) :
- minedge(mine), maxedge(maxe)
+ id(U32_MAX), minedge(mine), maxedge(maxe)
{
sortBoxVerticies(minedge, maxedge);
}
@@ -68,7 +68,8 @@ public:
size_t size() const { return areas_map.size(); }
/// Add an area to the store.
- /// Updates the area's ID.
+ /// Updates the area's ID if it hasn't already been set.
+ /// @return Whether the area insertion was successful.
virtual bool insertArea(Area *a) = 0;
/// Removes an area from the store by ID.