History

Working on factoring out the common metavoxel endpoint/client code.

Andrzej Kapolka committed 12 years ago

Commit 4b2d1221 parent 463ac9c13 files · +453 −38Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 13 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+16−16
@@ -54,7 +54,7 @@ SharedObjectPointer MetavoxelSystem::findFirstRaySpannerIntersection( · 53 unmodified lines
54 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {54 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
55 if (node->getType() == NodeType::MetavoxelServer) {55 if (node->getType() == NodeType::MetavoxelServer) {
56 QMutexLocker locker(&node->getMutex());56 QMutexLocker locker(&node->getMutex());
57 MetavoxelClient* client = static_cast<MetavoxelClient*>(node->getLinkedData());57 MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
58 if (client) {58 if (client) {
59 float clientDistance;59 float clientDistance;
60 SharedObjectPointer clientSpanner = client->getData().findFirstRaySpannerIntersection(60 SharedObjectPointer clientSpanner = client->getData().findFirstRaySpannerIntersection(
@@ -76,7 +76,7 @@ void MetavoxelSystem::applyEdit(const MetavoxelEditMessage& edit, bool reliable) · 15 unmodified lines
76 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {76 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
77 if (node->getType() == NodeType::MetavoxelServer) {77 if (node->getType() == NodeType::MetavoxelServer) {
78 QMutexLocker locker(&node->getMutex());78 QMutexLocker locker(&node->getMutex());
79 MetavoxelClient* client = static_cast<MetavoxelClient*>(node->getLinkedData());79 MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
80 if (client) {80 if (client) {
81 client->applyEdit(edit, reliable);81 client->applyEdit(edit, reliable);
82 }82 }
@@ -92,7 +92,7 @@ void MetavoxelSystem::simulate(float deltaTime) { · 9 unmodified lines
92 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {92 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
93 if (node->getType() == NodeType::MetavoxelServer) {93 if (node->getType() == NodeType::MetavoxelServer) {
94 QMutexLocker locker(&node->getMutex());94 QMutexLocker locker(&node->getMutex());
95 MetavoxelClient* client = static_cast<MetavoxelClient*>(node->getLinkedData());95 MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
96 if (client) {96 if (client) {
97 client->simulate(deltaTime);97 client->simulate(deltaTime);
98 client->guide(_simulateVisitor);98 client->guide(_simulateVisitor);
@@ -153,7 +153,7 @@ void MetavoxelSystem::render() { · 54 unmodified lines
153 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {153 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
154 if (node->getType() == NodeType::MetavoxelServer) {154 if (node->getType() == NodeType::MetavoxelServer) {
155 QMutexLocker locker(&node->getMutex());155 QMutexLocker locker(&node->getMutex());
156 MetavoxelClient* client = static_cast<MetavoxelClient*>(node->getLinkedData());156 MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
157 if (client) {157 if (client) {
158 client->guide(_renderVisitor);158 client->guide(_renderVisitor);
159 }159 }
@@ -164,7 +164,7 @@ void MetavoxelSystem::render() { · 4 unmodified lines
164void MetavoxelSystem::maybeAttachClient(const SharedNodePointer& node) {164void MetavoxelSystem::maybeAttachClient(const SharedNodePointer& node) {
165 if (node->getType() == NodeType::MetavoxelServer) {165 if (node->getType() == NodeType::MetavoxelServer) {
166 QMutexLocker locker(&node->getMutex());166 QMutexLocker locker(&node->getMutex());
167 node->setLinkedData(new MetavoxelClient(NodeList::getInstance()->nodeWithUUID(node->getUUID())));167 node->setLinkedData(new MetavoxelSystemClient(NodeList::getInstance()->nodeWithUUID(node->getUUID())));
168 }168 }
169}169}
170 170
@@ -235,7 +235,7 @@ bool MetavoxelSystem::RenderVisitor::visit(Spanner* spanner, const glm::vec3& cl · 64 unmodified lines
235 return true;235 return true;
236}236}
237 237
238MetavoxelClient::MetavoxelClient(const SharedNodePointer& node) :238MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node) :
239 _node(node),239 _node(node),
240 _sequencer(byteArrayWithPopulatedHeader(PacketTypeMetavoxelData)) {240 _sequencer(byteArrayWithPopulatedHeader(PacketTypeMetavoxelData)) {
241 241
@@ -253,7 +253,7 @@ MetavoxelClient::MetavoxelClient(const SharedNodePointer& node) : · 11 unmodified lines
253 _receiveRecords.append(receiveRecord);253 _receiveRecords.append(receiveRecord);
254}254}
255 255
256MetavoxelClient::~MetavoxelClient() {256MetavoxelSystemClient::~MetavoxelSystemClient() {
257 // close the session257 // close the session
258 Bitstream& out = _sequencer.startPacket();258 Bitstream& out = _sequencer.startPacket();
259 out << QVariant::fromValue(CloseSessionMessage());259 out << QVariant::fromValue(CloseSessionMessage());
@@ -265,12 +265,12 @@ static MetavoxelLOD getLOD() { · 5 unmodified lines
265 return MetavoxelLOD(Application::getInstance()->getCamera()->getPosition(), FIXED_LOD_THRESHOLD);265 return MetavoxelLOD(Application::getInstance()->getCamera()->getPosition(), FIXED_LOD_THRESHOLD);
266}266}
267 267
268void MetavoxelClient::guide(MetavoxelVisitor& visitor) {268void MetavoxelSystemClient::guide(MetavoxelVisitor& visitor) {
269 visitor.setLOD(getLOD());269 visitor.setLOD(getLOD());
270 _data.guide(visitor);270 _data.guide(visitor);
271}271}
272 272
273void MetavoxelClient::applyEdit(const MetavoxelEditMessage& edit, bool reliable) {273void MetavoxelSystemClient::applyEdit(const MetavoxelEditMessage& edit, bool reliable) {
274 if (reliable) {274 if (reliable) {
275 _sequencer.getReliableOutputChannel()->sendMessage(QVariant::fromValue(edit));275 _sequencer.getReliableOutputChannel()->sendMessage(QVariant::fromValue(edit));
276 276
@@ -283,7 +283,7 @@ void MetavoxelClient::applyEdit(const MetavoxelEditMessage& edit, bool reliable) · 6 unmodified lines
283 }283 }
284}284}
285 285
286void MetavoxelClient::simulate(float deltaTime) {286void MetavoxelSystemClient::simulate(float deltaTime) {
287 Bitstream& out = _sequencer.startPacket();287 Bitstream& out = _sequencer.startPacket();
288 288
289 ClientStateMessage state = { getLOD() };289 ClientStateMessage state = { getLOD() };
@@ -295,19 +295,19 @@ void MetavoxelClient::simulate(float deltaTime) { · 5 unmodified lines
295 _sendRecords.append(record);295 _sendRecords.append(record);
296}296}
297 297
298int MetavoxelClient::parseData(const QByteArray& packet) {298int MetavoxelSystemClient::parseData(const QByteArray& packet) {
299 // process through sequencer299 // process through sequencer
300 QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet));300 QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet));
301 Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::METAVOXELS).updateValue(packet.size());301 Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::METAVOXELS).updateValue(packet.size());
302 return packet.size();302 return packet.size();
303}303}
304 304
305void MetavoxelClient::sendData(const QByteArray& data) {305void MetavoxelSystemClient::sendData(const QByteArray& data) {
306 NodeList::getInstance()->writeDatagram(data, _node);306 NodeList::getInstance()->writeDatagram(data, _node);
307 Application::getInstance()->getBandwidthMeter()->outputStream(BandwidthMeter::METAVOXELS).updateValue(data.size());307 Application::getInstance()->getBandwidthMeter()->outputStream(BandwidthMeter::METAVOXELS).updateValue(data.size());
308}308}
309 309
310void MetavoxelClient::readPacket(Bitstream& in) {310void MetavoxelSystemClient::readPacket(Bitstream& in) {
311 QVariant message;311 QVariant message;
312 in >> message;312 in >> message;
313 handleMessage(message, in);313 handleMessage(message, in);
@@ -324,15 +324,15 @@ void MetavoxelClient::readPacket(Bitstream& in) { · 10 unmodified lines
324 }324 }
325}325}
326 326
327void MetavoxelClient::clearSendRecordsBefore(int index) {327void MetavoxelSystemClient::clearSendRecordsBefore(int index) {
328 _sendRecords.erase(_sendRecords.begin(), _sendRecords.begin() + index + 1);328 _sendRecords.erase(_sendRecords.begin(), _sendRecords.begin() + index + 1);
329}329}
330 330
331void MetavoxelClient::clearReceiveRecordsBefore(int index) {331void MetavoxelSystemClient::clearReceiveRecordsBefore(int index) {
332 _receiveRecords.erase(_receiveRecords.begin(), _receiveRecords.begin() + index + 1);332 _receiveRecords.erase(_receiveRecords.begin(), _receiveRecords.begin() + index + 1);
333}333}
334 334
335void MetavoxelClient::handleMessage(const QVariant& message, Bitstream& in) {335void MetavoxelSystemClient::handleMessage(const QVariant& message, Bitstream& in) {
336 int userType = message.userType();336 int userType = message.userType();
337 if (userType == MetavoxelDeltaMessage::Type) {337 if (userType == MetavoxelDeltaMessage::Type) {
338 _data.readDelta(_receiveRecords.first().data, _receiveRecords.first().lod, in, _sendRecords.first().lod);338 _data.readDelta(_receiveRecords.first().data, _receiveRecords.first().lod, in, _sendRecords.first().lod);