History

Merge remote-tracking branch 'upstream/master' into plugins

Brad Davis committed 11 years ago

Commit 4417c002 parents a5428ae 8a6ab68128 files · +3167 −2493Browse files

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

Unified · Split

interface/src/Application.cpp+94−24
@@ -896,8 +896,11 @@ void Application::paintGL() { · 895 unmodified lines
896896
897897 glEnable(GL_LINE_SMOOTH);
898898
899− Menu::getInstance()->setIsOptionChecked("First Person", _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
900− Application::getInstance()->cameraMenuChanged();
899+ if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
900+ Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
901+ Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN));
902+ Application::getInstance()->cameraMenuChanged();
903+ }
901904
902905 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
903906 // Always use the default eye position, not the actual head eye position.
@@ -1014,7 +1017,7 @@ void Application::paintGL() { · 110 unmodified lines
10141017 glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));
10151018 glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y,
10161019 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(),
1017− GL_COLOR_BUFFER_BIT, GL_NEAREST);
1020+ GL_COLOR_BUFFER_BIT, GL_LINEAR);
10181021 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
10191022
10201023 _compositor.displayOverlayTexture(&renderArgs);
@@ -1401,11 +1404,17 @@ void Application::keyPressEvent(QKeyEvent* event) { · 380 unmodified lines
14011404 if (isShifted) {
14021405 Menu::getInstance()->triggerOption(MenuOption::Mirror);
14031406 } else {
1404− Menu::getInstance()->triggerOption(MenuOption::FullscreenMirror);
1407+ Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror));
1408+ if (!Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1409+ Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true);
1410+ }
1411+ cameraMenuChanged();
14051412 }
14061413 break;
14071414 case Qt::Key_P:
1408− Menu::getInstance()->triggerOption(MenuOption::FirstPerson);
1415+ Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, !Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson));
1416+ Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson));
1417+ cameraMenuChanged();
14091418 break;
14101419 case Qt::Key_Slash:
14111420 Menu::getInstance()->triggerOption(MenuOption::Stats);
@@ -2358,13 +2367,17 @@ void Application::cameraMenuChanged() { · 946 unmodified lines
23582367 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
23592368 _myAvatar->setBoomLength(MyAvatar::ZOOM_MIN);
23602369 }
2361− } else {
2370+ } else if (Menu::getInstance()->isOptionChecked(MenuOption::ThirdPerson)) {
23622371 if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) {
23632372 _myCamera.setMode(CAMERA_MODE_THIRD_PERSON);
23642373 if (_myAvatar->getBoomLength() == MyAvatar::ZOOM_MIN) {
23652374 _myAvatar->setBoomLength(MyAvatar::ZOOM_DEFAULT);
23662375 }
23672376 }
2377+ } else if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) {
2378+ if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
2379+ _myCamera.setMode(CAMERA_MODE_INDEPENDENT);
2380+ }
23682381 }
23692382 }
23702383
@@ -2458,18 +2471,22 @@ void Application::update(float deltaTime) { · 87 unmodified lines
24582471
24592472 // Transfer the user inputs to the driveKeys
24602473 _myAvatar->clearDriveKeys();
2461− _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));
2462− _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));
2463− _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));
2464− _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
2465− _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
2466− _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));
2467− _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));
2468− _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));
2469− _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));
2470− _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));
2471− _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));
2472− _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));
2474+ if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
2475+ if (!_controllerScriptingInterface.areActionsCaptured()) {
2476+ _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));
2477+ _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));
2478+ _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));
2479+ _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
2480+ _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
2481+ _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));
2482+ _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));
2483+ _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));
2484+ _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));
2485+ _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));
2486+ }
2487+ _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));
2488+ _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));
2489+ }
24732490
24742491 updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...
24752492
@@ -2486,24 +2503,45 @@ void Application::update(float deltaTime) { · 10 unmodified lines
24862503
24872504 _entitySimulation.lock();
24882505 _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete());
2506+ _entitySimulation.unlock();
2507+
2508+ _entities.getTree()->lockForWrite();
2509+ _entitySimulation.lock();
24892510 _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd());
2511+ _entitySimulation.unlock();
2512+ _entities.getTree()->unlock();
2513+
2514+ _entities.getTree()->lockForWrite();
2515+ _entitySimulation.lock();
24902516 _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange());
2517+ _entitySimulation.unlock();
2518+ _entities.getTree()->unlock();
2519+
2520+ _entitySimulation.lock();
24912521 _entitySimulation.applyActionChanges();
24922522 _entitySimulation.unlock();
24932523
2524+
24942525 AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();
24952526 _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete());
24962527 _physicsEngine.addObjects(avatarManager->getObjectsToAdd());
24972528 _physicsEngine.changeObjects(avatarManager->getObjectsToChange());
24982529
2530+ _entities.getTree()->lockForWrite();
24992531 _physicsEngine.stepSimulation();
2532+ _entities.getTree()->unlock();
25002533
25012534 if (_physicsEngine.hasOutgoingChanges()) {
2535+ _entities.getTree()->lockForWrite();
25022536 _entitySimulation.lock();
25032537 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());
25042538 _entitySimulation.unlock();
2539+ _entities.getTree()->unlock();
25052540
2541+ _entities.getTree()->lockForWrite();
25062542 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());
2543+ _entities.getTree()->unlock();
2544+
25072545 auto collisionEvents = _physicsEngine.getCollisionEvents();
25082546 avatarManager->handleCollisionEvents(collisionEvents);
25092547
@@ -3280,6 +3318,11 @@ namespace render { · 770 unmodified lines
32803318 }
32813319
32823320 void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool selfAvatarOnly, bool billboard) {
3321+
3322+ // FIXME: This preRender call is temporary until we create a separate render::scene for the mirror rendering.
3323+ // Then we can move this logic into the Avatar::simulate call.
3324+ _myAvatar->preRender(renderArgs);
3325+
32833326 activeRenderingThread = QThread::currentThread();
32843327 PROFILE_RANGE(__FUNCTION__);
32853328 PerformanceTimer perfTimer("display");
@@ -3934,6 +3977,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 648 unmodified lines
39343977 connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));
39353978
39363979 connect(scriptEngine, SIGNAL(loadScript(const QString&, bool)), this, SLOT(loadScript(const QString&, bool)));
3980+ connect(scriptEngine, SIGNAL(reloadScript(const QString&, bool)), this, SLOT(reloadScript(const QString&, bool)));
39373981
39383982 scriptEngine->registerGlobalObject("Overlays", &_overlays);
39393983 qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);
@@ -4149,7 +4193,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 209 unmodified lines
41494193 }
41504194
41514195 ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
4152− bool loadScriptFromEditor, bool activateMainWindow) {
4196+ bool loadScriptFromEditor, bool activateMainWindow, bool reload) {
41534197
41544198 if (isAboutToQuit()) {
41554199 return NULL;
@@ -4178,7 +4222,7 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 22 unmodified lines
41784222 connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &Application::handleScriptLoadError);
41794223
41804224 // get the script engine object to load the script at the designated script URL
4181− scriptEngine->loadURL(scriptUrl);
4225+ scriptEngine->loadURL(scriptUrl, reload);
41824226 }
41834227
41844228 // restore the main window's active state
@@ -4189,6 +4233,10 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 4 unmodified lines
41894233 return scriptEngine;
41904234 }
41914235
4236+void Application::reloadScript(const QString& scriptName, bool isUserLoaded) {
4237+ loadScript(scriptName, isUserLoaded, false, false, true);
4238+}
4239+
41924240 void Application::handleScriptEngineLoaded(const QString& scriptFilename) {
41934241 ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
41944242
@@ -4216,14 +4264,25 @@ void Application::scriptFinished(const QString& scriptName) { · 21 unmodified lines
42164264 }
42174265
42184266 void Application::stopAllScripts(bool restart) {
4219− // stops all current running scripts
4267+ if (restart) {
4268+ // Delete all running scripts from cache so that they are re-downloaded when they are restarted
4269+ auto scriptCache = DependencyManager::get<ScriptCache>();
4270+ for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
4271+ it != _scriptEnginesHash.constEnd(); it++) {
4272+ if (!it.value()->isFinished()) {
4273+ scriptCache->deleteScript(it.key());
4274+ }
4275+ }
4276+ }
4277+
4278+ // Stop and possibly restart all currently running scripts
42204279 for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
42214280 it != _scriptEnginesHash.constEnd(); it++) {
42224281 if (it.value()->isFinished()) {
42234282 continue;
42244283 }
42254284 if (restart && it.value()->isUserLoaded()) {
4226− connect(it.value(), SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&)));
4285+ connect(it.value(), SIGNAL(finished(const QString&)), SLOT(reloadScript(const QString&)));
42274286 }
42284287 it.value()->stop();
42294288 qCDebug(interfaceapp) << "stopping script..." << it.key();
@@ -4231,13 +4290,20 @@ void Application::stopAllScripts(bool restart) { · 1 unmodified line
42314290 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
42324291 // whenever a script stops in case it happened to have been setting joint rotations.
42334292 // TODO: expose animation priorities and provide a layered animation control system.
4293+ _myAvatar->clearJointAnimationPriorities();
42344294 _myAvatar->clearScriptableSettings();
42354295 }
42364296
4237−void Application::stopScript(const QString &scriptName) {
4297+void Application::stopScript(const QString &scriptName, bool restart) {
42384298 const QString& scriptURLString = QUrl(scriptName).toString();
42394299 if (_scriptEnginesHash.contains(scriptURLString)) {
4240− _scriptEnginesHash.value(scriptURLString)->stop();
4300+ ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURLString];
4301+ if (restart) {
4302+ auto scriptCache = DependencyManager::get<ScriptCache>();
4303+ scriptCache->deleteScript(scriptName);
4304+ connect(scriptEngine, SIGNAL(finished(const QString&)), SLOT(reloadScript(const QString&)));
4305+ }
4306+ scriptEngine->stop();
42414307 qCDebug(interfaceapp) << "stopping script..." << scriptName;
42424308 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
42434309 // whenever a script stops in case it happened to have been setting joint rotations.
@@ -4253,6 +4319,10 @@ void Application::reloadAllScripts() { · 9 unmodified lines
42534319 stopAllScripts(true);
42544320 }
42554321
4322+void Application::reloadOneScript(const QString& scriptName) {
4323+ stopScript(scriptName, true);
4324+}
4325+
42564326 void Application::loadDefaultScripts() {
42574327 if (!_scriptEnginesHash.contains(DEFAULT_SCRIPTS_JS_URL)) {
42584328 loadScript(DEFAULT_SCRIPTS_JS_URL);