History

merge from upstream

Seth Alves committed 10 years ago

Commit f013f952 parents 0b1fa4f eecb5b9361 files · +14555 −4248Browse files

Showing the changes to interface/src/Application.cpp (1 of 361 files). Show all

Unified · Split

interface/src/Application.cpp+97−49
@@ -70,6 +70,7 @@ · 69 unmodified lines
7070 #include <LogHandler.h>
7171 #include <MainWindow.h>
7272 #include <MessageDialog.h>
73+#include <MessagesClient.h>
7374 #include <ModelEntityItem.h>
7475 #include <NetworkAccessManager.h>
7576 #include <NetworkingConstants.h>
@@ -86,6 +87,7 @@ · 10 unmodified lines
8687 #include <RenderDeferredTask.h>
8788 #include <ResourceCache.h>
8889 #include <SceneScriptingInterface.h>
90+#include <RecordingScriptingInterface.h>
8991 #include <ScriptCache.h>
9092 #include <SoundCache.h>
9193 #include <TextureCache.h>
@@ -94,13 +96,15 @@ · 2 unmodified lines
9496 #include <UserActivityLogger.h>
9597 #include <UUID.h>
9698 #include <VrMenu.h>
99+#include <recording/Deck.h>
100+#include <recording/Recorder.h>
97101
98102 #include "AnimDebugDraw.h"
99103 #include "AudioClient.h"
100104 #include "audio/AudioScope.h"
101105 #include "avatar/AvatarManager.h"
102106 #include "CrashHandler.h"
103−#include "devices/3DConnexionClient.h"
107+#include "input-plugins/SpacemouseManager.h"
104108 #include "devices/DdeFaceTracker.h"
105109 #include "devices/EyeTracker.h"
106110 #include "devices/Faceshift.h"
@@ -132,6 +136,7 @@ · 25 unmodified lines
132136 #endif
133137 #include "Stars.h"
134138 #include "ui/AddressBarDialog.h"
139+#include "ui/RecorderDialog.h"
135140 #include "ui/AvatarInputs.h"
136141 #include "ui/AssetUploadDialogFactory.h"
137142 #include "ui/DataWebDialog.h"
@@ -298,6 +303,8 @@ bool setupEssentials(int& argc, char** argv) { · 160 unmodified lines
298303 Setting::init();
299304
300305 // Set dependencies
306+ DependencyManager::set<recording::Deck>();
307+ DependencyManager::set<recording::Recorder>();
301308 DependencyManager::set<AddressManager>();
302309 DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
303310 DependencyManager::set<GeometryCache>();
@@ -322,6 +329,7 @@ bool setupEssentials(int& argc, char** argv) { · 18 unmodified lines
322329 DependencyManager::set<ResourceCacheSharedItems>();
323330 DependencyManager::set<DesktopScriptingInterface>();
324331 DependencyManager::set<EntityScriptingInterface>();
332+ DependencyManager::set<RecordingScriptingInterface>();
325333 DependencyManager::set<WindowScriptingInterface>();
326334 DependencyManager::set<HMDScriptingInterface>();
327335
@@ -335,6 +343,7 @@ bool setupEssentials(int& argc, char** argv) { · 7 unmodified lines
335343 DependencyManager::set<PathUtils>();
336344 DependencyManager::set<InterfaceActionFactory>();
337345 DependencyManager::set<AssetClient>();
346+ DependencyManager::set<MessagesClient>();
338347 DependencyManager::set<UserInputMapper>();
339348 DependencyManager::set<controller::ScriptingInterface, ControllerScriptingInterface>();
340349 DependencyManager::set<InterfaceParentFinder>();
@@ -449,6 +458,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 108 unmodified lines
449458 audioIO->setOrientationGetter([this]{ return getMyAvatar()->getOrientationForAudio(); });
450459
451460 audioIO->moveToThread(audioThread);
461+ recording::Frame::registerFrameHandler(AudioConstants::AUDIO_FRAME_NAME, [=](recording::Frame::ConstPointer frame) {
462+ audioIO->handleRecordedAudioInput(frame->data);
463+ });
464+
465+ connect(audioIO.data(), &AudioClient::inputReceived, [](const QByteArray& audio){
466+ static auto recorder = DependencyManager::get<recording::Recorder>();
467+ if (recorder->isRecording()) {
468+ static const recording::FrameType AUDIO_FRAME_TYPE = recording::Frame::registerFrameType(AudioConstants::AUDIO_FRAME_NAME);
469+ recorder->recordFrame(AUDIO_FRAME_TYPE, audio);
470+ }
471+ });
452472
453473 auto& audioScriptingInterface = AudioScriptingInterface::getInstance();
454474
@@ -481,6 +501,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 26 unmodified lines
481501 connect(assetThread, &QThread::started, assetClient.data(), &AssetClient::init);
482502 assetThread->start();
483503
504+ // Setup MessagesClient
505+ auto messagesClient = DependencyManager::get<MessagesClient>();
506+ QThread* messagesThread = new QThread;
507+ messagesThread->setObjectName("Messages Client Thread");
508+ messagesClient->moveToThread(messagesThread);
509+ connect(messagesThread, &QThread::started, messagesClient.data(), &MessagesClient::init);
510+ messagesThread->start();
511+
484512 const DomainHandler& domainHandler = nodeList->getDomainHandler();
485513
486514 connect(&domainHandler, SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&)));
@@ -547,7 +575,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 60 unmodified lines
547575
548576 // tell the NodeList instance who to tell the domain server we care about
549577 nodeList->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer
550− << NodeType::EntityServer << NodeType::AssetServer);
578+ << NodeType::EntityServer << NodeType::AssetServer << NodeType::MessagesMixer);
551579
552580 // connect to the packet sent signal of the _entityEditSender
553581 connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent);
@@ -650,11 +678,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 96 unmodified lines
650678 _applicationStateDevice->addInputVariant(QString("ComfortMode"), controller::StateController::ReadLambda([]() -> float {
651679 return (float)Menu::getInstance()->isOptionChecked(MenuOption::ComfortMode);
652680 }));
681+ _applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float {
682+ return (float)qApp->getMyAvatar()->getCharacterController()->onGround();
683+ }));
653684
654685 userInputMapper->registerDevice(_applicationStateDevice);
655686
656687 // Setup the keyboardMouseDevice and the user input mapper with the default bindings
657− userInputMapper->registerDevice(_keyboardMouseDevice);
688+ userInputMapper->registerDevice(_keyboardMouseDevice->getInputDevice());
658689
659690
660691 userInputMapper->loadDefaultMapping(userInputMapper->getStandardDeviceID());
@@ -730,9 +761,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 69 unmodified lines
730761 // Now that menu is initalized we can sync myAvatar with it's state.
731762 getMyAvatar()->updateMotionBehaviorFromMenu();
732763
764+// FIXME spacemouse code still needs cleanup
733765 #if 0
734766 // the 3Dconnexion device wants to be initiliazed after a window is displayed.
735− ConnexionClient::getInstance().init();
767+ SpacemouseManager::getInstance().init();
736768 #endif
737769
738770 auto& packetReceiver = nodeList->getPacketReceiver();
@@ -804,8 +836,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 65 unmodified lines
804836
805837 void Application::aboutToQuit() {
806838 emit beforeAboutToQuit();
839+
807840 getActiveDisplayPlugin()->deactivate();
841+
808842 _aboutToQuit = true;
843+
809844 cleanupBeforeQuit();
810845 }
811846
@@ -817,7 +852,6 @@ void Application::cleanupBeforeQuit() { · 5 unmodified lines
817852 #ifdef HAVE_IVIEWHMD
818853 DependencyManager::get<EyeTracker>()->setEnabled(false, true);
819854 #endif
820−
821855 AnimDebugDraw::getInstance().shutdown();
822856
823857 // FIXME: once we move to shared pointer for the INputDevice we shoud remove this naked delete:
@@ -831,8 +865,14 @@ void Application::cleanupBeforeQuit() { · 7 unmodified lines
831865
832866 _entities.clear(); // this will allow entity scripts to properly shutdown
833867
868+ auto nodeList = DependencyManager::get<NodeList>();
869+
870+ // send the domain a disconnect packet, force stoppage of domain-server check-ins
871+ nodeList->getDomainHandler().disconnect();
872+ nodeList->setIsShuttingDown(true);
873+
834874 // tell the packet receiver we're shutting down, so it can drop packets
835− DependencyManager::get<NodeList>()->getPacketReceiver().setShouldDropPackets(true);
875+ nodeList->getPacketReceiver().setShouldDropPackets(true);
836876
837877 _entities.shutdown(); // tell the entities system we're shutting down, so it will stop running scripts
838878 ScriptEngine::stopAllScripts(this); // stop all currently running global scripts
@@ -852,9 +892,6 @@ void Application::cleanupBeforeQuit() { · 13 unmodified lines
852892 saveSettings();
853893 _window->saveGeometry();
854894
855− // let the avatar mixer know we're out
856− MyAvatar::sendKillAvatar();
857−
858895 // stop the AudioClient
859896 QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
860897 "stop", Qt::BlockingQueuedConnection);
@@ -944,14 +981,12 @@ void Application::initializeGL() { · 83 unmodified lines
944981 qCDebug(interfaceapp) << "Created Display Window.";
945982
946983 // initialize glut for shape drawing; Qt apparently initializes it on OS X
947− #ifndef __APPLE__
948− static bool isInitialized = false;
949− if (isInitialized) {
984+ if (_isGLInitialized) {
950985 return;
951986 } else {
952− isInitialized = true;
987+ _isGLInitialized = true;
953988 }
954− #endif
989+
955990 // Where the gpuContext is initialized and where the TRUE Backend is created and assigned
956991 gpu::Context::init<gpu::GLBackend>();
957992 _gpuContext = std::make_shared<gpu::Context>();
@@ -978,10 +1013,6 @@ void Application::initializeGL() { · 20 unmodified lines
9781013 connect(&_octreeProcessor, &OctreePacketProcessor::packetVersionMismatch, this, &Application::notifyPacketVersionMismatch);
9791014 _entityEditSender.initialize(_enableProcessOctreeThread);
9801015
981− // call our timer function every second
982− connect(&pingTimer, &QTimer::timeout, this, &Application::ping);
983− pingTimer.start(1000);
984−
9851016 _idleLoopStdev.reset();
9861017
9871018 // update before the first render
@@ -992,6 +1023,7 @@ void Application::initializeGL() { · 4 unmodified lines
9921023
9931024 void Application::initializeUi() {
9941025 AddressBarDialog::registerType();
1026+ RecorderDialog::registerType();
9951027 ErrorDialog::registerType();
9961028 LoginDialog::registerType();
9971029 MessageDialog::registerType();
@@ -1007,6 +1039,7 @@ void Application::initializeUi() { · 9 unmodified lines
10071039 offscreenUi->load("RootMenu.qml");
10081040 auto scriptingInterface = DependencyManager::get<controller::ScriptingInterface>();
10091041 offscreenUi->getRootContext()->setContextProperty("Controller", scriptingInterface.data());
1042+ offscreenUi->getRootContext()->setContextProperty("MyAvatar", getMyAvatar());
10101043 _glWidget->installEventFilter(offscreenUi.data());
10111044 VrMenu::load();
10121045 VrMenu::executeQueuedLambdas();
@@ -1035,10 +1068,7 @@ void Application::initializeUi() { · 22 unmodified lines
10351068 foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) {
10361069 QString name = inputPlugin->getName();
10371070 if (name == KeyboardMouseDevice::NAME) {
1038− auto kbm = static_cast<KeyboardMouseDevice*>(inputPlugin.data());
1039− // FIXME incredibly evil.... _keyboardMouseDevice is now owned by
1040− // both a QSharedPointer and a std::shared_ptr
1041− _keyboardMouseDevice = std::shared_ptr<KeyboardMouseDevice>(kbm);
1071+ _keyboardMouseDevice = std::dynamic_pointer_cast<KeyboardMouseDevice>(inputPlugin);
10421072 }
10431073 }
10441074 updateInputModes();
@@ -1063,7 +1093,9 @@ void Application::paintGL() { · 18 unmodified lines
10631093 _lastFramesPerSecondUpdate = now;
10641094 }
10651095
1066− idle(now);
1096+ if (_isGLInitialized) {
1097+ idle(now);
1098+ }
10671099
10681100 PROFILE_RANGE(__FUNCTION__);
10691101 PerformanceTimer perfTimer("paintGL");
@@ -1204,6 +1236,19 @@ void Application::paintGL() { · 134 unmodified lines
12041236 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
12051237 }
12061238 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
1239+ } else if (_myCamera.getMode() == CAMERA_MODE_ENTITY) {
1240+ EntityItemPointer cameraEntity = _myCamera.getCameraEntityPointer();
1241+ if (cameraEntity != nullptr) {
1242+ if (isHMDMode()) {
1243+ glm::quat hmdRotation = extractRotation(myAvatar->getHMDSensorMatrix());
1244+ _myCamera.setRotation(cameraEntity->getRotation() * hmdRotation);
1245+ glm::vec3 hmdOffset = extractTranslation(myAvatar->getHMDSensorMatrix());
1246+ _myCamera.setPosition(cameraEntity->getPosition() + (hmdRotation * hmdOffset));
1247+ } else {
1248+ _myCamera.setRotation(cameraEntity->getRotation());
1249+ _myCamera.setPosition(cameraEntity->getPosition());
1250+ }
1251+ }
12071252 }
12081253 // Update camera position
12091254 if (!isHMDMode()) {
@@ -1577,8 +1622,9 @@ void Application::keyPressEvent(QKeyEvent* event) { · 367 unmodified lines
15771622
15781623 case Qt::Key_X:
15791624 if (isMeta && isShifted) {
1580− auto offscreenUi = DependencyManager::get<OffscreenUi>();
1581− offscreenUi->load("TestControllers.qml");
1625+// auto offscreenUi = DependencyManager::get<OffscreenUi>();
1626+// offscreenUi->load("TestControllers.qml");
1627+ RecorderDialog::toggle();
15821628 }
15831629 break;
15841630
@@ -1855,8 +1901,12 @@ void Application::focusOutEvent(QFocusEvent* event) { · 270 unmodified lines
18551901 inputPlugin->pluginFocusOutEvent();
18561902 }
18571903 }
1904+
1905+// FIXME spacemouse code still needs cleanup
18581906 #if 0
1859− ConnexionData::getInstance().focusOutEvent();
1907+ //SpacemouseDevice::getInstance().focusOutEvent();
1908+ //SpacemouseManager::getInstance().getDevice()->focusOutEvent();
1909+ SpacemouseManager::getInstance().ManagerFocusOutEvent();
18601910 #endif
18611911
18621912 // synthesize events for keys currently pressed, since we may not get their release events
@@ -2103,13 +2153,6 @@ bool Application::acceptSnapshot(const QString& urlString) { · 240 unmodified lines
21032153 return true;
21042154 }
21052155
2106−// Every second, send a ping, if menu item is checked.
2107−void Application::ping() {
2108− if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) {
2109− DependencyManager::get<NodeList>()->sendPingPackets();
2110− }
2111−}
2112−
21132156 void Application::idle(uint64_t now) {
21142157 if (_aboutToQuit) {
21152158 return; // bail early, nothing to do here.
@@ -2649,8 +2692,8 @@ void Application::cycleCamera() { · 533 unmodified lines
26492692 menu->setIsOptionChecked(MenuOption::ThirdPerson, false);
26502693 menu->setIsOptionChecked(MenuOption::FullscreenMirror, true);
26512694
2652− } else if (menu->isOptionChecked(MenuOption::IndependentMode)) {
2653− // do nothing if in independe mode
2695+ } else if (menu->isOptionChecked(MenuOption::IndependentMode) || menu->isOptionChecked(MenuOption::CameraEntityMode)) {
2696+ // do nothing if in independent or camera entity modes
26542697 return;
26552698 }
26562699 cameraMenuChanged(); // handle the menu change
@@ -2677,6 +2720,10 @@ void Application::cameraMenuChanged() { · 20 unmodified lines
26772720 if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
26782721 _myCamera.setMode(CAMERA_MODE_INDEPENDENT);
26792722 }
2723+ } else if (Menu::getInstance()->isOptionChecked(MenuOption::CameraEntityMode)) {
2724+ if (_myCamera.getMode() != CAMERA_MODE_ENTITY) {
2725+ _myCamera.setMode(CAMERA_MODE_ENTITY);
2726+ }
26802727 }
26812728 }
26822729
@@ -2799,7 +2846,7 @@ void Application::update(float deltaTime) { · 116 unmodified lines
27992846 float timeFactor = EXPECTED_FRAME_RATE * deltaTime;
28002847 myAvatar->setDriveKeys(PITCH, -1.0f * userInputMapper->getActionState(controller::Action::PITCH) / timeFactor);
28012848 myAvatar->setDriveKeys(YAW, -1.0f * userInputMapper->getActionState(controller::Action::YAW) / timeFactor);
2802− myAvatar->setDriveKeys(STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW) / timeFactor);
2849+ myAvatar->setDriveKeys(STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW));
28032850 }
28042851 }
28052852 myAvatar->setDriveKeys(ZOOM, userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z));
@@ -3498,10 +3545,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 692 unmodified lines
34983545 if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowHulls)) {
34993546 renderDebugFlags = (RenderArgs::DebugFlags) (renderDebugFlags | (int)RenderArgs::RENDER_DEBUG_HULLS);
35003547 }
3501− if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned)) {
3502− renderDebugFlags =
3503− (RenderArgs::DebugFlags) (renderDebugFlags | (int)RenderArgs::RENDER_DEBUG_SIMULATION_OWNERSHIP);
3504− }
35053548 renderArgs->_debugFlags = renderDebugFlags;
35063549 //ViveControllerManager::getInstance().updateRendering(renderArgs, _main3DScene, pendingChanges);
35073550 }
@@ -3561,6 +3604,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 53 unmodified lines
35613604 renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems();
35623605
35633606 renderContext._drawItemStatus = sceneInterface->doEngineDisplayItemStatus();
3607+ if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned)) {
3608+ renderContext._drawItemStatus |= render::showNetworkStatusFlag;
3609+ }
35643610 renderContext._drawHitEffect = sceneInterface->doEngineDisplayHitEffect();
35653611
35663612 renderContext._occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion);
@@ -4650,7 +4696,7 @@ DisplayPlugin* Application::getActiveDisplayPlugin() { · 1083 unmodified lines
46504696 updateDisplayMode();
46514697 Q_ASSERT(_displayPlugin);
46524698 }
4653− return _displayPlugin.data();
4699+ return _displayPlugin.get();
46544700 }
46554701
46564702 const DisplayPlugin* Application::getActiveDisplayPlugin() const {
@@ -4690,10 +4736,10 @@ void Application::updateDisplayMode() { · 33 unmodified lines
46904736 bool first = true;
46914737 foreach(auto displayPlugin, displayPlugins) {
46924738 addDisplayPluginToMenu(displayPlugin, first);
4693− QObject::connect(displayPlugin.data(), &DisplayPlugin::requestRender, [this] {
4739+ QObject::connect(displayPlugin.get(), &DisplayPlugin::requestRender, [this] {
46944740 paintGL();
46954741 });
4696− QObject::connect(displayPlugin.data(), &DisplayPlugin::recommendedFramebufferSizeChanged, [this](const QSize & size) {
4742+ QObject::connect(displayPlugin.get(), &DisplayPlugin::recommendedFramebufferSizeChanged, [this](const QSize & size) {
46974743 resizeGL();
46984744 });
46994745
@@ -4819,12 +4865,14 @@ void Application::updateInputModes() { · 119 unmodified lines
48194865 foreach(auto inputPlugin, inputPlugins) {
48204866 QString name = inputPlugin->getName();
48214867 QAction* action = menu->getActionForOption(name);
4822− if (action->isChecked() && !_activeInputPlugins.contains(inputPlugin)) {
4823− _activeInputPlugins.append(inputPlugin);
4824− newInputPlugins.append(inputPlugin);
4825− } else if (!action->isChecked() && _activeInputPlugins.contains(inputPlugin)) {
4826− _activeInputPlugins.removeOne(inputPlugin);
4827− removedInputPlugins.append(inputPlugin);
4868+
4869+ auto it = std::find(std::begin(_activeInputPlugins), std::end(_activeInputPlugins), inputPlugin);
4870+ if (action->isChecked() && it == std::end(_activeInputPlugins)) {
4871+ _activeInputPlugins.push_back(inputPlugin);
4872+ newInputPlugins.push_back(inputPlugin);
4873+ } else if (!action->isChecked() && it != std::end(_activeInputPlugins)) {
4874+ _activeInputPlugins.erase(it);
4875+ removedInputPlugins.push_back(inputPlugin);
48284876 }
48294877 }
48304878