1 #ifndef VOXEL_SIMPLE_CONTAINER_INMEMORY_HPP 
    2 #define VOXEL_SIMPLE_CONTAINER_INMEMORY_HPP 
    5 #include "blub/math/vector3int32map.hpp" 
    6 #include "blub/procedural/voxel/simple/container/base.hpp" 
    7 #include "blub/serialization/access.hpp" 
    8 #include "blub/serialization/nameValuePair.hpp" 
    9 #include "blub/serialization/saveLoad.hpp" 
   31 template <
class configType>
 
   32 class inMemory : 
public base<configType>
 
   35     typedef base<configType> t_base;
 
   37     typedef vector3int32map<typename t_base::t_utilsTile> t_tilesMap;
 
   47         blub::BOUT(
"inMemory::inMemory()");
 
   57         blub::BOUT(
"inMemory::~inMemory()");
 
   70         if (bounds.isInside(
id))
 
   72             return m_tiles.getValue(
id);
 
   74         typename t_base::t_utilsTile result;
 
   93         m_tiles.resize(bounds);
 
  102         return m_tiles.getBounds();
 
  117         m_tiles.setValue(
id, toSet);
 
  127 #ifdef BLUB_LOG_VOXEL 
  128         blub::BOUT(
"inMemory::setTileMaster id:" + blub::string::number(
id));
 
  132         bool alreadyEmpty(holder.state == utils::tileState::empty);
 
  134         if (toSet.state == utils::tileState::empty && alreadyEmpty)
 
  140             if (toSet.state == utils::tileState::full &&
 
  141                 holder.state == utils::tileState::full) 
 
  148         if (toSet.state == utils::tileState::partitial)
 
  150             BASSERT(!toSet.data->isEmpty());
 
  151             BASSERT(!toSet.data->isFull());
 
  153             if (!toSet.data->getEditedVoxelBoundingBox().isValid()) 
 
  155                 toSet.data->endEdit();
 
  159         t_base::addToChangeList(
id, toSet);
 
  164 #ifdef BLUB_LOG_VOXEL 
  165         blub::BOUT(
"inMemory::setTileToFullMaster id:" + blub::string::number(
id));
 
  167         const typename t_base::t_utilsTile holder(utils::tileState::full);
 
  172 #ifdef BLUB_LOG_VOXEL 
  173         blub::BOUT(
"inMemory::setTileToEmtpyMaster id:" + blub::string::number(
id));
 
  175         const typename t_base::t_utilsTile holder(utils::tileState::empty);
 
  180     BLUB_SERIALIZATION_ACCESS
 
  182     template <
class formatType>
 
  183     void save(formatType & readWrite, 
const uint32& version)
 const 
  188         readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(bounds);
 
  190         for (int32 indX = bounds.getMinimum().x; indX < bounds.getMaximum().x; ++indX)
 
  192             for (int32 indY = bounds.getMinimum().y; indY < bounds.getMaximum().y; ++indY)
 
  194                 for (int32 indZ = bounds.getMinimum().z; indZ < bounds.getMaximum().z; ++indZ)
 
  197                     const typename t_base::t_utilsTile holder(
getTileHolder(
id));
 
  199                     readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(
id);
 
  200                     readWrite & serialization::nameValuePair::create(
"state", holder.state);
 
  202                     if (holder.state != utils::tileState::partitial)
 
  207                     readWrite & serialization::nameValuePair::create(
"tile", *holder.data.data());
 
  212     template <
class formatType>
 
  213     void load(formatType & readWrite, 
const uint32& version)
 
  219         axisAlignedBoxInt32 bounds;
 
  220         readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(bounds);
 
  224         for (int32 indX = bounds.getMinimum().x; indX < bounds.getMaximum().x; ++indX)
 
  226             for (int32 indY = bounds.getMinimum().y; indY < bounds.getMaximum().y; ++indY)
 
  228                 for (int32 indZ = bounds.getMinimum().z; indZ < bounds.getMaximum().z; ++indZ)
 
  231                     readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(
id);
 
  232                     BASSERT(
id == vector3int32(indX, indY, indZ));
 
  234                     typename t_base::t_utilsTile holder;
 
  235                     readWrite & serialization::nameValuePair::create(
"state", holder.state);
 
  237                     if (holder.state == utils::tileState::partitial)
 
  240                         readWrite & serialization::nameValuePair::create(
"tile", *holder.data.data());
 
  250     template <
class formatType>
 
  251     void serialize(formatType & readWrite, 
const uint32& version)
 
  253         using namespace serialization;
 
  255         saveLoad(readWrite, *
this, version);
 
  271 #endif // VOXEL_SIMPLE_CONTAINER_INMEMORY_HPP 
void setTileBounds(const axisAlignedBoxInt32 &bounds)
setTileBounds sets the size for the map. Call for optimization, if you know the tile-dimensions befor...
Definition: inMemory.hpp:91
const axisAlignedBoxInt32 & getTileBounds() const 
getTileBounds returns the tile bounds. 
Definition: inMemory.hpp:100
virtual t_tilePtr createTile() const
createTile creates a new Tile. Uses callback set by setCreateTileCallback() 
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 meth...
Definition: base.hpp:87
void setTileToEmtpyMaster(const vector3int32 &id) override
setTileToFullMaster sets a tiles voxel to minimum - for memory optimizations. Method gets called by a...
Definition: inMemory.hpp:170
Definition: axisAlignedBoxInt32.hpp:12
Definition: dispatcher.hpp:29
~inMemory()
~inMemory descructor 
Definition: inMemory.hpp:54
const t_tilesMap & getTilesMap() const 
getTilesMap returns all tiles. 
Definition: inMemory.hpp:82
void lockForEdit()
lockForEdit locks the class for editing/writing it. Call unlockForEdit() after work done...
t_base::t_utilsTile getTileHolder(const blub::vector3int32 &id) const override
getTileHolder returns a utils::tileHolder setted by setTile() or by editVoxel(). Read-lock class befo...
Definition: inMemory.hpp:67
void setTileToFullMaster(const vector3int32 &id) override
setTileToFullMaster sets a tiles voxel to maximum - for memory optimizations. Method gets called by a...
Definition: inMemory.hpp:162
void unlockForEdit()
unlockForEdit unlocks edit/write-lock and calls signalEditDone() . Method executes unlock by the disp...
void setTileMaster(const blub::vector3int32 &id, const typename t_base::t_utilsTile &toSet) override
setTileMaster sets a tile to an id. Call by one thread at a time. 
Definition: inMemory.hpp:125
Definition: deadlineTimer.hpp:10
inMemory(blub::async::dispatcher &worker)
inMemory constructor 
Definition: inMemory.hpp:43
virtual void setTileToContainerMaster(const typename t_base::t_tileId id, const typename t_base::t_utilsTile &oldOne, const typename t_base::t_utilsTile &toSet)
setTileToContainerMaster replaces a tile. Call method by one thread at a time. Write-lock class befor...
Definition: inMemory.hpp:112