History

Use the existing session stuff for metavoxels rather than a separate system.

Andrzej Kapolka committed 12 years ago

Commit 9c91d3c1 parent bb56e286 files · +69 −167Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+24−63
@@ -25,12 +25,6 @@ MetavoxelSystem::MetavoxelSystem() : · 24 unmodified lines
2525 _buffer(QOpenGLBuffer::VertexBuffer) {
2626 }
2727
28−MetavoxelSystem::~MetavoxelSystem() {
29− for (QHash<QUuid, MetavoxelClient*>::const_iterator it = _clients.begin(); it != _clients.end(); it++) {
30− delete it.value();
31− }
32−}
33−
3428 void MetavoxelSystem::init() {
3529 if (!_program.isLinked()) {
3630 switchToResourcesParentIfRequired();
@@ -42,33 +36,35 @@ void MetavoxelSystem::init() { · 5 unmodified lines
4236 // let the script cache know to use our common access manager
4337 ScriptCache::getInstance()->setNetworkAccessManager(Application::getInstance()->getNetworkAccessManager());
4438 }
45−
46− NodeList* nodeList = NodeList::getInstance();
47−
48− connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), SLOT(nodeAdded(SharedNodePointer)));
49− connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
50−
5139 _buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
5240 _buffer.create();
41+
42+ connect(NodeList::getInstance(), SIGNAL(nodeAdded(SharedNodePointer)), SLOT(maybeAttachClient(const SharedNodePointer&)));
5343 }
5444
5545 void MetavoxelSystem::applyEdit(const MetavoxelEditMessage& edit) {
56− foreach (MetavoxelClient* client, _clients) {
57− client->applyEdit(edit);
46+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
47+ if (node->getType() == NodeType::MetavoxelServer) {
48+ MetavoxelClient* client = static_cast<MetavoxelClient*>(node->getLinkedData());
49+ if (client) {
50+ client->applyEdit(edit);
51+ }
52+ }
5853 }
5954 }
6055
61−void MetavoxelSystem::processData(const QByteArray& data, const HifiSockAddr& sender) {
62− QMetaObject::invokeMethod(this, "receivedData", Q_ARG(const QByteArray&, data), Q_ARG(const HifiSockAddr&, sender));
63−}
64−
6556 void MetavoxelSystem::simulate(float deltaTime) {
6657 // simulate the clients
6758 _points.clear();
68− foreach (MetavoxelClient* client, _clients) {
69− client->simulate(deltaTime, _pointVisitor);
59+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
60+ if (node->getType() == NodeType::MetavoxelServer) {
61+ MetavoxelClient* client = static_cast<MetavoxelClient*>(node->getLinkedData());
62+ if (client) {
63+ client->simulate(deltaTime, _pointVisitor);
64+ }
65+ }
7066 }
71−
67+
7268 _buffer.bind();
7369 int bytes = _points.size() * sizeof(Point);
7470 if (_buffer.size() < bytes) {
@@ -120,39 +116,10 @@ void MetavoxelSystem::render() { · 45 unmodified lines
120116 _program.release();
121117 }
122118
123−void MetavoxelSystem::nodeAdded(SharedNodePointer node) {
119+void MetavoxelSystem::maybeAttachClient(const SharedNodePointer& node) {
124120 if (node->getType() == NodeType::MetavoxelServer) {
125− QMetaObject::invokeMethod(this, "addClient", Q_ARG(const SharedNodePointer&, node));
126− }
127−}
128−
129−void MetavoxelSystem::nodeKilled(SharedNodePointer node) {
130− if (node->getType() == NodeType::MetavoxelServer) {
131− QMetaObject::invokeMethod(this, "removeClient", Q_ARG(const QUuid&, node->getUUID()));
132− }
133−}
134−
135−void MetavoxelSystem::addClient(const SharedNodePointer& node) {
136− MetavoxelClient* client = new MetavoxelClient(node);
137− _clients.insert(node->getUUID(), client);
138− _clientsBySessionID.insert(client->getSessionID(), client);
139−}
140−
141−void MetavoxelSystem::removeClient(const QUuid& uuid) {
142− MetavoxelClient* client = _clients.take(uuid);
143− _clientsBySessionID.remove(client->getSessionID());
144− delete client;
145−}
146−
147−void MetavoxelSystem::receivedData(const QByteArray& data, const SharedNodePointer& sendingNode) {
148− int headerPlusIDSize;
149− QUuid sessionID = readSessionID(data, sendingNode, headerPlusIDSize);
150− if (sessionID.isNull()) {
151− return;
152− }
153− MetavoxelClient* client = _clientsBySessionID.value(sessionID);
154− if (client) {
155− client->receivedData(data);
121+ QMutexLocker locker(&node->getMutex());
122+ node->setLinkedData(new MetavoxelClient(NodeList::getInstance()->nodeWithUUID(node->getUUID())));
156123 }
157124 }
158125
@@ -179,16 +146,9 @@ bool MetavoxelSystem::PointVisitor::visit(MetavoxelInfo& info) { · 20 unmodified lines
179146 return false;
180147 }
181148
182−static QByteArray createDatagramHeader(const QUuid& sessionID) {
183− QByteArray header = byteArrayWithPopluatedHeader(PacketTypeMetavoxelData);
184− header += sessionID.toRfc4122();
185− return header;
186−}
187−
188149 MetavoxelClient::MetavoxelClient(const SharedNodePointer& node) :
189150 _node(node),
190− _sessionID(QUuid::createUuid()),
191− _sequencer(createDatagramHeader(_sessionID)) {
151+ _sequencer(byteArrayWithPopluatedHeader(PacketTypeMetavoxelData)) {
192152
193153 connect(&_sequencer, SIGNAL(readyToWrite(const QByteArray&)), SLOT(sendData(const QByteArray&)));
194154 connect(&_sequencer, SIGNAL(readyToRead(Bitstream&)), SLOT(readPacket(Bitstream&)));
@@ -223,9 +183,10 @@ void MetavoxelClient::simulate(float deltaTime, MetavoxelVisitor& visitor) { · 28 unmodified lines
223183 _data.guide(visitor);
224184 }
225185
226−void MetavoxelClient::receivedData(const QByteArray& data) {
186+int MetavoxelClient::parseData(const QByteArray& packet) {
227187 // process through sequencer
228− _sequencer.receivedDatagram(data);
188+ QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet));
189+ return packet.size();
229190 }
230191
231192 void MetavoxelClient::sendData(const QByteArray& data) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t