1 #ifndef PROCEDURAL_VOXEL_SIMPLE_BASE_HPP
2 #define PROCEDURAL_VOXEL_SIMPLE_BASE_HPP
4 #include "blub/async/mutexReadWrite.hpp"
5 #include "blub/async/predecl.hpp"
6 #include "blub/core/bind.hpp"
7 #include "blub/core/globals.hpp"
8 #include "blub/core/hashMap.hpp"
9 #include "blub/core/signal.hpp"
10 #include "blub/async/dispatcher.hpp"
11 #include "blub/async/strand.hpp"
12 #include "blub/math/vector3int.hpp"
13 #include "blub/procedural/log/global.hpp"
14 #include "blub/procedural/predecl.hpp"
34 template <
class tileType>
35 class base :
public noncopyable
38 typedef tileType t_tile;
39 typedef sharedPointer<t_tile> t_tilePtr;
41 typedef base<t_tile> t_thisClass;
47 typedef std::function<t_tilePtr ()> t_createTileCallback;
150 t_tilesGotChangedMap m_tilesThatGotEdited;
152 t_createTileCallback m_createTileCallback;
156 t_sigEditDone m_sigEditDone;
159 template <
class tileType>
168 template <
class tileType>
173 template <
class tileType>
179 template <
class tileType>
185 template <
class tileType>
188 m_classLocker.lockForRead();
191 template <
class tileType>
194 m_classLocker.unlockRead();
197 template <
class tileType>
200 return m_tilesThatGotEdited;
203 template <
class tileType>
206 m_createTileCallback = callback;
209 template <
class tileType>
212 BASSERT(!m_classLocker.tryLockForWrite());
213 m_tilesThatGotEdited.insert(
id, toAdd);
216 template <
class tileType>
219 const bool result(m_classLocker.tryLockForWrite());
222 m_tilesThatGotEdited.clear();
227 template <
class tileType>
230 m_classLocker.lockForWrite();
232 m_tilesThatGotEdited.clear();
235 template <
class tileType>
238 m_classLocker.unlock();
239 #ifdef BLUB_LOG_VOXEL
240 BLUB_PROCEDURAL_LOG_OUT() <<
"simple master unlock m_tilesThatGotEdited.size():" << m_tilesThatGotEdited.size();
242 if (!m_tilesThatGotEdited.empty())
248 template <
class tileType>
251 return m_createTileCallback();
254 template <
class tileType>
260 template <
class tileType>
263 return &m_sigEditDone;
272 #endif // PROCEDURAL_VOXEL_SIMPLE_BASE_HPP
virtual void lockForEditMaster()
lockForEditMaster locks for write, or waits until possible. Call by master dispatcher.
Definition: base.hpp:228
vector3int32 t_tileId
Definition: base.hpp:44
virtual t_tilePtr createTile() const
createTile creates a new Tile. Uses callback set by setCreateTileCallback()
Definition: base.hpp:249
virtual bool tryLockForEditMaster()
tryLockForEditMaster tries to lock for write. Call by master dispatcher.
Definition: base.hpp:217
virtual void unlockForEditMaster()
unlockForEditMaster unlocks write. Call by master dispatcher.
Definition: base.hpp:236
base(blub::async::dispatcher &worker)
base constructor
Definition: base.hpp:160
Definition: strand.hpp:16
const t_tilesGotChangedMap & getTilesThatGotEdited() const
getTilesThatGotEdited returns a list of tiles which changed since the last call lockForEdit() / lockF...
Definition: base.hpp:198
Definition: sharedPointer.hpp:12
void addToChangeList(const t_tileId &id, t_tilePtr toAdd)
addToChangeList adds a tile to the change-list.
Definition: base.hpp:210
void unlockRead()
unlockRead unlocks the class after reading.
Definition: base.hpp:192
blub::async::strand & getMaster()
getMaster returns the master dispatcher. The master synchronises jobs for the worker-thread and write...
Definition: base.hpp:255
Definition: dispatcher.hpp:29
void lockForRead()
lockForRead locks the class for reading.
Definition: base.hpp:186
void lockForEdit()
lockForEdit locks the class for editing/writing it. Call unlockForEdit() after work done...
Definition: base.hpp:174
t_sigEditDone * signalEditDone()
signalEditDone gets called after unlockForEdit() got called.
Definition: base.hpp:261
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...
Definition: base.hpp:148
~base()
~base destructor
Definition: base.hpp:169
void unlockForEdit()
unlockForEdit unlocks edit/write-lock and calls signalEditDone() . Method executes unlock by the disp...
Definition: base.hpp:180
Definition: deadlineTimer.hpp:10
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.
Definition: base.hpp:143
void setCreateTileCallback(const t_createTileCallback &callback)
setCreateTileCallback sets a callback for creating tiles. Use this method if you want to create custo...
Definition: base.hpp:204
Definition: mutexReadWrite.hpp:15