1 #ifndef NETWORK_SYNC_VOXEL_ACCESSOR_TERRAIN_SENDER_HPP
2 #define NETWORK_SYNC_VOXEL_ACCESSOR_TERRAIN_SENDER_HPP
4 #include "blub/async/dispatcher.hpp"
5 #include "blub/async/predecl.hpp"
6 #include "blub/core/byteArray.hpp"
7 #include "blub/core/globals.hpp"
8 #include "blub/core/signal.hpp"
9 #include "blub/core/vector.hpp"
10 #include "blub/log/global.hpp"
11 #include "blub/math/axisAlignedBox.hpp"
12 #include "blub/procedural/predecl.hpp"
13 #include "blub/procedural/voxel/terrain/accessor.hpp"
14 #include "blub/procedural/voxel/tile/container.hpp"
15 #include "blub/sync/voxel/accessor/multipleTiles/base.hpp"
16 #include "blub/sync/voxel/accessor/multipleTiles/sender.hpp"
31 template <
class voxelType,
class identifierType>
36 typedef identifierType t_identifier;
50 const t_syncRadiusList& syncRadien,
51 t_terrainAccessor* tiles)
52 : m_syncRadien(syncRadien)
54 BASSERT(tiles !=
nullptr);
55 BASSERT(tiles->
getNumLod() <= (int32)syncRadien.size());
59 for (int32 indLod = 0; indLod < tiles->
getNumLod(); ++indLod)
61 const auto callback(boost::bind(&sender::isInRange,
this, _1, _2, indLod));
63 t_simpleAccessor* toWork(tiles->
getLod(indLod));
64 t_multipleTilesPtr lod(
new t_multipleTiles(worker, voxelSize, callback, toWork));
66 m_multipleTiles.push_back(lod);
68 lod->signalSendTileData()->connect(boost::bind(&sender::lodWantsToSendTileData,
this, _1, _2, indLod));
73 for (t_multipleTilesPtr toDelete : m_multipleTiles)
77 m_multipleTiles.clear();
80 t_multipleTilesPtr getLodSync(
const uint16& lod)
const
82 return m_multipleTiles.at(lod);
86 void addSyncReceiver(t_receiverIdentifierPtr
receiver,
const vector3& pos)
88 for (t_multipleTilesPtr work : m_multipleTiles)
90 work->addSyncReceiver(receiver, pos);
93 void updateSyncReceiver(t_receiverIdentifierPtr receiver,
const vector3& pos)
95 for (t_multipleTilesPtr work : m_multipleTiles)
97 work->updateSyncReceiver(receiver, pos);
100 void removeSyncReceiver(t_receiverIdentifierPtr receiver)
102 for (t_multipleTilesPtr work : m_multipleTiles)
104 work->removeSyncReceiver(receiver);
110 t_sigSendTileData* signalSendTileData()
112 return &m_sigSendTileData;
116 void lodWantsToSendTileData(t_receiverIdentifierPtr rec, t_tileDataPtr
data,
const uint32 &lodInd)
118 std::ostringstream result;
123 format << *data.get();
125 t_tileDataPtr dataWithLodInformation(
new byteArray(result.str().c_str(), result.str().size()));
127 m_sigSendTileData(rec, dataWithLodInformation);
131 const vector3 sizeLeaf(t_tileContainer::voxelLength);
132 const vector3 sizeLeafDoubled(sizeLeaf*2);
133 const vector3 octreeNodeTwiceMinimum((octreeNode.
getMinimum()/sizeLeafDoubled).getFloor()*sizeLeafDoubled);
134 const axisAlignedBox octreeNodeTwice(octreeNodeTwiceMinimum, octreeNodeTwiceMinimum + octreeNode.
getSize()*2.);
136 const vector3 posLeafCenterScaled((posLeafCenter / sizeLeafDoubled).getFloor());
138 if (lod != 0 &&
false)
140 if (octreeNode.
getSize() == sizeLeaf)
142 const real radius(m_syncRadien[lod-1] / 2.);
151 const real radius(m_syncRadien[lod]);
152 blub::sphere coll(posLeafCenterScaled * sizeLeafDoubled + sizeLeaf, radius);
153 const bool result(coll.
intersects(octreeNodeTwice));
159 t_syncRadiusList m_syncRadien;
160 t_multipleTilesList m_multipleTiles;
162 t_sigSendTileData m_sigSendTileData;
174 #endif // NETWORK_SYNC_VOXEL_ACCESSOR_TERRAIN_SENDER_HPP
The base class gets derived by every class in the namespace simple::*. It represends one level of det...
Definition: predecl.hpp:30
Definition: sender.hpp:40
t_lod getLod(const uint16 &lod) const
getLod returns a level of detail.
Definition: base.hpp:94
vector3 getSize(void) const
Gets the size of the box.
Definition: axisAlignedBox.cpp:57
bool intersects(const sphere &s) const
Definition: sphere.cpp:9
The container class contains an array of voxel. The amount of voxel per tile is voxelLength^3. The class counts how many voxel are max and how many are min. if all voxel are min or max the class simple::container::base doesnt save them. Additionally it saves an axisAlignedBox which describes the bounds of the voxel that changed.
Definition: predecl.hpp:19
Definition: portable_binary_oarchive.hpp:63
Definition: sharedPointer.hpp:12
Definition: receiver.hpp:27
Definition: sender.hpp:32
Definition: dispatcher.hpp:29
Definition: vector3.hpp:26
Definition: axisAlignedBox.hpp:20
const vector3 & getMinimum(void) const
Definition: axisAlignedBox.hpp:126
Definition: byteArray.hpp:17
int32 getNumLod() const
getNumLod returns number of level of details.
Definition: base.hpp:107
Definition: deadlineTimer.hpp:10
The accessor class contains a custom amount of level of details of type simple::accessor.
Definition: predecl.hpp:60
Definition: customVertexInformation.cpp:177
Definition: sphere.hpp:10