voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
Public Types | Public Member Functions | Protected Member Functions | List of all members
blub::procedural::voxel::simple::container::inMemory< configType > Class Template Reference

The inMemory class stores all voxels in instances of tile::container and safes them in a very fast in-memory-container. Accessing a voxel-container costs O(1). The class does not save tiles that are full (container-tile returns true for isEmpty() ) or that are empty (container-tile returns true for isFull() ). Instead the class saves the state empty/full. Tiles that are full or empty dont produce a surface. More...

#include <inMemory.hpp>

Inheritance diagram for blub::procedural::voxel::simple::container::inMemory< configType >:
blub::procedural::voxel::simple::container::base< configType > blub::procedural::voxel::simple::base< configType::t_container::t_tile > blub::noncopyable

Public Types

typedef base< configType > t_base
 
typedef vector3int32map
< typename t_base::t_utilsTile > 
t_tilesMap
 
- Public Types inherited from blub::procedural::voxel::simple::container::base< configType >
typedef configType t_config
 
typedef t_config::t_data t_voxel
 
typedef
configType::t_container::t_tile 
t_tile
 
typedef simple::base< t_tile > t_base
 
typedef sharedPointer< t_tile > t_tilePtr
 
typedef utils::tile< t_tile > t_utilsTile
 
typedef sharedPointer
< edit::base< t_config > const > 
t_editConstPtr
 
typedef sharedPointer
< edit::base< t_config > > 
t_editPtr
 
typedef t_base::t_tileId t_tileId
 
typedef hashMap< t_tileId,
t_utilsTile
t_tilesGotChangedMap
 
- Public Types inherited from blub::procedural::voxel::simple::base< configType::t_container::t_tile >
typedef
configType::t_container::t_tile 
t_tile
 
typedef sharedPointer< t_tile > t_tilePtr
 
typedef base< t_tile > t_thisClass
 
typedef vector3int32 t_tileId
 
typedef hashMap< t_tileId,
t_tilePtr
t_tilesGotChangedMap
 
typedef std::function< t_tilePtr()> t_createTileCallback
 
typedef blub::signal< void()> t_sigEditDone
 

Public Member Functions

 inMemory (blub::async::dispatcher &worker)
 inMemory constructor More...
 
 ~inMemory ()
 ~inMemory descructor
 
t_base::t_utilsTile getTileHolder (const blub::vector3int32 &id) const override
 getTileHolder returns a utils::tileHolder setted by setTile() or by editVoxel(). Read-lock class before call. Read-lock the class before. More...
 
const t_tilesMapgetTilesMap () const
 getTilesMap returns all tiles. More...
 
void setTileBounds (const axisAlignedBoxInt32 &bounds)
 setTileBounds sets the size for the map. Call for optimization, if you know the tile-dimensions before editing. More...
 
const axisAlignedBoxInt32getTileBounds () const
 getTileBounds returns the tile bounds. More...
 
- Public Member Functions inherited from blub::procedural::voxel::simple::container::base< configType >
 base (blub::async::dispatcher &worker)
 base constructor. More...
 
void editVoxel (t_editConstPtr change, const transform &trans=blub::transform())
 editVoxel edits the container. Its guranteed that the edits are getting in order of calling this method. Returns immediately. Does NOT calculate any voxel, but creates and dispatches the jobs for it. More...
 
void setTile (const t_tileId &id, const t_utilsTile &toSet)
 editVoxel edits the container. Its guranteed that the edits are getting in order of calling this method. Returns immediately. Does NOT calculate any voxel, but creates and dispatches the jobs for it. More...
 
t_utilsTile getTileHolderByVoxelPosition (const blub::vector3int32 &pos) const
 getTileHolderByVoxelPosition returns a utils::tileHolder setted by setTile() or by editVoxel(). Read-lock class before call. More...
 
t_voxel getVoxel (const vector3int32 &voxelPos) const
 getVoxel returns an voxel. Read-lock the class before call. More...
 
const t_tilesGotChangedMapgetTilesThatGotEdited () const
 
- Public Member Functions inherited from blub::procedural::voxel::simple::base< configType::t_container::t_tile >
 base (blub::async::dispatcher &worker)
 base constructor More...
 
 ~base ()
 ~base destructor
 
void lockForEdit ()
 lockForEdit locks the class for editing/writing it. Call unlockForEdit() after work done. Method executes locks by the dispatcher master. More...
 
void unlockForEdit ()
 unlockForEdit unlocks edit/write-lock and calls signalEditDone() . Method executes unlock by the dispatcher master. More...
 
void lockForRead ()
 lockForRead locks the class for reading.
 
void unlockRead ()
 unlockRead unlocks the class after reading.
 
