Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
AreaStore Class Referenceabstract

#include <areastore.h>

+ Inheritance diagram for AreaStore:
+ Collaboration diagram for AreaStore:

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 AreagetArea (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 AreaStoregetOptimalImplementation ()
 

Protected Types

typedef std::map< u32, AreaAreaMap
 

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
 

Member Typedef Documentation

◆ AreaMap

typedef std::map<u32, Area> AreaStore::AreaMap
protected

Constructor & Destructor Documentation

◆ AreaStore()

AreaStore::AreaStore ( )
inline

◆ ~AreaStore()

virtual AreaStore::~AreaStore ( )
virtualdefault

Member Function Documentation

◆ cacheMiss()

void AreaStore::cacheMiss ( void * data,
const v3s16 & mpos,
std::vector< Area * > * dest )
staticprivate

Called by the cache when a value isn't found in the cache.

References getAreasInArea(), and m_cacheblock_radius.

+ Here is the call graph for this function:

◆ deserialize()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getArea()

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().

+ Here is the caller graph for this function:

◆ getAreasForPos()

void AreaStore::getAreasForPos ( std::vector< Area * > * result,
v3s16 pos )

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAreasForPosImpl()

virtual void AreaStore::getAreasForPosImpl ( std::vector< Area * > * result,
v3s16 pos )
protectedpure virtual

Implementation of getAreasForPos.

getAreasForPos calls this if the cache is disabled.

Implemented in SpatialAreaStore, and VectorAreaStore.

Referenced by getAreasForPos().

+ Here is the caller graph for this function:

◆ getAreasInArea()

virtual void AreaStore::getAreasInArea ( std::vector< Area * > * result,
v3s16 minedge,
v3s16 maxedge,
bool accept_overlap )
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().

+ Here is the caller graph for this function:

◆ getNextId()

u32 AreaStore::getNextId ( ) const
protected

Returns the next area ID and increments it.

References areas_map.

Referenced by SpatialAreaStore::insertArea(), and VectorAreaStore::insertArea().

+ Here is the caller graph for this function:

◆ getOptimalImplementation()

AreaStore * AreaStore::getOptimalImplementation ( )
static

◆ insertArea()

virtual bool AreaStore::insertArea ( Area * a)
pure virtual

Add an area to the store.

Updates the area's ID if it hasn't already been set.

Returns
Whether the area insertion was successful.

Implemented in SpatialAreaStore, and VectorAreaStore.

Referenced by deserialize(), TestAreaStore::genericStoreTest(), and LuaAreaStore::l_insert_area().

+ Here is the caller graph for this function:

◆ invalidateCache()

void AreaStore::invalidateCache ( )
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeArea()

virtual bool AreaStore::removeArea ( u32 id)
pure virtual

Removes an area from the store by ID.

Returns
Whether the area was in the store and removed.

Implemented in SpatialAreaStore, and VectorAreaStore.

Referenced by TestAreaStore::genericStoreTest(), and LuaAreaStore::l_remove_area().

+ Here is the caller graph for this function:

◆ reserve()

virtual void AreaStore::reserve ( size_t count)
inlinevirtual

Reimplemented in VectorAreaStore.

Referenced by TestAreaStore::genericStoreTest(), and LuaAreaStore::l_reserve().

+ Here is the caller graph for this function:

◆ serialize()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCacheParams()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

size_t AreaStore::size ( ) const
inline

References areas_map.

Referenced by TestAreaStore::genericStoreTest(), and TestAreaStore::testSerialization().

+ Here is the caller graph for this function:

Member Data Documentation

◆ areas_map

◆ m_cache_enabled

bool AreaStore::m_cache_enabled = true
private

◆ m_cacheblock_radius

u8 AreaStore::m_cacheblock_radius = 64
private

Range, in nodes, of the getAreasForPos cache.

If you modify this, call invalidateCache()

Referenced by cacheMiss(), getAreasForPos(), and setCacheParams().

◆ m_res_cache

LRUCache<v3s16, std::vector<Area *> > AreaStore::m_res_cache
private

The documentation for this class was generated from the following files: