Retain a shared node pointer, use the active socket. Fixed a compile warning.

This commit is contained in:
Andrzej Kapolka 2014-01-27 16:41:25 -08:00
parent fbcd4cf363
commit 1e4bfffdd8
4 changed files with 22 additions and 21 deletions

View file

@ -128,4 +128,4 @@ void DatagramProcessor::processDatagrams() {
}
}
}
}
}

View file

@ -6,6 +6,7 @@
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include <QMutexLocker>
#include <QtDebug>
#include <SharedUtil.h>
@ -111,8 +112,7 @@ void MetavoxelSystem::render() {
void MetavoxelSystem::nodeAdded(SharedNodePointer node) {
if (node->getType() == NODE_TYPE_METAVOXEL_SERVER) {
QMetaObject::invokeMethod(this, "addClient", Q_ARG(const QUuid&, node->getUUID()),
Q_ARG(const HifiSockAddr&, node->getLocalSocket()));
QMetaObject::invokeMethod(this, "addClient", Q_ARG(const SharedNodePointer&, node));
}
}
@ -122,9 +122,9 @@ void MetavoxelSystem::nodeKilled(SharedNodePointer node) {
}
}
void MetavoxelSystem::addClient(const QUuid& uuid, const HifiSockAddr& address) {
MetavoxelClient* client = new MetavoxelClient(address);
_clients.insert(uuid, client);
void MetavoxelSystem::addClient(const SharedNodePointer& node) {
MetavoxelClient* client = new MetavoxelClient(node);
_clients.insert(node->getUUID(), client);
_clientsBySessionID.insert(client->getSessionID(), client);
}
@ -142,7 +142,7 @@ void MetavoxelSystem::receivedData(const QByteArray& data, const HifiSockAddr& s
}
MetavoxelClient* client = _clientsBySessionID.value(sessionID);
if (client) {
client->receivedData(data, sender);
client->receivedData(data);
}
}
@ -176,8 +176,8 @@ static QByteArray createDatagramHeader(const QUuid& sessionID) {
return header;
}
MetavoxelClient::MetavoxelClient(const HifiSockAddr& address) :
_address(address),
MetavoxelClient::MetavoxelClient(const SharedNodePointer& node) :
_node(node),
_sessionID(QUuid::createUuid()),
_sequencer(createDatagramHeader(_sessionID)) {
@ -214,16 +214,17 @@ void MetavoxelClient::simulate(float deltaTime, MetavoxelVisitor& visitor) {
_data.guide(visitor);
}
void MetavoxelClient::receivedData(const QByteArray& data, const HifiSockAddr& sender) {
// save the most recent sender
_address = sender;
void MetavoxelClient::receivedData(const QByteArray& data) {
// process through sequencer
_sequencer.receivedDatagram(data);
}
void MetavoxelClient::sendData(const QByteArray& data) {
NodeList::getInstance()->getNodeSocket().writeDatagram(data, _address.getAddress(), _address.getPort());
QMutexLocker locker(&_node->getMutex());
const HifiSockAddr* address = _node->getActiveSocket();
if (address) {
NodeList::getInstance()->getNodeSocket().writeDatagram(data, address->getAddress(), address->getPort());
}
}
void MetavoxelClient::readPacket(Bitstream& in) {

View file

@ -49,7 +49,7 @@ public slots:
private:
Q_INVOKABLE void addClient(const QUuid& uuid, const HifiSockAddr& address);
Q_INVOKABLE void addClient(const SharedNodePointer& node);
Q_INVOKABLE void removeClient(const QUuid& uuid);
Q_INVOKABLE void receivedData(const QByteArray& data, const HifiSockAddr& sender);
@ -86,7 +86,7 @@ class MetavoxelClient : public QObject {
public:
MetavoxelClient(const HifiSockAddr& address);
MetavoxelClient(const SharedNodePointer& node);
virtual ~MetavoxelClient();
const QUuid& getSessionID() const { return _sessionID; }
@ -95,7 +95,7 @@ public:
void simulate(float deltaTime, MetavoxelVisitor& visitor);
void receivedData(const QByteArray& data, const HifiSockAddr& sender);
void receivedData(const QByteArray& data);
private slots:
@ -115,7 +115,7 @@ private:
MetavoxelData data;
};
HifiSockAddr _address;
SharedNodePointer _node;
QUuid _sessionID;
DatagramSequencer _sequencer;

View file

@ -9,9 +9,9 @@
#ifndef __hifi__Snapshot__
#define __hifi__Snapshot__
#import <QString>
#import <QImage>
#import <QGLWidget>
#include <QString>
#include <QImage>
#include <QGLWidget>
#include <glm/glm.hpp>