Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -6,6 +6,7 @@ · 5 unmodified lines | |||
| 6 | // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. | 6 | // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. |
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #include <QMutexLocker> | ||
| 9 | #include <QtDebug> | 10 | #include <QtDebug> |
| 10 | 11 | ||
| 11 | #include <SharedUtil.h> | 12 | #include <SharedUtil.h> |
| @@ -111,8 +112,7 @@ void MetavoxelSystem::render() { · 99 unmodified lines | |||
| 111 | 112 | ||
| 112 | void MetavoxelSystem::nodeAdded(SharedNodePointer node) { | 113 | void MetavoxelSystem::nodeAdded(SharedNodePointer node) { |
| 113 | if (node->getType() == NODE_TYPE_METAVOXEL_SERVER) { | 114 | if (node->getType() == NODE_TYPE_METAVOXEL_SERVER) { |
| 114 | QMetaObject::invokeMethod(this, "addClient", Q_ARG(const QUuid&, node->getUUID()), | 115 | QMetaObject::invokeMethod(this, "addClient", Q_ARG(const SharedNodePointer&, node)); |
| 115 | Q_ARG(const HifiSockAddr&, node->getLocalSocket())); | ||
| 116 | } | 116 | } |
| 117 | } | 117 | } |
| 118 | 118 | ||
| @@ -122,9 +122,9 @@ void MetavoxelSystem::nodeKilled(SharedNodePointer node) { · 3 unmodified lines | |||
| 122 | } | 122 | } |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | void MetavoxelSystem::addClient(const QUuid& uuid, const HifiSockAddr& address) { | 125 | void MetavoxelSystem::addClient(const SharedNodePointer& node) { |
| 126 | MetavoxelClient* client = new MetavoxelClient(address); | 126 | MetavoxelClient* client = new MetavoxelClient(node); |
| 127 | _clients.insert(uuid, client); | 127 | _clients.insert(node->getUUID(), client); |
| 128 | _clientsBySessionID.insert(client->getSessionID(), client); | 128 | _clientsBySessionID.insert(client->getSessionID(), client); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| @@ -142,7 +142,7 @@ void MetavoxelSystem::receivedData(const QByteArray& data, const HifiSockAddr& s · 11 unmodified lines | |||
| 142 | } | 142 | } |
| 143 | MetavoxelClient* client = _clientsBySessionID.value(sessionID); | 143 | MetavoxelClient* client = _clientsBySessionID.value(sessionID); |
| 144 | if (client) { | 144 | if (client) { |
| 145 | client->receivedData(data, sender); | 145 | client->receivedData(data); |
| 146 | } | 146 | } |
| 147 | } | 147 | } |
| 148 | 148 | ||
| @@ -176,8 +176,8 @@ static QByteArray createDatagramHeader(const QUuid& sessionID) { · 27 unmodified lines | |||
| 176 | return header; | 176 | return header; |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | MetavoxelClient::MetavoxelClient(const HifiSockAddr& address) : | 179 | MetavoxelClient::MetavoxelClient(const SharedNodePointer& node) : |
| 180 | _address(address), | 180 | _node(node), |
| 181 | _sessionID(QUuid::createUuid()), | 181 | _sessionID(QUuid::createUuid()), |
| 182 | _sequencer(createDatagramHeader(_sessionID)) { | 182 | _sequencer(createDatagramHeader(_sessionID)) { |
| 183 | 183 | ||
| @@ -214,16 +214,17 @@ void MetavoxelClient::simulate(float deltaTime, MetavoxelVisitor& visitor) { · 30 unmodified lines | |||
| 214 | _data.guide(visitor); | 214 | _data.guide(visitor); |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | void MetavoxelClient::receivedData(const QByteArray& data, const HifiSockAddr& sender) { | 217 | void MetavoxelClient::receivedData(const QByteArray& data) { |
| 218 | // save the most recent sender | ||
| 219 | _address = sender; | ||
| 220 | |||
| 221 | // process through sequencer | 218 | // process through sequencer |
| 222 | _sequencer.receivedDatagram(data); | 219 | _sequencer.receivedDatagram(data); |
| 223 | } | 220 | } |
| 224 | 221 | ||
| 225 | void MetavoxelClient::sendData(const QByteArray& data) { | 222 | void MetavoxelClient::sendData(const QByteArray& data) { |
| 226 | NodeList::getInstance()->getNodeSocket().writeDatagram(data, _address.getAddress(), _address.getPort()); | 223 | QMutexLocker locker(&_node->getMutex()); |
| 224 | const HifiSockAddr* address = _node->getActiveSocket(); | ||
| 225 | if (address) { | ||
| 226 | NodeList::getInstance()->getNodeSocket().writeDatagram(data, address->getAddress(), address->getPort()); | ||
| 227 | } | ||
| 227 | } | 228 | } |
| 228 | 229 | ||
| 229 | void MetavoxelClient::readPacket(Bitstream& in) { | 230 | void MetavoxelClient::readPacket(Bitstream& in) { |