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

The base class is getting derived by all container classes. The class handles synchronisation and paralellisation of edits and provides several voxel-getter/setter. All methods are threadsafe, if not declared different. More...

#include <base.hpp>

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

Classes

struct  editTodo
 The editTodo struct holds the edit information, for the dispatcher. A primitive buffer for the paramters delivered by editVoxel(). More...
 

Public Types

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

 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...
 
virtual t_utilsTile getTileHolder (const t_tileId &id) const =0
 getTileHolder returns a utils::tileHolder setted by setTile() or by editVoxel(). Read-lock class before call. Read-lock the class before. 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...
 

Static Public Member Functions

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

typedef list< editTodot_editTodoList
 

Protected Member Functions

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...
 
virtual void setTileToFullMaster (const t_tileId &id)=0
 setTileToFullMaster sets a tiles voxel to maximum - for memory optimizations. Method gets called by a single thread at a time. More...
 
virtual void setTileToEmtpyMaster (const t_tileId &id)=0
 setTileToFullMaster sets a tiles voxel to minimum - for memory optimizations. Method gets called by a single thread at a time. 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...
 

Static Protected Member Functions

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

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::base< configType >

The base class is getting derived by all container classes. The class handles synchronisation and paralellisation of edits and provides several voxel-getter/setter. All methods are threadsafe, if not declared different.

Constructor & Destructor Documentation

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

base constructor.

Parameters
workermay gets run by several threads.

Member Function Documentation

template<class configType>
static void blub::procedural::voxel::simple::container::base< configType >::calculateAffectetedTilesByAabb ( const axisAlignedBoxInt32 voxelAabb,
t_tileId startResult,
t_tileId endResult 
)
inlinestaticprotected

calculateAffectetedTilesByAabb caluclates a list of affected tiles by an axisAlignedBox. Used to determine which tiles to recalculate for an edit.

Parameters
voxelAabbaxisAlignedBox
startResultResulting minId.
endResultResulting maxId.
template<class configType>
static vector3int32 blub::procedural::voxel::simple::container::base< configType >::calculateVoxelPosInTile ( const vector3int32 voxelPos)
inlinestatic

calculateVoxelPosInTile converts an absolute voxel-position to an relative container-confirm position.

Parameters
voxelPosAn absolute voxel-postion.
Returns
A inside tile position. Voxel-position of voxelPos inside a tile.
template<class configType>
static t_tileId blub::procedural::voxel::simple::container::base< configType >::calculateVoxelPosToTileId ( const vector3int32 voxelPos)
inlinestatic

calculateVoxelPosToTileId converts an absolute voxel-position to an relative container-id position.

Parameters
voxelPosAn absolute voxel-postion.
Returns
A absolute tile-id
template<class configType>
static t_tilePtr blub::procedural::voxel::simple::container::base< configType >::createTileFull ( const bool &  full)
inlinestaticprotected

createTileFull creates a tile in which all voxel are maximum or minimum.

Parameters
fullIf false all voxel get initialised with default value.
Returns
Never nullptr.
template<class configType>
void blub::procedural::voxel::simple::container::base< configType >::doNextEditMaster ( const bool &  alreadyLocked = false)
inlineprotected

doNextEditMaster finds out which tiles the edit affects and dispaches the change to the worker-threads.

Parameters
alreadyLockedoptimization parameter, if class is already write locked. (indirect recursive calls)
template<class configType>
void blub::procedural::voxel::simple::container::base< configType >::editMaster ( t_editConstPtr  change,
const blub::transform trans 
)
inlineprotected

editMaster saves the edit in a qeue and starts to handle it.

Parameters
changeMust not be nullptr.
transThe transform.
template<class configType>
void blub::procedural::voxel::simple::container::base< configType >::editVoxel ( t_editConstPtr  change,
const transform trans = blub::transform() 
)
inline

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.