const t_tilesGotChangedMapgetTilesThatGotEdited () const
 getTilesThatGotEdited returns a list of tiles which changed since the last call lockForEdit() / lockForEditMaster() More...
 
void setCreateTileCallback (const t_createTileCallback &callback)
 setCreateTileCallback sets a callback for creating tiles. Use this method if you want to create custom tiles. More...
 
blub::async::strandgetMaster ()
 getMaster returns the master dispatcher. The master synchronises jobs for the worker-thread and writes to class member. The master calls all methods which end with *Master. More...
 
t_sigEditDonesignalEditDone ()
 signalEditDone gets called after unlockForEdit() got called. More...
 

Protected Member Functions

virtual void setTileToContainerMaster (const typename t_base::t_tileId id, const typename t_base::t_utilsTile &oldOne, const typename t_base::t_utilsTile &toSet)
 setTileToContainerMaster replaces a tile. Call method by one thread at a time. Write-lock class before. More...
 
void setTileMaster (const blub::vector3int32 &id, const typename t_base::t_utilsTile &toSet) override
 setTileMaster sets a tile to an id. Call by one thread at a time. More...
 
void setTileToFullMaster (const vector3int32 &id) override
 setTileToFullMaster sets a tiles voxel to maximum - for memory optimizations. Method gets called by a single thread at a time. More...
 
void setTileToEmtpyMaster (const vector3int32 &id) override
 setTileToFullMaster sets a tiles voxel to minimum - for memory optimizations. Method gets called by a single thread at a time. More...
 
template<class formatType >
BLUB_SERIALIZATION_ACCESS void save (formatType &readWrite, const uint32 &version) const
 
template<class formatType >
void load (formatType &readWrite, const uint32 &version)
 
template<class formatType >
void serialize (formatType &readWrite, const uint32 &version)
 
- Protected Member Functions inherited from blub::procedural::voxel::simple::container::base< configType >
void addToChangeList (const t_tileId &id, t_utilsTile toAdd)
 
void unlockForEditMaster () override
 unlockForEditMaster unlocks write. Call by master dispatcher.
 
bool tryLockForEditMaster () override
 tryLockForEditMaster tries to lock for write. Call by master dispatcher. More...
 
void lockForEditMaster () override
 lockForEditMaster locks for write, or waits until possible. Call by master dispatcher.
 
void editMaster (t_editConstPtr change, const blub::transform &trans)
 editMaster saves the edit in a qeue and starts to handle it. More...
 
void doNextEditMaster (const bool &alreadyLocked=false)
 doNextEditMaster finds out which tiles the edit affects and dispaches the change to the worker-threads. More...
 
void editVoxelWorker (t_editConstPtr change, const t_utilsTile &holder, const blub::vector3int32 &id, const blub::transform &trans)
 editVoxelWorker affects with change holder. Method gets called paralell by various threads. Method only affects the delivered holder. More...
 
void editVoxelDoneMaster (t_utilsTile tileHolder_, const blub::vector3int32 &id)
 editVoxelDoneMaster gets called after edit got applied on the tile. Call method only by one thread at a time. More...
 
virtual void setTileMaster (const t_tileId &id, const t_utilsTile &toSet)=0
 gets called by setTile. Call only by one thread at a time. Write-lock class before. More...
 
t_tilePtr getOrCreateTile (const vector3int32 &id)
 getOrCreateTile looks up if tile already exists. If not creates one. More...
 
- Protected Member Functions inherited from blub::procedural::voxel::simple::base< configType::t_container::t_tile >
void addToChangeList (const t_tileId &id, t_tilePtr toAdd)
 addToChangeList adds a tile to the change-list. More...
 
virtual t_tilePtr createTile () const
 createTile creates a new Tile. Uses callback set by setCreateTileCallback() More...
 

Additional Inherited Members

- Static Public Member Functions inherited from blub::procedural::voxel::simple::container::base< configType >
static t_tileId calculateVoxelPosToTileId (const vector3int32 &voxelPos)
 calculateVoxelPosToTileId converts an absolute voxel-position to an relative container-id position. More...
 
static vector3int32 calculateVoxelPosInTile (const vector3int32 &voxelPos)
 calculateVoxelPosInTile converts an absolute voxel-position to an relative container-confirm position. More...
 
- Protected Types inherited from blub::procedural::voxel::simple::container::base< configType >
typedef list< editTodot_editTodoList
 
- Static Protected Member Functions inherited from blub::procedural::voxel::simple::container::base< configType >
static t_tilePtr createTileFull (const bool &full)
 createTileFull creates a tile in which all voxel are maximum or minimum. More...
 
static void calculateAffectetedTilesByAabb (const axisAlignedBoxInt32 &voxelAabb, t_tileId &startResult, t_tileId &endResult)
 calculateAffectetedTilesByAabb caluclates a list of affected tiles by an axisAlignedBox. Used to determine which tiles to recalculate for an edit. More...
 
