change to new packet sending in Application

This commit is contained in:
Stephen Birarda 2015-07-07 11:11:20 -07:00
parent edf7a96b58
commit e05470a11c

View file

@ -378,7 +378,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_runningScriptsWidget = new RunningScriptsWidget(_window); _runningScriptsWidget = new RunningScriptsWidget(_window);
_renderEngine->addTask(render::TaskPointer(new RenderDeferredTask())); _renderEngine->addTask(render::TaskPointer(new RenderDeferredTask()));
_renderEngine->registerScene(_main3DScene); _renderEngine->registerScene(_main3DScene);
// start the nodeThread so its event loop is running // start the nodeThread so its event loop is running
QThread* nodeThread = new QThread(this); QThread* nodeThread = new QThread(this);
nodeThread->setObjectName("Datagram Processor Thread"); nodeThread->setObjectName("Datagram Processor Thread");
@ -537,7 +537,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
// the GL surface // the GL surface
_glWidget->setCursor(Qt::BlankCursor); _glWidget->setCursor(Qt::BlankCursor);
#endif #endif
// enable mouse tracking; otherwise, we only get drag events // enable mouse tracking; otherwise, we only get drag events
_glWidget->setMouseTracking(true); _glWidget->setMouseTracking(true);
@ -606,7 +606,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_settingsTimer.setSingleShot(false); _settingsTimer.setSingleShot(false);
_settingsTimer.setInterval(SAVE_SETTINGS_INTERVAL); _settingsTimer.setInterval(SAVE_SETTINGS_INTERVAL);
_settingsThread.start(); _settingsThread.start();
if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) { if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) {
Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true); Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true);
cameraMenuChanged(); cameraMenuChanged();
@ -637,7 +637,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
ddeTracker->init(); ddeTracker->init();
connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
#endif #endif
auto applicationUpdater = DependencyManager::get<AutoUpdater>(); auto applicationUpdater = DependencyManager::get<AutoUpdater>();
connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog); connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog);
applicationUpdater->checkForUpdate(); applicationUpdater->checkForUpdate();
@ -879,7 +879,7 @@ void Application::paintGL() {
OculusManager::beginFrameTiming(); OculusManager::beginFrameTiming();
} }
PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings)); PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
PerformanceWarning warn(showWarnings, "Application::paintGL()"); PerformanceWarning warn(showWarnings, "Application::paintGL()");
@ -897,7 +897,7 @@ void Application::paintGL() {
} }
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN); Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN)); Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN));
@ -982,7 +982,7 @@ void Application::paintGL() {
renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
renderRearViewMirror(&renderArgs, _mirrorViewRect); renderRearViewMirror(&renderArgs, _mirrorViewRect);
} }
renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
@ -1756,9 +1756,9 @@ bool Application::acceptSnapshot(const QString& urlString) {
} }
void Application::sendPingPackets() { void Application::sendPingPackets() {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
nodeList->eachMatchingNode([](const SharedNodePointer& node)->bool { nodeList->eachMatchingNode([](const SharedNodePointer& node)->bool {
switch (node->getType()) { switch (node->getType()) {
case NodeType::AvatarMixer: case NodeType::AvatarMixer:
@ -1855,7 +1855,7 @@ void Application::idle() {
// After finishing all of the above work, ensure the idle timer is set to the proper interval, // After finishing all of the above work, ensure the idle timer is set to the proper interval,
// depending on whether we're throttling or not // depending on whether we're throttling or not
idleTimer->start(_glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : 0); idleTimer->start(_glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : 0);
} }
// check for any requested background downloads. // check for any requested background downloads.
emit checkBackgroundDownloads(); emit checkBackgroundDownloads();
@ -2661,7 +2661,8 @@ int Application::sendNackPackets() {
} }
int packetsSent = 0; int packetsSent = 0;
char packet[MAX_PACKET_SIZE];
auto nackPacket { NLPacket::create(PacketType::OctreeDataNack); }
// iterates thru all nodes in NodeList // iterates thru all nodes in NodeList
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
@ -2698,33 +2699,26 @@ int Application::sendNackPackets() {
QSet<OCTREE_PACKET_SEQUENCE>::const_iterator missingSequenceNumbersIterator = missingSequenceNumbers.constBegin(); QSet<OCTREE_PACKET_SEQUENCE>::const_iterator missingSequenceNumbersIterator = missingSequenceNumbers.constBegin();
while (numSequenceNumbersAvailable > 0) { while (numSequenceNumbersAvailable > 0) {
char* dataAt = packet; // reset the position we are writing at and the size we have used
int bytesRemaining = MAX_PACKET_SIZE; nackPacket->seek(0);
nackPacket->setSizeUsed(0);
// pack header
int numBytesPacketHeader = nodeList->populatePacketHeader(packet, PacketTypeOctreeDataNack);
dataAt += numBytesPacketHeader;
bytesRemaining -= numBytesPacketHeader;
// calculate and pack the number of sequence numbers // calculate and pack the number of sequence numbers
int numSequenceNumbersRoomFor = (bytesRemaining - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE); int numSequenceNumbersRoomFor = (nackPacket->size() - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE);
uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor); uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor);
uint16_t* numSequenceNumbersAt = (uint16_t*)dataAt;
*numSequenceNumbersAt = numSequenceNumbers; nackPacket->write(&numSequenceNumbers, sizeof(numSequenceNumbers));
dataAt += sizeof(uint16_t);
// pack sequence numbers // pack sequence numbers
for (int i = 0; i < numSequenceNumbers; i++) { for (int i = 0; i < numSequenceNumbers; i++) {
OCTREE_PACKET_SEQUENCE* sequenceNumberAt = (OCTREE_PACKET_SEQUENCE*)dataAt; OCTREE_PACKET_SEQUENCE missingNumber = *missingSequenceNumbersIterator;
*sequenceNumberAt = *missingSequenceNumbersIterator; nackPacket->write(&missingNumber, sizeof(OCTREE_PACKET_SEQUENCE));
dataAt += sizeof(OCTREE_PACKET_SEQUENCE);
missingSequenceNumbersIterator++; missingSequenceNumbersIterator++;
} }
numSequenceNumbersAvailable -= numSequenceNumbers; numSequenceNumbersAvailable -= numSequenceNumbers;
// send it // send the packet
nodeList->writeUnverifiedDatagram(packet, dataAt - packet, node); nodeList->sendUnreliablePacket(packet, node);
packetsSent++; packetsSent++;
} }
} }
@ -2756,9 +2750,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType::Value packetTyp
_octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale()); _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());
_octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust()); _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());
unsigned char queryPacket[MAX_PACKET_SIZE]; // Iterate all of the nodes, and get a count of how many octree servers we have...
// Iterate all of the nodes, and get a count of how many voxel servers we have...
int totalServers = 0; int totalServers = 0;
int inViewServers = 0; int inViewServers = 0;
int unknownJurisdictionServers = 0; int unknownJurisdictionServers = 0;
@ -2825,6 +2817,8 @@ void Application::queryOctree(NodeType_t serverType, PacketType::Value packetTyp
qCDebug(interfaceapp, "perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer); qCDebug(interfaceapp, "perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer);
} }
auto queryPacket { NLPacket::create(packetType); }
nodeList->eachNode([&](const SharedNodePointer& node){ nodeList->eachNode([&](const SharedNodePointer& node){
// only send to the NodeTypes that are serverType // only send to the NodeTypes that are serverType
if (node->getActiveSocket() && node->getType() == serverType) { if (node->getActiveSocket() && node->getType() == serverType) {
@ -2899,19 +2893,13 @@ void Application::queryOctree(NodeType_t serverType, PacketType::Value packetTyp
} else { } else {
_octreeQuery.setMaxQueryPacketsPerSecond(0); _octreeQuery.setMaxQueryPacketsPerSecond(0);
} }
// set up the packet for sending...
unsigned char* endOfQueryPacket = queryPacket;
// insert packet type/version and node UUID // encode the query data
endOfQueryPacket += nodeList->populatePacketHeader(reinterpret_cast<char*>(endOfQueryPacket), packetType); int packetSize = _octreeQuery.getBroadcastData(queryPacket.payload());
queryPacket.setSizeUsed(packetSize);
// encode the query data...
endOfQueryPacket += _octreeQuery.getBroadcastData(endOfQueryPacket);
int packetLength = endOfQueryPacket - queryPacket;
// make sure we still have an active socket // make sure we still have an active socket
nodeList->writeUnverifiedDatagram(reinterpret_cast<const char*>(queryPacket), packetLength, node); nodeList->sendUnreliablePacket(queryPacket, node);
} }
}); });
} }
@ -3310,7 +3298,7 @@ namespace render {
const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f; const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f;
const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f; const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f;
glm::vec3 sunDirection = (args->_viewFrustum->getPosition()/*getAvatarPosition()*/ - closestData.getSunLocation()) glm::vec3 sunDirection = (args->_viewFrustum->getPosition()/*getAvatarPosition()*/ - closestData.getSunLocation())
/ closestData.getAtmosphereOuterRadius(); / closestData.getAtmosphereOuterRadius();
float height = glm::distance(args->_viewFrustum->getPosition()/*theCamera.getPosition()*/, closestData.getAtmosphereCenter()); float height = glm::distance(args->_viewFrustum->getPosition()/*theCamera.getPosition()*/, closestData.getAtmosphereCenter());
if (height < closestData.getAtmosphereInnerRadius()) { if (height < closestData.getAtmosphereInnerRadius()) {
@ -3318,20 +3306,20 @@ namespace render {
alpha = 0.0f; alpha = 0.0f;
if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) { if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {
float directionY = glm::clamp(sunDirection.y, float directionY = glm::clamp(sunDirection.y,
-APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON)
+ APPROXIMATE_DISTANCE_FROM_HORIZON; + APPROXIMATE_DISTANCE_FROM_HORIZON;
alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
} }
} else if (height < closestData.getAtmosphereOuterRadius()) { } else if (height < closestData.getAtmosphereOuterRadius()) {
alpha = (height - closestData.getAtmosphereInnerRadius()) / alpha = (height - closestData.getAtmosphereInnerRadius()) /
(closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius()); (closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius());
if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) { if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {
float directionY = glm::clamp(sunDirection.y, float directionY = glm::clamp(sunDirection.y,
-APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON)
+ APPROXIMATE_DISTANCE_FROM_HORIZON; + APPROXIMATE_DISTANCE_FROM_HORIZON;
alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
} }
@ -3358,7 +3346,7 @@ namespace render {
} }
} else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) { } else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) {
PerformanceTimer perfTimer("skybox"); PerformanceTimer perfTimer("skybox");
skybox = skyStage->getSkybox(); skybox = skyStage->getSkybox();
if (skybox) { if (skybox) {
model::Skybox::render(batch, *(Application::getInstance()->getDisplayViewFrustum()), *skybox); model::Skybox::render(batch, *(Application::getInstance()->getDisplayViewFrustum()), *skybox);
@ -3465,7 +3453,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// Assuming nothing get's rendered through that // Assuming nothing get's rendered through that
if (!selfAvatarOnly) { if (!selfAvatarOnly) {
@ -3508,8 +3496,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload); pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);
} else { } else {
pendingChanges.updateItem<WorldBoxRenderData>(WorldBoxRenderData::_item, pendingChanges.updateItem<WorldBoxRenderData>(WorldBoxRenderData::_item,
[](WorldBoxRenderData& payload) { [](WorldBoxRenderData& payload) {
payload._val++; payload._val++;
}); });
} }
@ -3528,7 +3516,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
} }
{ {
PerformanceTimer perfTimer("SceneProcessPendingChanges"); PerformanceTimer perfTimer("SceneProcessPendingChanges");
_main3DScene->enqueuePendingChanges(pendingChanges); _main3DScene->enqueuePendingChanges(pendingChanges);
_main3DScene->processPendingChangesQueue(); _main3DScene->processPendingChangesQueue();
@ -3560,7 +3548,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
// Before the deferred pass, let's try to use the render engine // Before the deferred pass, let's try to use the render engine
_renderEngine->run(); _renderEngine->run();
auto engineRC = _renderEngine->getRenderContext(); auto engineRC = _renderEngine->getRenderContext();
sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems); sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems);
sceneInterface->setEngineDrawnOpaqueItems(engineRC->_numDrawnOpaqueItems); sceneInterface->setEngineDrawnOpaqueItems(engineRC->_numDrawnOpaqueItems);
@ -4835,8 +4823,8 @@ qreal Application::getDevicePixelRatio() {
mat4 Application::getEyeProjection(int eye) const { mat4 Application::getEyeProjection(int eye) const {
if (isHMDMode()) { if (isHMDMode()) {
return OculusManager::getEyeProjection(eye); return OculusManager::getEyeProjection(eye);
} }
return _viewFrustum.getProjection(); return _viewFrustum.getProjection();
} }