1 #ifndef PROCEDURAL_VOXEL_SIMPLE_SURFACE_HPP
2 #define PROCEDURAL_VOXEL_SIMPLE_SURFACE_HPP
5 #include "blub/core/globals.hpp"
6 #include "blub/core/hashList.hpp"
7 #include "blub/core/hashMap.hpp"
8 #include "blub/core/signal.hpp"
9 #include "blub/math/vector3int.hpp"
10 #include "blub/procedural/log/global.hpp"
11 #include "blub/procedural/voxel/simple/accessor.hpp"
13 #include <boost/signals2/connection.hpp>
29 template <
class configType>
30 class surface :
public base<typename configType::t_surface::t_tile>
34 typedef typename t_config::t_surface::t_tile t_tile;
35 typedef sharedPointer<t_tile> t_tilePtr;
36 typedef base<t_tile> t_base;
40 typedef hashMap<t_tileId, t_tilePtr> t_tilesMap;
41 typedef hashList<vector3int32> t_tileIdList;
43 typedef typename t_config::t_accessor::t_tile t_tileAccessor;
44 typedef sharedPointer<t_tileAccessor> t_tileAccessorPtr;
55 t_voxelAccessor& voxels,
80 return m_tiles.size();
88 return math::pow(2., m_lod);
98 typename t_tilesMap::const_iterator it(m_tiles.find(
id));
99 if (it == m_tiles.cend())
114 t_tilePtr workTile(
getTile(
id));
115 if (workTile.isNull())
141 #ifdef BLUB_LOG_VOXEL
142 BLUB_PROCEDURAL_LOG_OUT() <<
"surface editDoneMaster change.size():" << change.size();
146 BLUB_PROCEDURAL_LOG_WARNING() <<
"change.empty()";
152 BASSERT(m_numTilesInWork == 0);
153 m_numTilesInWork = change.size();
155 for (
auto work : change)
157 if (work.second.isNull())
163 BASSERT(!work.second->isEmpty());
164 BASSERT(!work.second->isFull());
166 t_tilePtr workTile(
getTile(work.first));
182 if (workTile.isNull())
186 workTile->calculateSurface(work,
191 if (workTile->getIndices().empty())
193 #ifdef BLUB_LOG_VOXEL
194 BLUB_PROCEDURAL_LOG_WARNING() <<
"workTile->getIndices().empty() id:" <<
id <<
" m_lod:" << m_lod <<
" work->getNumVoxelLargerZero():" << work->getNumVoxelLargerZero();
211 #ifdef BLUB_LOG_VOXEL
212 BLUB_LOG_OUT() <<
"afterCalculateSurfaceMaster id:" << id;
215 typename t_tilesMap::const_iterator it(m_tiles.find(
id));
218 if (!workTile.isNull())
220 numIndices = workTile->getIndices().size();
226 if (it != m_tiles.cend())
234 BASSERT(!workTile.isNull());
235 if (it == m_tiles.cend())
237 m_tiles.insert(
id, workTile);
243 BASSERT(m_numTilesInWork >= 0);
244 if (m_numTilesInWork == 0)
255 t_voxelAccessor &m_voxels;
257 int32 m_numTilesInWork;
259 boost::signals2::scoped_connection m_connTilesGotChanged;
270 #endif // PROCEDURAL_VOXEL_SIMPLE_SURFACE_HPP
void calculateSurfaceTS(const t_tileId id, t_tileAccessorPtr work, t_tilePtr workTile)
calculateSurfaceTS gets called by editDoneMaster(), by any worker-thread. Calls afterCalculateSurface...
Definition: surface.hpp:180
virtual void lockForEditMaster()
lockForEditMaster locks for write, or waits until possible. Call by master dispatcher.
Definition: base.hpp:228
Definition: customVertexInformation.cpp:193
vector3int32 t_tileId
Definition: base.hpp:44
void editDoneMaster()
editDoneMaster same like editDone() but on master-thread. Write locks class, dispatches surface gener...
Definition: surface.hpp:138
virtual t_tilePtr createTile() const
createTile creates a new Tile. Uses callback set by setCreateTileCallback()
Definition: base.hpp:249
virtual void unlockForEditMaster()
unlockForEditMaster unlocks write. Call by master dispatcher.
Definition: base.hpp:236
const t_tilesGotChangedMap & getTilesThatGotEdited() const
getTilesThatGotEdited returns a list of tiles which changed since the last call lockForEdit() / lockF...
Definition: base.hpp:198
void addToChangeList(const t_tileId &id, t_tilePtr toAdd)
addToChangeList adds a tile to the change-list.
Definition: base.hpp:210
t_tilePtr getOrCreateTile(const blub::vector3int32 &id) const
getOrCreateTile returns same like getTile() except that when not found instances a new tile...
Definition: surface.hpp:112
void unlockRead()
unlockRead unlocks the class after reading.
Definition: base.hpp:192
int32 getTileCount() const
getTileCount returns the tile count calculated by this class. Read-lock class before calling...
Definition: surface.hpp:78
surface(blub::async::dispatcher &worker, t_voxelAccessor &voxels, const int32 &lod)
surface constructor.
Definition: surface.hpp:54
Definition: dispatcher.hpp:29
void afterCalculateSurfaceMaster(const t_tileId &id, t_tilePtr workTile)
afterCalculateSurfaceMaster gets called by calculateSurfaceTS() on master-thread. ...
Definition: surface.hpp:209
real getVoxelSize() const
getVoxelSize returns the voxel-size.
Definition: surface.hpp:86
void lockForRead()
lockForRead locks the class for reading.
Definition: base.hpp:186
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
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
The accessor class contains a custom amount of level of details of type simple::accessor.
Definition: predecl.hpp:60
t_tilePtr getTile(const blub::vector3int32 &id) const
getTile returns a surface-tile. Lock-read class before.
Definition: surface.hpp:96
void editDone()
editDone gets called when data in accessor changed.
Definition: surface.hpp:126
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
~surface()
~surface destructor.
Definition: surface.hpp:69