switch to using SharedNodePointer instead of UUID in octree server send thread

This commit is contained in:
ZappoMan 2014-03-27 02:33:32 -07:00
parent 55b9dd1aee
commit 9fdfa4a7a8
5 changed files with 15 additions and 31 deletions

View file

@ -76,9 +76,9 @@ void OctreeQueryNode::deleteLater() {
}
void OctreeQueryNode::initializeOctreeSendThread(OctreeServer* octreeServer, const QUuid& nodeUUID) {
void OctreeQueryNode::initializeOctreeSendThread(OctreeServer* octreeServer, SharedNodePointer node) {
// Create octree sending thread...
_octreeSendThread = new OctreeSendThread(nodeUUID, octreeServer);
_octreeSendThread = new OctreeSendThread(octreeServer, node);
_octreeSendThread->initialize(true);
}

View file

@ -83,7 +83,7 @@ public:
OctreeSceneStats stats;
void initializeOctreeSendThread(OctreeServer* octreeServer, const QUuid& nodeUUID);
void initializeOctreeSendThread(OctreeServer* octreeServer, SharedNodePointer node);
bool isOctreeSendThreadInitalized() { return _octreeSendThread; }
void dumpOutOfView();

View file

@ -19,11 +19,10 @@
quint64 startSceneSleepTime = 0;
quint64 endSceneSleepTime = 0;
OctreeSendThread::OctreeSendThread(const QUuid& nodeUUID, OctreeServer* myServer) :
_nodeUUID(nodeUUID),
OctreeSendThread::OctreeSendThread(OctreeServer* myServer, SharedNodePointer node) :
_myServer(myServer),
_node(node),
_packetData(),
_nodeMissingCount(0),
_processLock(),
_isShuttingDown(false)
{
@ -44,7 +43,8 @@ OctreeSendThread::~OctreeSendThread() {
}
qDebug() << qPrintable(safeServerName) << "server [" << _myServer << "]: client disconnected "
"- ending sending thread [" << this << "]";
OctreeServer::clientDisconnected();
_node.clear();
OctreeServer::clientDisconnected();
}
void OctreeSendThread::setIsShuttingDown() {
@ -68,35 +68,18 @@ bool OctreeSendThread::process() {
return false; // exit early if we're shutting down
}
const int MAX_NODE_MISSING_CHECKS = 10;
if (_nodeMissingCount > MAX_NODE_MISSING_CHECKS) {
qDebug() << "our target node:" << _nodeUUID << "has been missing the last" << _nodeMissingCount
<< "times we checked, we are going to stop attempting to send.";
return false; // stop processing and shutdown, our node no longer exists
}
quint64 start = usecTimestampNow();
// don't do any send processing until the initial load of the octree is complete...
if (_myServer->isInitialLoadComplete()) {
// see if we can get access to our node, but don't wait on the lock, if the nodeList is busy
// it might not return a node that is known, but that's ok we can handle that case.
SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(_nodeUUID, false);
if (node) {
_nodeMissingCount = 0;
OctreeQueryNode* nodeData = NULL;
nodeData = (OctreeQueryNode*) node->getLinkedData();
if (!_node.isNull()) {
OctreeQueryNode* nodeData = static_cast<OctreeQueryNode*>(_node->getLinkedData());
// Sometimes the node data has not yet been linked, in which case we can't really do anything
if (nodeData && !nodeData->isShuttingDown()) {
bool viewFrustumChanged = nodeData->updateCurrentViewFrustum();
packetDistributor(node, nodeData, viewFrustumChanged);
packetDistributor(_node, nodeData, viewFrustumChanged);
}
} else {
_nodeMissingCount++;
}
}

View file

@ -21,7 +21,7 @@
class OctreeSendThread : public GenericThread {
Q_OBJECT
public:
OctreeSendThread(const QUuid& nodeUUID, OctreeServer* myServer);
OctreeSendThread(OctreeServer* myServer, SharedNodePointer node);
virtual ~OctreeSendThread();
void setIsShuttingDown();
@ -38,7 +38,7 @@ protected:
virtual bool process();
private:
QUuid _nodeUUID;
SharedNodePointer _node;
OctreeServer* _myServer;
int handlePacketSend(const SharedNodePointer& node, OctreeQueryNode* nodeData, int& trueBytesSent, int& truePacketsSent);
@ -46,7 +46,6 @@ private:
OctreePacketData _packetData;
int _nodeMissingCount;
QMutex _processLock; // don't allow us to have our nodeData, or our thread to be deleted while we're processing
bool _isShuttingDown;
};

View file

@ -835,7 +835,7 @@ void OctreeServer::readPendingDatagrams() {
if (debug) {
qDebug() << "calling initializeOctreeSendThread()... node:" << *matchingNode;
}
nodeData->initializeOctreeSendThread(this, matchingNode->getUUID());
nodeData->initializeOctreeSendThread(this, matchingNode);
}
}
} else if (packetType == PacketTypeJurisdictionRequest) {
@ -852,7 +852,9 @@ void OctreeServer::readPendingDatagrams() {
void OctreeServer::run() {
_safeServerName = getMyServerName();
// Before we do anything else, create our tree...
OctreeElement::resetPopulationStatistics();
_tree = createTree();
// use common init to setup common timers and logging