fix to how voxel servers are queried when they have no known jurisdiction

This commit is contained in:
ZappoMan 2013-10-31 12:06:18 -07:00
parent ee39898891
commit af1047f5e0

View file

@ -2391,13 +2391,23 @@ void Application::queryVoxels() {
NodeList* nodeList = NodeList::getInstance();
// Iterate all of the nodes, and get a count of how many voxel servers we have...
int voxelServerCount = 0;
int totalServers = 0;
int inViewServers = 0;
int unknownJurisdictionServers = 0;
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
// only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER
if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) {
totalServers++;
// get the server bounds for this server
QUuid nodeUUID = node->getUUID();
// if we haven't heard from this voxel server, go ahead and send it a query, so we
// can get the jurisdiction...
if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) {
unknownJurisdictionServers++;
} else {
const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID];
unsigned char* rootCode = map.getRootOctalCode();
@ -2411,19 +2421,33 @@ void Application::queryVoxels() {
ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds);
if (serverFrustumLocation != ViewFrustum::OUTSIDE) {
voxelServerCount++;
inViewServers++;
}
}
}
}
}
// assume there's at least one voxel server
if (voxelServerCount < 1) {
voxelServerCount = 1;
//qDebug("Servers: total %d, in view %d, unknown jurisdiction %d \n",
// totalServers, inViewServers, unknownJurisdictionServers);
int perServerPPS;
const int SMALL_BUDGET = 10;
int perUnknownServer = SMALL_BUDGET;
// determine PPS based on number of servers
if (inViewServers >= 1) {
// set our preferred PPS to be exactly evenly divided among all of the voxel servers... and allocate 1 PPS
// for each unknown jurisdiction server
perServerPPS = (DEFAULT_MAX_VOXEL_PPS/inViewServers) - (unknownJurisdictionServers * SMALL_BUDGET);
} else {
perServerPPS = 0;
if (unknownJurisdictionServers > 0) {
perUnknownServer = (DEFAULT_MAX_VOXEL_PPS/unknownJurisdictionServers);
}
}
// set our preferred PPS to be exactly evenly divided among all of the voxel servers...
int perServerPPS = DEFAULT_MAX_VOXEL_PPS/voxelServerCount;
//qDebug("perServerPPS: %d perUnknownServer: %d\n", perServerPPS, perUnknownServer);
UDPSocket* nodeSocket = NodeList::getInstance()->getNodeSocket();
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
@ -2433,6 +2457,16 @@ void Application::queryVoxels() {
// get the server bounds for this server
QUuid nodeUUID = node->getUUID();
bool inView = false;
bool unknownView = false;
// if we haven't heard from this voxel server, go ahead and send it a query, so we
// can get the jurisdiction...
if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) {
unknownView = true; // assume it's in view
//qDebug() << "no known jurisdiction for node " << *node << ", assume it's visible.\n";
} else {
const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID];
unsigned char* rootCode = map.getRootOctalCode();
@ -2444,12 +2478,28 @@ void Application::queryVoxels() {
serverBounds.scale(TREE_SCALE);
ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds);
if (serverFrustumLocation != ViewFrustum::OUTSIDE) {
//printf("_voxelQuery.setMaxVoxelPacketsPerSecond(perServerPPS=%d)\n",perServerPPS);
_voxelQuery.setMaxVoxelPacketsPerSecond(perServerPPS);
inView = true;
} else {
inView = false;
}
}
}
if (inView) {
_voxelQuery.setMaxVoxelPacketsPerSecond(perServerPPS);
} else if (unknownView) {
//qDebug() << "no known jurisdiction for node " << *node << ", give it budget of "
// << perUnknownServer << " to send us jurisdiction.\n";
// set the query's position/orientation to be degenerate in a manner that will get the scene quickly
_voxelQuery.setCameraPosition(glm::vec3(-0.1,-0.1,-0.1));
const glm::quat OFF_IN_NEGATIVE_SPACE = glm::quat(-0.5, 0, -0.5, 1.0);
_voxelQuery.setCameraOrientation(OFF_IN_NEGATIVE_SPACE);
_voxelQuery.setCameraNearClip(0.1);
_voxelQuery.setCameraFarClip(0.1);
_voxelQuery.setMaxVoxelPacketsPerSecond(perUnknownServer);
} else {
//printf("_voxelQuery.setMaxVoxelPacketsPerSecond(0)\n");
_voxelQuery.setMaxVoxelPacketsPerSecond(0);
}
// set up the packet for sending...
@ -2472,7 +2522,6 @@ void Application::queryVoxels() {
_bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////