#include <areastore.h>
Public Member Functions | |
AreaStore () | |
virtual | ~AreaStore ()=default |
virtual void | reserve (size_t count) |
size_t | size () const |
virtual bool | insertArea (Area *a)=0 |
Add an area to the store. | |
virtual bool | removeArea (u32 id)=0 |
Removes an area from the store by ID. | |
void | getAreasForPos (std::vector< Area * > *result, v3s16 pos) |
Finds areas that the passed position is contained in. | |
virtual void | getAreasInArea (std::vector< Area * > *result, v3s16 minedge, v3s16 maxedge, bool accept_overlap)=0 |
Finds areas that are completely contained inside the area defined by the passed edges. | |
void | setCacheParams (bool enabled, u8 block_radius, size_t limit) |
Sets cache parameters. | |
const Area * | getArea (u32 id) const |
Returns a pointer to the area coresponding to the passed ID, or NULL if it doesn't exist. | |
void | serialize (std::ostream &is) const |
Serializes the store's areas to a binary ostream. | |
void | deserialize (std::istream &is) |
Deserializes the Areas from a binary istream. | |
Static Public Member Functions | |
static AreaStore * | getOptimalImplementation () |
Protected Types | |
typedef std::map< u32, Area > | AreaMap |
Protected Member Functions | |
void | invalidateCache () |
Invalidates the getAreasForPos cache. | |
virtual void | getAreasForPosImpl (std::vector< Area * > *result, v3s16 pos)=0 |
Implementation of getAreasForPos. | |
u32 | getNextId () const |
Returns the next area ID and increments it. | |
Protected Attributes | |
AreaMap | areas_map |
Static Private Member Functions | |
static void | cacheMiss (void *data, const v3s16 &mpos, std::vector< Area * > *dest) |
Called by the cache when a value isn't found in the cache. | |
Private Attributes | |
bool | m_cache_enabled = true |
u8 | m_cacheblock_radius = 64 |
Range, in nodes, of the getAreasForPos cache. | |
LRUCache< v3s16, std::vector< Area * > > | m_res_cache |
|
protected |
|
inline |
|
virtualdefault |
|
staticprivate |
Called by the cache when a value isn't found in the cache.
References getAreasInArea(), and m_cacheblock_radius.
void AreaStore::deserialize | ( | std::istream & | is | ) |
Deserializes the Areas from a binary istream.
This does not currently clear the AreaStore before adding the areas, making it possible to deserialize multiple serialized AreaStores.
References Area::data, insertArea(), Area::maxedge, Area::minedge, readU16(), readU32(), readU8(), readV3S16(), and U32_MAX.
Referenced by deserialization_helper(), and TestAreaStore::testSerialization().
const Area * AreaStore::getArea | ( | u32 | id | ) | const |
Returns a pointer to the area coresponding to the passed ID, or NULL if it doesn't exist.
References areas_map.
Referenced by LuaAreaStore::l_get_area().
Finds areas that the passed position is contained in.
Stores output in passed vector.
References AST_CONTAINS_PT, getAreasForPosImpl(), getContainerPos(), LRUCache< K, V >::lookupCache(), m_cache_enabled, m_cacheblock_radius, and m_res_cache.
Referenced by TestAreaStore::genericStoreTest(), and LuaAreaStore::l_get_areas_for_pos().
|
protectedpure virtual |
Implementation of getAreasForPos.
getAreasForPos calls this if the cache is disabled.
Implemented in SpatialAreaStore, and VectorAreaStore.
Referenced by getAreasForPos().
|
pure virtual |
Finds areas that are completely contained inside the area defined by the passed edges.
If accept_overlap
is true this finds any areas that intersect with the passed area at any point.
Implemented in SpatialAreaStore, and VectorAreaStore.
Referenced by cacheMiss(), TestAreaStore::genericStoreTest(), and LuaAreaStore::l_get_areas_in_area().
|
protected |
Returns the next area ID and increments it.
References areas_map.
Referenced by SpatialAreaStore::insertArea(), and VectorAreaStore::insertArea().
|
static |
|
pure virtual |
Add an area to the store.
Updates the area's ID if it hasn't already been set.
Implemented in SpatialAreaStore, and VectorAreaStore.
Referenced by deserialize(), TestAreaStore::genericStoreTest(), and LuaAreaStore::l_insert_area().
|
protected |
Invalidates the getAreasForPos cache.
Call after adding or removing an area.
References LRUCache< K, V >::invalidate(), m_cache_enabled, and m_res_cache.
Referenced by SpatialAreaStore::insertArea(), VectorAreaStore::insertArea(), SpatialAreaStore::removeArea(), VectorAreaStore::removeArea(), and setCacheParams().
|
pure virtual |
Removes an area from the store by ID.
Implemented in SpatialAreaStore, and VectorAreaStore.
Referenced by TestAreaStore::genericStoreTest(), and LuaAreaStore::l_remove_area().
|
inlinevirtual |
Reimplemented in VectorAreaStore.
Referenced by TestAreaStore::genericStoreTest(), and LuaAreaStore::l_reserve().
void AreaStore::serialize | ( | std::ostream & | is | ) | const |
Serializes the store's areas to a binary ostream.
References areas_map, Area::data, Area::maxedge, Area::minedge, writeU16(), writeU32(), writeU8(), and writeV3S16().
Referenced by LuaAreaStore::l_to_file(), LuaAreaStore::l_to_string(), and TestAreaStore::testSerialization().
void AreaStore::setCacheParams | ( | bool | enabled, |
u8 | block_radius, | ||
size_t | limit ) |
Sets cache parameters.
References invalidateCache(), m_cache_enabled, m_cacheblock_radius, m_res_cache, MYMAX, and LRUCache< K, V >::setLimit().
Referenced by LuaAreaStore::l_set_cache_params().
|
inline |
References areas_map.
Referenced by TestAreaStore::genericStoreTest(), and TestAreaStore::testSerialization().
|
protected |
|
private |
Referenced by getAreasForPos(), invalidateCache(), and setCacheParams().
|
private |
Range, in nodes, of the getAreasForPos cache.
If you modify this, call invalidateCache()
Referenced by cacheMiss(), getAreasForPos(), and setCacheParams().
Referenced by getAreasForPos(), invalidateCache(), and setCacheParams().