51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef AREA_STORE_H_
-#define AREA_STORE_H_
+#pragma once
#include "irr_v3d.h"
#include "noise.h" // for PcgRandom
struct Area {
- Area() {}
- Area(const v3s16 &mine, const v3s16 &maxe) :
- minedge(mine), maxedge(maxe)
+ Area(u32 area_id) : id(area_id) {}
+
+ Area(const v3s16 &mine, const v3s16 &maxe, u32 area_id = U32_MAX) :
+ id(area_id), minedge(mine), maxedge(maxe)
{
sortBoxVerticies(minedge, maxedge);
}
class AreaStore {
public:
AreaStore() :
- m_cache_enabled(true),
- m_cacheblock_radius(64),
- m_res_cache(1000, &cacheMiss, this),
- m_next_id(0)
+ m_res_cache(1000, &cacheMiss, this)
{}
- virtual ~AreaStore() {}
+ virtual ~AreaStore() = default;
static AreaStore *getOptimalImplementation();
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.
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos) = 0;
/// Returns the next area ID and increments it.
- u32 getNextId() { return m_next_id++; }
+ u32 getNextId() const;
// Note: This can't be an unordered_map, since all
// references would be invalidated on rehash.
/// Called by the cache when a value isn't found in the cache.
static void cacheMiss(void *data, const v3s16 &mpos, std::vector<Area *> *dest);
- bool m_cache_enabled;
+ bool m_cache_enabled = true;
/// Range, in nodes, of the getAreasForPos cache.
/// If you modify this, call invalidateCache()
- u8 m_cacheblock_radius;
+ u8 m_cacheblock_radius = 64;
LRUCache<v3s16, std::vector<Area *> > m_res_cache;
-
- u32 m_next_id;
};
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos);
private:
- SpatialIndex::ISpatialIndex *m_tree;
- SpatialIndex::IStorageManager *m_storagemanager;
+ SpatialIndex::ISpatialIndex *m_tree = nullptr;
+ SpatialIndex::IStorageManager *m_storagemanager = nullptr;
class VectorResultVisitor : public SpatialIndex::IVisitor {
public:
}
private:
- SpatialAreaStore *m_store;
- std::vector<Area *> *m_result;
+ SpatialAreaStore *m_store = nullptr;
+ std::vector<Area *> *m_result = nullptr;
};
};
#endif // USE_SPATIAL
-
-#endif // AREA_STORE_H_