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

The accessor class accesses and caches voxels for the surface-calculation. It caches voxel optimized for the marching cubes algorithm. If lod is larger 0 it addionally caches voxel for the transvoxel aalgorithm. More...

#include <accessor.hpp>

Inheritance diagram for blub::procedural::voxel::simple::accessor< configType >:
blub::procedural::voxel::simple::base< configType::t_accessor::t_tile > blub::noncopyable

Public Types

typedef configType t_config
 
typedef
t_config::t_accessor::t_tile 
t_tile
 
typedef sharedPointer< t_tile > t_tilePtr
 
typedef base< t_tile > t_base
 
typedef t_config::t_data t_voxel
 
typedef t_base::t_tileId t_tileId
 
typedef hashMap< vector3int32,
t_tilePtr
t_tiles
 
typedef
t_config::t_container::t_tile 
t_tileContainer
 
typedef sharedPointer
< t_tileContainer > 
t_tileContainerPtr
 
typedef hashList< vector3int32t_tileIdList
 
typedef container::utils::tileState t_tileState
 
typedef container::utils::tile
< t_tileContainer > 
t_tileHolder
 
typedef hashMap< t_tileId,
t_tileHolder
t_tileHolderMap
 
typedef
t_config::t_container::t_simple 
t_simpleContainerVoxel
 
- Public Types inherited from blub::procedural::voxel::simple::base< configType::t_accessor::t_tile >
typedef
configType::t_accessor::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

 accessor (async::dispatcher &worker, t_simpleContainerVoxel &voxels, const int32 &lod)
 accessor constructor More...
 
 ~accessor ()
 ~accessor destructor
 
t_simpleContainerVoxel & getVoxelContainer () const
 getVoxelContainer returns the voxel container, set in the constructor. More...
 
t_tilePtr getTile (const t_tileId &id) const
 getTile returns an accessor tile. Read-lock class before. More...
 
- Public Member Functions inherited from blub::procedural::voxel::simple::base< configType::t_accessor::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

void tilesGotChanged ()
 tilesGotChanged gets called after in the voxel container m_voxels, set in the constructor, the voxels changed. Which leads to a recalculation of the cache.
 
void tilesGotChangedMaster ()
 tilesGotChangedMaster must not get called paralell. More...
 
void calculateAccessorTS (const t_tileId &id, t_tilePtr workTile)
 calculateAccessorTS accesses the container and pulls out all voxel needed for surface calculation (marching-cubes/transvoxel). More...
 
void afterCalculateAccessorMaster (const t_tileId &id, t_tilePtr workTile, const bool &didValuesChanged)
 afterCalculateAccessorMaster gets called after a worker-thread finished calculation of a part. More...
 
void calculateAffectedAccessorTilesByContainerTile (const t_tileId &conterainerId, const t_tileHolder &holder, t_tileIdList &resultingSurfaceTiles)
 When a tile in container gets changed it affects (because of normal-correction and lod) 3^3 accessor-tiles. More...
 
t_tilePtr createTile () const override
 createTile creates an empty tile. More...
 
t_voxel getVoxelData (const vector3int32 &voxelPosAbs, t_tileHolderMap &lastUsedTiles)
 getVoxelData returns a voxel from a cahned container-tile or looks up the tile and returns it. More...
 
- Protected Member Functions inherited from blub::procedural::voxel::simple::base< configType::t_accessor::t_tile >
void addToChangeList (const t_tileId &id, t_tilePtr toAdd)
 addToChangeList adds a tile to the change-list. More...
 
virtual bool tryLockForEditMaster ()
 tryLockForEditMaster tries to lock for write. Call by master dispatcher. More...
 
virtual void lockForEditMaster ()
 lockForEditMaster locks for write, or waits until possible. Call by master dispatcher.
 
virtual void unlockForEditMaster ()
 unlockForEditMaster unlocks write. Call by master dispatcher.
 

Protected Attributes

