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>
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 |
![]() | |
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_tilesGotChangedMap & | getTilesThatGotEdited () const |
![]() | |
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_tilesGotChangedMap & | getTilesThatGotEdited () 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::strand & | 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. More... | |
t_sigEditDone * | signalEditDone () |
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< editTodo > | t_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... | |
![]() | |
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 |
![]() | |
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::dispatcher & | m_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 |
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.
|
inline |
base constructor.
worker | may gets run by several threads. |
|
inlinestaticprotected |
calculateAffectetedTilesByAabb caluclates a list of affected tiles by an axisAlignedBox. Used to determine which tiles to recalculate for an edit.
voxelAabb | axisAlignedBox |
startResult | Resulting minId. |
endResult | Resulting maxId. |
|
inlinestatic |
calculateVoxelPosInTile converts an absolute voxel-position to an relative container-confirm position.
voxelPos | An absolute voxel-postion. |
|
inlinestatic |
calculateVoxelPosToTileId converts an absolute voxel-position to an relative container-id position.
voxelPos | An absolute voxel-postion. |
|
inlinestaticprotected |
createTileFull creates a tile in which all voxel are maximum or minimum.
full | If false all voxel get initialised with default value. |
|
inlineprotected |
doNextEditMaster finds out which tiles the edit affects and dispaches the change to the worker-threads.
alreadyLocked | optimization parameter, if class is already write locked. (indirect recursive calls) |
|
inlineprotected |
editMaster saves the edit in a qeue and starts to handle it.
change | Must not be nullptr. |
trans | The 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.
change | Must not be nullptr |
trans | The transform of the edit. |
|
inlineprotected |
editVoxelDoneMaster gets called after edit got applied on the tile. Call method only by one thread at a time.
tileHolder_ | Affected tile. |
id | Tile identifier. |
|
inlineprotected |
editVoxelWorker affects with change holder. Method gets called paralell by various threads. Method only affects the delivered holder.
change | The edit. |
holder | The tile which gets affected. |
id | TileId. |
trans | Transform. |
|
inlineprotected |
getOrCreateTile looks up if tile already exists. If not creates one.
id | TileId |
|
pure virtual |
getTileHolder returns a utils::tileHolder setted by setTile() or by editVoxel(). Read-lock class before call. Read-lock the class before.
id | Identifier. Contains voxel from id*blub::procedural::voxel::tile::container::voxelLength to (id+1)*blub::procedural::voxel::tile::container::voxelLength-1 |
Implemented in blub::procedural::voxel::simple::container::inMemory< configType >, and blub::procedural::voxel::simple::container::inMemory< voxelType >.
|
inline |
getTileHolderByVoxelPosition returns a utils::tileHolder setted by setTile() or by editVoxel(). Read-lock class before call.
pos | An absolute voxel-coordinate. |
|
inline |
getVoxel returns an voxel. Read-lock the class before call.
voxelPos | An absolute voxel-coordinate. |
|
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.
change | Must not be nullptr |
trans | The 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. |
id | Identifier. Contains voxel from id*blub::procedural::voxel::tile::container::voxelLength to (id+1)*blub::procedural::voxel::tile::container::voxelLength-1 |
toSet | Tile to set. |
|
protectedpure virtual |
gets called by setTile. Call only by one thread at a time. Write-lock class before.
|
protectedpure virtual |
setTileToFullMaster sets a tiles voxel to minimum - for memory optimizations. Method gets called by a single thread at a time.
id | TileId |
Implemented in blub::procedural::voxel::simple::container::inMemory< configType >, and blub::procedural::voxel::simple::container::inMemory< voxelType >.
|
protectedpure virtual |
setTileToFullMaster sets a tiles voxel to maximum - for memory optimizations. Method gets called by a single thread at a time.
id | TileId |
Implemented in blub::procedural::voxel::simple::container::inMemory< configType >, and blub::procedural::voxel::simple::container::inMemory< voxelType >.
|
inlineoverrideprotectedvirtual |
tryLockForEditMaster tries to lock for write. Call by master dispatcher.
Reimplemented from blub::procedural::voxel::simple::base< configType::t_container::t_tile >.