mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 19:02:55 +02:00
correct timing for assignment-client check in
This commit is contained in:
parent
9eef894e24
commit
f18a40dc89
2 changed files with 36 additions and 30 deletions
|
@ -16,7 +16,7 @@
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
const int ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
|
const long long ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
|
||||||
|
|
||||||
int main(int argc, char* const argv[]) {
|
int main(int argc, char* const argv[]) {
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ int main(int argc, char* const argv[]) {
|
||||||
// change the timeout on the nodelist socket to be as often as we want to re-request
|
// change the timeout on the nodelist socket to be as often as we want to re-request
|
||||||
nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS);
|
nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS);
|
||||||
|
|
||||||
|
timeval lastRequest = {};
|
||||||
|
|
||||||
unsigned char packetData[MAX_PACKET_SIZE];
|
unsigned char packetData[MAX_PACKET_SIZE];
|
||||||
ssize_t receivedBytes = 0;
|
ssize_t receivedBytes = 0;
|
||||||
|
|
||||||
|
@ -51,38 +53,41 @@ int main(int argc, char* const argv[]) {
|
||||||
Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool);
|
Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// if we're here we have no assignment, so send a request
|
if (usecTimestampNow() - usecTimestamp(&lastRequest) >= ASSIGNMENT_REQUEST_INTERVAL_USECS) {
|
||||||
qDebug() << "Sending an assignment request -" << requestAssignment;
|
gettimeofday(&lastRequest, NULL);
|
||||||
nodeList->sendAssignment(requestAssignment);
|
// if we're here we have no assignment, so send a request
|
||||||
|
qDebug() << "Sending an assignment request -" << requestAssignment;
|
||||||
|
nodeList->sendAssignment(requestAssignment);
|
||||||
|
}
|
||||||
|
|
||||||
while (nodeList->getNodeSocket()->receive(packetData, &receivedBytes)) {
|
if (nodeList->getNodeSocket()->receive(packetData, &receivedBytes) &&
|
||||||
if (packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) {
|
packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) {
|
||||||
|
|
||||||
// construct the deployed assignment from the packet data
|
// construct the deployed assignment from the packet data
|
||||||
Assignment deployedAssignment(packetData, receivedBytes);
|
Assignment deployedAssignment(packetData, receivedBytes);
|
||||||
|
|
||||||
qDebug() << "Received an assignment - " << deployedAssignment << "\n";
|
qDebug() << "Received an assignment - " << deployedAssignment << "\n";
|
||||||
|
|
||||||
// switch our nodelist DOMAIN_IP to the ip receieved in the assignment
|
// switch our nodelist DOMAIN_IP to the ip receieved in the assignment
|
||||||
if (deployedAssignment.getDomainSocket()->sa_family == AF_INET) {
|
if (deployedAssignment.getDomainSocket()->sa_family == AF_INET) {
|
||||||
in_addr domainSocketAddr = ((sockaddr_in*) deployedAssignment.getDomainSocket())->sin_addr;
|
in_addr domainSocketAddr = ((sockaddr_in*) deployedAssignment.getDomainSocket())->sin_addr;
|
||||||
nodeList->setDomainIP(inet_ntoa(domainSocketAddr));
|
nodeList->setDomainIP(inet_ntoa(domainSocketAddr));
|
||||||
|
|
||||||
qDebug() << "Changed domain IP to " << inet_ntoa(domainSocketAddr);
|
qDebug() << "Changed domain IP to " << inet_ntoa(domainSocketAddr);
|
||||||
}
|
|
||||||
|
|
||||||
if (deployedAssignment.getType() == Assignment::AudioMixer) {
|
|
||||||
AudioMixer::run();
|
|
||||||
} else {
|
|
||||||
AvatarMixer::run();
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "Assignment finished or never started - waiting for new assignment";
|
|
||||||
|
|
||||||
// reset our NodeList by switching back to unassigned and clearing the list
|
|
||||||
nodeList->setOwnerType(NODE_TYPE_UNASSIGNED);
|
|
||||||
nodeList->clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (deployedAssignment.getType() == Assignment::AudioMixer) {
|
||||||
|
AudioMixer::run();
|
||||||
|
} else {
|
||||||
|
qDebug() << "Running as an avatar mixer!";
|
||||||
|
AvatarMixer::run();
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Assignment finished or never started - waiting for new assignment";
|
||||||
|
|
||||||
|
// reset our NodeList by switching back to unassigned and clearing the list
|
||||||
|
nodeList->setOwnerType(NODE_TYPE_UNASSIGNED);
|
||||||
|
nodeList->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -255,6 +255,7 @@ void NodeList::clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_numNodes = 0;
|
_numNodes = 0;
|
||||||
|
_numNoReplyDomainCheckIns = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest) {
|
void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest) {
|
||||||
|
|
Loading…
Reference in a new issue