have stubbed Operative check in with DS

This commit is contained in:
Stephen Birarda 2013-07-08 16:48:53 -07:00
parent 6a253f78d1
commit b5a47cddc0
2 changed files with 27 additions and 2 deletions

View file

@ -13,6 +13,7 @@
#include <iterator>
#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; }

View file

@ -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));