From b5a47cddc0f7bb4cfb13f3be2446ab809a599db6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 8 Jul 2013 16:48:53 -0700 Subject: [PATCH] have stubbed Operative check in with DS --- libraries/shared/src/NodeList.h | 4 +++- libraries/shared/src/Operative.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index b1f7acdbb3..f926c0a5d6 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -13,6 +13,7 @@ #include #include "Node.h" +#include "NodeTypes.h" #include "UDPSocket.h" #ifdef _WIN32 @@ -48,7 +49,8 @@ public: NodeListIterator begin() const; NodeListIterator end() const; - char getOwnerType() const { return _ownerType; } + NODE_TYPE getOwnerType() const { return _ownerType; } + void setOwnerType(NODE_TYPE ownerType) { _ownerType = ownerType; } uint16_t getLastNodeID() const { return _lastNodeID; } void increaseNodeID() { ++_lastNodeID; } diff --git a/libraries/shared/src/Operative.cpp b/libraries/shared/src/Operative.cpp index ad45b1ed94..1ec74c7e86 100644 --- a/libraries/shared/src/Operative.cpp +++ b/libraries/shared/src/Operative.cpp @@ -200,13 +200,36 @@ const double OUR_FPS_IN_MILLISECONDS = 1000.0/ACTUAL_FPS; // determines FPS from const int ANIMATE_VOXELS_INTERVAL_USECS = OUR_FPS_IN_MILLISECONDS * 1000.0; // converts from milliseconds to usecs void Operative::run() { - timeval lastSendTime; + timeval lastSendTime = {}; + timeval lastDomainServerCheckIn = {}; + + NodeList* nodeList = NodeList::getInstance(); + + sockaddr nodePublicAddress; + + unsigned char* packetData = new unsigned char[MAX_PACKET_SIZE]; + ssize_t receivedBytes; + + // change the owner type on our NodeList + NodeList::getInstance()->setOwnerType(NODE_TYPE_AGENT); + NodeList::getInstance()->setNodeTypesOfInterest(&NODE_TYPE_VOXEL_SERVER, 1); while (true) { gettimeofday(&lastSendTime, NULL); renderMovingBug(); + // send a check in packet to the domain server if DOMAIN_SERVER_CHECK_IN_USECS has elapsed + if (usecTimestampNow() - usecTimestamp(&lastDomainServerCheckIn) >= DOMAIN_SERVER_CHECK_IN_USECS) { + gettimeofday(&lastDomainServerCheckIn, NULL); + NodeList::getInstance()->sendDomainServerCheckIn(); + } + + // Nodes sending messages to us... + if (nodeList->getNodeSocket()->receive(&nodePublicAddress, packetData, &receivedBytes)) { + NodeList::getInstance()->processNodeData(&nodePublicAddress, packetData, receivedBytes); + } + // dynamically sleep until we need to fire off the next set of voxels long long usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));