mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 22:07:34 +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 <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[]) {
|
||||
|
||||
|
@ -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
|
||||
nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS);
|
||||
|
||||
timeval lastRequest = {};
|
||||
|
||||
unsigned char packetData[MAX_PACKET_SIZE];
|
||||
ssize_t receivedBytes = 0;
|
||||
|
||||
|
@ -51,38 +53,41 @@ int main(int argc, char* const argv[]) {
|
|||
Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool);
|
||||
|
||||
while (true) {
|
||||
// if we're here we have no assignment, so send a request
|
||||
qDebug() << "Sending an assignment request -" << requestAssignment;
|
||||
nodeList->sendAssignment(requestAssignment);
|
||||
if (usecTimestampNow() - usecTimestamp(&lastRequest) >= ASSIGNMENT_REQUEST_INTERVAL_USECS) {
|
||||
gettimeofday(&lastRequest, NULL);
|
||||
// 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 (packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) {
|
||||
if (nodeList->getNodeSocket()->receive(packetData, &receivedBytes) &&
|
||||
packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) {
|
||||
|
||||
// construct the deployed assignment from the packet data
|
||||
Assignment deployedAssignment(packetData, receivedBytes);
|
||||
|
||||
qDebug() << "Received an assignment - " << deployedAssignment << "\n";
|
||||
|
||||
// switch our nodelist DOMAIN_IP to the ip receieved in the assignment
|
||||
if (deployedAssignment.getDomainSocket()->sa_family == AF_INET) {
|
||||
in_addr domainSocketAddr = ((sockaddr_in*) deployedAssignment.getDomainSocket())->sin_addr;
|
||||
nodeList->setDomainIP(inet_ntoa(domainSocketAddr));
|
||||
|
||||
// construct the deployed assignment from the packet data
|
||||
Assignment deployedAssignment(packetData, receivedBytes);
|
||||
|
||||
qDebug() << "Received an assignment - " << deployedAssignment << "\n";
|
||||
|
||||
// switch our nodelist DOMAIN_IP to the ip receieved in the assignment
|
||||
if (deployedAssignment.getDomainSocket()->sa_family == AF_INET) {
|
||||
in_addr domainSocketAddr = ((sockaddr_in*) deployedAssignment.getDomainSocket())->sin_addr;
|
||||
nodeList->setDomainIP(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();
|
||||
qDebug() << "Changed domain IP to " << inet_ntoa(domainSocketAddr);
|
||||
}
|
||||
|
||||
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;
|
||||
_numNoReplyDomainCheckIns = 0;
|
||||
}
|
||||
|
||||
void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest) {
|
||||
|
|
Loading…
Reference in a new issue