Parameters
changeMust not be nullptr
transThe transform of the edit.
Examples:
customVertexInformation.cpp, mesh.cpp, noise.cpp, and primitives.cpp.
template<class configType>
void blub::procedural::voxel::simple::container::base< configType >::editVoxelDoneMaster ( t_utilsTile  tileHolder_,
const blub::vector3int32 id 
)
inlineprotected

editVoxelDoneMaster gets called after edit got applied on the tile. Call method only by one thread at a time.

Parameters
tileHolder_Affected tile.
idTile identifier.
template<class configType>
void blub::procedural::voxel::simple::container::base< configType >::editVoxelWorker ( t_editConstPtr  change,
const t_utilsTile holder,
const blub::vector3int32 id,
const blub::transform trans 
)
inlineprotected

editVoxelWorker affects with change holder. Method gets called paralell by various threads. Method only affects the delivered holder.

Parameters
changeThe edit.
holderThe tile which gets affected.
idTileId.
transTransform.
template<class configType>
t_tilePtr blub::procedural::voxel::simple::container::base< configType >::getOrCreateTile ( const vector3int32 id)
inlineprotected

getOrCreateTile looks up if tile already exists. If not creates one.

Parameters
idTileId
Returns
Valid Tile. Never nullptr.
template<class configType>
virtual t_utilsTile blub::procedural::voxel::simple::container::base< configType >::getTileHolder ( const t_tileId id) const
pure virtual

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.

Implemented in blub::procedural::voxel::simple::container::inMemory< configType >, and blub::procedural::voxel::simple::container::inMemory< voxelType >.

template<class configType>
t_utilsTile blub::procedural::voxel::simple::container::base< configType >::getTileHolderByVoxelPosition ( const blub::vector3int32 pos) const
inline

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

Parameters
posAn absolute voxel-coordinate.
Returns
Always returns a valid value. If nothing found state in utils::tile gets set to empty.
template<class configType>
t_voxel blub::procedural::voxel::simple::container::base< configType >::getVoxel ( const vector3int32 voxelPos) const
inline

getVoxel returns an voxel. Read-lock the class before call.

Parameters
voxelPosAn absolute voxel-coordinate.
Returns
always returns a valid value.
template<class configType>
void blub::procedural::voxel::simple::container::base< configType >::setTile ( const t_tileId id,
const t_utilsTile toSet 
)
inline

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.

Parameters
changeMust not be nullptr
transThe transform of the edit. setTile sets a tile. You may wanna call this method on loading or synchronisation. Method is threadsafe. Write-lock class before.
idIdentifier. Contains voxel from id*blub::procedural::voxel::tile::container::voxelLength to (id+1)*blub::procedural::voxel::tile::container::voxelLength-1
toSetTile to set.
See also
setTileMaster
template<class configType>
virtual void blub::procedural::voxel::simple::container::base< configType >::setTileMaster ( const t_tileId id,
const t_utilsTile toSet 
)
protectedpure virtual

gets called by setTile. Call only by one thread at a time. Write-lock class before.

See also
setTile
template<class configType>
virtual void blub::procedural::voxel::simple::container::base< configType >::setTileToEmtpyMaster ( const t_tileId id)
protectedpure virtual

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

Parameters
idTileId

Implemented in blub::procedural::voxel::simple::container::inMemory< configType >, and blub::procedural::voxel::simple::container::inMemory< voxelType >.

template<class configType>
virtual void blub::procedural::voxel::simple::container::base< configType >::setTileToFullMaster ( const t_tileId id)
protectedpure virtual

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

Parameters
idTileId

Implemented in blub::procedural::voxel::simple::container::inMemory< configType >, and blub::procedural::voxel::simple::container::inMemory< voxelType >.

template<class configType>
bool blub::procedural::voxel::simple::container::base< configType >::tryLockForEditMaster ( )
inlineoverrideprotectedvirtual

tryLockForEditMaster tries to lock for write. Call by master dispatcher.

Returns
True on successfully-lock.

Reimplemented from blub::procedural::voxel::simple::base< configType::t_container::t_tile >.


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