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::base< tileType > Class Template Reference

The base class gets derived by every class in the namespace simple::*. It represends one level of detail. If you dont need a terrain but a voxel-surface use a class in this namespace. More...

#include <base.hpp>

Inheritance diagram for blub::procedural::voxel::simple::base< tileType >:
blub::noncopyable

Public Types

typedef tileType 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...
 
 ~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 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.
 
virtual t_tilePtr createTile () const
 createTile creates a new Tile. Uses callback set by setCreateTileCallback() More...
 

Protected Attributes

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 tileType>
class blub::procedural::voxel::simple::base< tileType >

The base class gets derived by every class in the namespace simple::*. It represends one level of detail. If you dont need a terrain but a voxel-surface use a class in this namespace.

Member Typedef Documentation

template<class tileType>
typedef vector3int32 blub::procedural::voxel::simple::base< tileType >::t_tileId

id Identifier. Contains voxel from id*blub::procedural::voxel::tile::container::voxelLength to (id+1)*blub::procedural::voxel::tile::container::voxelLength-1

Constructor & Destructor Documentation

template<class tileType >
blub::procedural::voxel::simple::base< tileType >::base ( blub::async::dispatcher worker)

base constructor

Parameters
workermay gets run by multiple threads.

Member Function Documentation

template<class tileType >
void blub::procedural::voxel::simple::base< tileType >::addToChangeList ( const t_tileId id,
t_tilePtr  toAdd 
)
protected

addToChangeList adds a tile to the change-list.

Parameters
id
toAdd
See also
getTilesThatGotEdited()
template<class tileType >
base< tileType >::t_tilePtr blub::procedural::voxel::simple::base< tileType >::createTile ( ) const
protectedvirtual

createTile creates a new Tile. Uses callback set by setCreateTileCallback()

Returns

Reimplemented in blub::procedural::voxel::simple::accessor< configType >.

template<class tileType >
blub::async::strand & blub::procedural::voxel::simple::base< tileType >::getMaster ( )

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.

Returns
template<class tileType >
const base< tileType >::t_tilesGotChangedMap & blub::procedural::voxel::simple::base< tileType >::getTilesThatGotEdited ( ) const

getTilesThatGotEdited returns a list of tiles which changed since the last call lockForEdit() / lockForEditMaster()

Returns
template<class tileType >
void blub::procedural::voxel::simple::base< tileType >::lockForEdit ( )

lockForEdit locks the class for editing/writing it. Call unlockForEdit() after work done. Method executes locks by the dispatcher master.

See also
getMaster()
template<class tileType >
void blub::procedural::voxel::simple::base< tileType >::setCreateTileCallback ( const t_createTileCallback &  callback)

setCreateTileCallback sets a callback for creating tiles. Use this method if you want to create custom tiles.

Parameters
callbackMust not be empty.
template<class tileType >
base< tileType >::t_sigEditDone * blub::procedural::voxel::simple::base< tileType >::signalEditDone ( )

signalEditDone gets called after unlockForEdit() got called.

Returns
template<class tileType >
bool blub::procedural::voxel::simple::base< tileType >::tryLockForEditMaster ( )
protectedvirtual

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

Returns
True on successfully-lock.

Reimplemented in blub::procedural::voxel::simple::container::base< configType >, and blub::procedural::voxel::simple::container::base< voxelType >.

template<class tileType >
void blub::procedural::voxel::simple::base< tileType >::unlockForEdit ( )

unlockForEdit unlocks edit/write-lock and calls signalEditDone() . Method executes unlock by the dispatcher master.

See also
getMaster()

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