1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Sort AreaStore header

This commit is contained in:
ShadowNinja 2015-10-30 00:52:45 -04:00
parent 5641da43d6
commit 6e9d71342a
2 changed files with 70 additions and 75 deletions

View file

@ -39,21 +39,55 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct Area {
Area() {}
Area(const v3s16 &mine, const v3s16 &maxe)
Area(const v3s16 &mine, const v3s16 &maxe) :
minedge(mine), maxedge(maxe)
{
minedge = mine;
maxedge = maxe;
sortBoxVerticies(minedge, maxedge);
}
u32 id;
v3s16 minedge;
v3s16 maxedge;
v3s16 minedge, maxedge;
std::string data;
};
class AreaStore {
public:
AreaStore() :
m_cache_enabled(true),
m_cacheblock_radius(64),
m_res_cache(1000, &cacheMiss, this),
m_next_id(0)
{}
virtual ~AreaStore() {}
static AreaStore *getOptimalImplementation();
virtual void reserve(size_t count) {};
size_t size() const { return areas_map.size(); }
// Updates the area's ID
virtual bool insertArea(Area *a) = 0;
virtual bool removeArea(u32 id) = 0;
void getAreasForPos(std::vector<Area *> *result, v3s16 pos);
virtual void getAreasInArea(std::vector<Area *> *result,
v3s16 minedge, v3s16 maxedge, bool accept_overlap) = 0;
void setCacheParams(bool enabled, u8 block_radius, size_t limit);
const Area *getArea(u32 id) const;
#if 0
typedef bool (*ForEachCallback)(const Area *a, void *arg);
// Calls a passed function for every stored area, until the
// callback returns true. If that happens, it returns true,
// if the search is exhausted, it returns false.
virtual bool forEach(ForEachCallback, void *arg=NULL) const = 0;
void serialize(std::ostream &is) const;
bool deserialize(std::istream &is);
#endif
protected:
void invalidateCache();
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos) = 0;
@ -63,98 +97,64 @@ protected:
// references would be invalidated on rehash.
typedef std::map<u32, Area> AreaMap;
AreaMap areas_map;
public:
// Updates the area's ID
virtual bool insertArea(Area *a) = 0;
virtual void reserve(size_t count) {};
virtual bool removeArea(u32 id) = 0;
void getAreasForPos(std::vector<Area *> *result, v3s16 pos);
virtual void getAreasInArea(std::vector<Area *> *result,
v3s16 minedge, v3s16 maxedge, bool accept_overlap) = 0;
#if 0
// calls a passed function for every stored area, until the
// callback returns true. If that happens, it returns true,
// if the search is exhausted, it returns false
virtual bool forEach(bool (*callback)(void *args, Area *a), void *args) const = 0;
#endif
virtual ~AreaStore()
{}
AreaStore() :
m_cacheblock_radius(64),
m_res_cache(1000, &cacheMiss, this),
m_next_id(0),
m_cache_enabled(true)
{
}
void setCacheParams(bool enabled, u8 block_radius, size_t limit);
const Area *getArea(u32 id) const;
u16 size() const;
static AreaStore *getOptimalImplementation();
#if 0
bool deserialize(std::istream &is);
void serialize(std::ostream &is) const;
#endif
private:
static void cacheMiss(void *data, const v3s16 &mpos, std::vector<Area *> *dest);
bool m_cache_enabled;
u8 m_cacheblock_radius; // if you modify this, call invalidateCache()
LRUCache<v3s16, std::vector<Area *> > m_res_cache;
u32 m_next_id;
bool m_cache_enabled;
};
class VectorAreaStore : public AreaStore {
protected:
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos);
public:
virtual void reserve(size_t count) { m_areas.reserve(count); }
virtual bool insertArea(Area *a);
virtual bool removeArea(u32 id);
virtual void getAreasInArea(std::vector<Area *> *result,
v3s16 minedge, v3s16 maxedge, bool accept_overlap);
// virtual bool forEach(bool (*callback)(void *args, Area *a), void *args) const;
//virtual bool forEach(ForEachCallback, void *arg) const;
protected:
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos);
private:
std::vector<Area *> m_areas;
};
#if USE_SPATIAL
class SpatialAreaStore : public AreaStore {
protected:
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos);
public:
SpatialAreaStore();
virtual ~SpatialAreaStore();
virtual bool insertArea(Area *a);
virtual bool removeArea(u32 id);
virtual void getAreasInArea(std::vector<Area *> *result,
v3s16 minedge, v3s16 maxedge, bool accept_overlap);
// virtual bool forEach(bool (*callback)(void *args, Area *a), void *args) const;
//virtual bool forEach(ForEachCallback, void *arg) const;
protected:
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos);
virtual ~SpatialAreaStore();
private:
SpatialIndex::ISpatialIndex *m_tree;
SpatialIndex::IStorageManager *m_storagemanager;
class VectorResultVisitor : public SpatialIndex::IVisitor {
private:
SpatialAreaStore *m_store;
std::vector<Area *> *m_result;
public:
VectorResultVisitor(std::vector<Area *> *result, SpatialAreaStore *store)
{
m_store = store;
m_result = result;
}
VectorResultVisitor(std::vector<Area *> *result, SpatialAreaStore *store) :
m_store(store),
m_result(result)
{}
~VectorResultVisitor() {}
virtual void visitNode(const SpatialIndex::INode &in)
{
}
virtual void visitNode(const SpatialIndex::INode &in) {}
virtual void visitData(const SpatialIndex::IData &in)
{
@ -171,10 +171,12 @@ private:
visitData(*(v[i]));
}
~VectorResultVisitor() {}
private:
SpatialAreaStore *m_store;
std::vector<Area *> *m_result;
};
};
#endif
#endif // USE_SPATIAL
#endif // AREA_STORE_H_