t_simpleContainerVoxel & m_voxels
 
const int32 m_lod
 
const int32 m_voxelSkip
 
int32 m_numTilesInWork
 
t_tiles m_tiles
 
boost::signals2::scoped_connection m_connTilesGotChanged
 
- Protected Attributes inherited from blub::procedural::voxel::simple::base< configType::t_accessor::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::accessor< configType >

The accessor class accesses and caches voxels for the surface-calculation. It caches voxel optimized for the marching cubes algorithm. If lod is larger 0 it addionally caches voxel for the transvoxel aalgorithm.

Constructor & Destructor Documentation

template<class configType >
blub::procedural::voxel::simple::accessor< configType >::accessor ( async::dispatcher worker,
t_simpleContainerVoxel &  voxels,
const int32 &  lod 
)
inline

accessor constructor

Parameters
workerMay gets run by multiple threads.
voxelsThe container to read the voxels from. The Accessor will connect the signal container::base::signalEditDone() to this class, so it keeps up to date.
lodIndicates the level of detail. Use 0 zero for the most detailed one, use 1 for half detail and so on.

Member Function Documentation

template<class configType >
void blub::procedural::voxel::simple::accessor< configType >::afterCalculateAccessorMaster ( const t_tileId id,
t_tilePtr  workTile,
const bool &  didValuesChanged 
)
inlineprotected

afterCalculateAccessorMaster gets called after a worker-thread finished calculation of a part.

Parameters
idTileId
workTileThe resulting accessor-tile.
didValuesChangedTells if anything changed.
template<class configType >
void blub::procedural::voxel::simple::accessor< configType >::calculateAccessorTS ( const t_tileId id,
t_tilePtr  workTile 
)
inlineprotected

calculateAccessorTS accesses the container and pulls out all voxel needed for surface calculation (marching-cubes/transvoxel).

Parameters
idAccessor-TileId
workTileThe accessor-tile to fill with.
template<class configType >
void blub::procedural::voxel::simple::accessor< configType >::calculateAffectedAccessorTilesByContainerTile ( const t_tileId conterainerId,
const t_tileHolder holder,
t_tileIdList resultingSurfaceTiles 
)
inlineprotected

When a tile in container gets changed it affects (because of normal-correction and lod) 3^3 accessor-tiles.

Parameters
conterainerIdContainer-Tile-Id
holderContainer-Data
resultingSurfaceTilesResulting, up to 27, to recalculate tiles. Depending on how the change-axisAligendBox in the container-tile looks like.
template<class configType >
t_tilePtr blub::procedural::voxel::simple::accessor< configType >::createTile ( ) const
inlineoverrideprotectedvirtual

createTile creates an empty tile.

Returns

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

template<class configType >
t_tilePtr blub::procedural::voxel::simple::accessor< configType >::getTile ( const t_tileId id) const
inline

getTile returns an accessor tile. Read-lock class before.

Parameters
idTileId
Returns
Returns nullptr if no tile is available.
template<class configType >
t_simpleContainerVoxel& blub::procedural::voxel::simple::accessor< configType >::getVoxelContainer ( ) const
inline

getVoxelContainer returns the voxel container, set in the constructor.

Returns
Returns never nullptr
template<class configType >
t_voxel blub::procedural::voxel::simple::accessor< configType >::getVoxelData ( const vector3int32 voxelPosAbs,
t_tileHolderMap lastUsedTiles 
)
inlineprotected

getVoxelData returns a voxel from a cahned container-tile or looks up the tile and returns it.

Parameters
voxelPosAbsAbsolut voxel position.
lastUsedTilesLast used container-tile.
Returns
Always a valid voxel. If not found a default-constructed voxel.
template<class configType >
void blub::procedural::voxel::simple::accessor< configType >::tilesGotChangedMaster ( )
inlineprotected

tilesGotChangedMaster must not get called paralell.

See also
tilesGotChanged()

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