- Protected Attributes inherited from blub::procedural::voxel::simple::container::base< configType >
int32 m_numInTilesInTask
 
t_editTodoList m_editsTodo
 
t_tilesGotChangedMap m_tilesThatGotEdited
 
- Protected Attributes inherited from blub::procedural::voxel::simple::base< configType::t_container::t_tile >
blub::async::strand m_master
 m_master The master synchronises jobs for the worker-thread and writes to class member. The master calls all methods which end with *Master.
 
blub::async::dispatcherm_worker
 m_worker use it to dispatch heavy work. Don't write to class member with it. Do not use any locks. Use m_master for such tasks.
 
t_tilesGotChangedMap m_tilesThatGotEdited
 
t_createTileCallback m_createTileCallback
 
async::mutexReadWrite m_classLocker
 
t_sigEditDone m_sigEditDone
 

Detailed Description

template<class configType>
class blub::procedural::voxel::simple::container::inMemory< configType >

The inMemory class stores all voxels in instances of tile::container and safes them in a very fast in-memory-container. Accessing a voxel-container costs O(1). The class does not save tiles that are full (container-tile returns true for isEmpty() ) or that are empty (container-tile returns true for isFull() ). Instead the class saves the state empty/full. Tiles that are full or empty dont produce a surface.

Examples:
customVertexInformation.cpp, mesh.cpp, noise.cpp, and primitives.cpp.

Constructor & Destructor Documentation

template<class configType>
blub::procedural::voxel::simple::container::inMemory< configType >::inMemory ( blub::async::dispatcher worker)
inline

inMemory constructor

Parameters
workerMay gets called by several threads.

Member Function Documentation

template<class configType>
const axisAlignedBoxInt32& blub::procedural::voxel::simple::container::inMemory< configType >::getTileBounds ( ) const
inline

getTileBounds returns the tile bounds.

Returns
template<class configType>
t_base::t_utilsTile blub::procedural::voxel::simple::container::inMemory< configType >::getTileHolder ( const blub::vector3int32 id) const
inlineoverridevirtual

getTileHolder returns a utils::tileHolder setted by setTile() or by editVoxel(). Read-lock class before call. Read-lock the class before.

Parameters
idIdentifier. Contains voxel from id*blub::procedural::voxel::tile::container::voxelLength to (id+1)*blub::procedural::voxel::tile::container::voxelLength-1
Returns
Always returns a valid value. If nothing found state in utils::tile gets set to empty.

Implements blub::procedural::voxel::simple::container::base< configType >.

template<class configType>
const t_tilesMap& blub::procedural::voxel::simple::container::inMemory< configType >::getTilesMap ( ) const
inline

getTilesMap returns all tiles.

Returns
template<class configType>
void blub::procedural::voxel::simple::container::inMemory< configType >::setTileBounds ( const axisAlignedBoxInt32 bounds)
inline

setTileBounds sets the size for the map. Call for optimization, if you know the tile-dimensions before editing.

Parameters
bounds
template<class configType>
void blub::procedural::voxel::simple::container::inMemory< configType >::setTileMaster ( const blub::vector3int32 id,
const typename t_base::t_utilsTile &  toSet 
)
inlineoverrideprotected

setTileMaster sets a tile to an id. Call by one thread at a time.

Parameters
idTileId
toSet
template<class configType>
virtual void blub::procedural::voxel::simple::container::inMemory< configType >::setTileToContainerMaster ( const typename t_base::t_tileId  id,
const typename t_base::t_utilsTile &  oldOne,
const typename t_base::t_utilsTile &  toSet 
)
inlineprotectedvirtual

setTileToContainerMaster replaces a tile. Call method by one thread at a time. Write-lock class before.

Parameters
idTileId
oldOneNot used - may be interesting in derived classes.
toSet

Reimplemented in blub::procedural::voxel::simple::container::database< voxelType >.

template<class configType>
void blub::procedural::voxel::simple::container::inMemory< configType >::setTileToEmtpyMaster ( const vector3int32 id)
inlineoverrideprotectedvirtual

setTileToFullMaster sets a tiles voxel to minimum - for memory optimizations. Method gets called by a single thread at a time.

Parameters
idTileId

Implements blub::procedural::voxel::simple::container::base< configType >.

template<class configType>
void blub::procedural::voxel::simple::container::inMemory< configType >::setTileToFullMaster ( const vector3int32 id)
inlineoverrideprotectedvirtual

setTileToFullMaster sets a tiles voxel to maximum - for memory optimizations. Method gets called by a single thread at a time.

Parameters
idTileId

Implements blub::procedural::voxel::simple::container::base< configType >.


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