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
896 896
897 glEnable(GL_LINE_SMOOTH);897 glEnable(GL_LINE_SMOOTH);
898 898
899 Menu::getInstance()->setIsOptionChecked("First Person", _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);899 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
900 Application::getInstance()->cameraMenuChanged();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 }
901 904
902 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {905 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
903 // Always use the default eye position, not the actual head eye position.906 // Always use the default eye position, not the actual head eye position.
@@ -1014,7 +1017,7 @@ void Application::paintGL() { · 110 unmodified lines
1014 glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));1017 glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));
1015 glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y,1018 glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y,
1016 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(),1019 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(),
1017 GL_COLOR_BUFFER_BIT, GL_NEAREST);1020 GL_COLOR_BUFFER_BIT, GL_LINEAR);
1018 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);1021 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1019 1022
1020 _compositor.displayOverlayTexture(&renderArgs);1023 _compositor.displayOverlayTexture(&renderArgs);
@@ -1401,11 +1404,17 @@ void Application::keyPressEvent(QKeyEvent* event) { · 380 unmodified lines
1401 if (isShifted) {1404 if (isShifted) {
1402 Menu::getInstance()->triggerOption(MenuOption::Mirror);1405 Menu::getInstance()->triggerOption(MenuOption::Mirror);
1403 } else {1406 } 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();
1405 }1412 }
1406 break;1413 break;
1407 case Qt::Key_P:1414 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();
1409 break;1418 break;
1410 case Qt::Key_Slash:1419 case Qt::Key_Slash:
1411 Menu::getInstance()->triggerOption(MenuOption::Stats);1420 Menu::getInstance()->triggerOption(MenuOption::Stats);
@@ -2358,13 +2367,17 @@ void Application::cameraMenuChanged() { · 946 unmodified lines
2358 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);2367 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
2359 _myAvatar->setBoomLength(MyAvatar::ZOOM_MIN);2368 _myAvatar->setBoomLength(MyAvatar::ZOOM_MIN);
2360 }2369 }
2361 } else {2370 } else if (Menu::getInstance()->isOptionChecked(MenuOption::ThirdPerson)) {
2362 if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) {2371 if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) {
2363 _myCamera.setMode(CAMERA_MODE_THIRD_PERSON);2372 _myCamera.setMode(CAMERA_MODE_THIRD_PERSON);
2364 if (_myAvatar->getBoomLength() == MyAvatar::ZOOM_MIN) {2373 if (_myAvatar->getBoomLength() == MyAvatar::ZOOM_MIN) {
2365 _myAvatar->setBoomLength(MyAvatar::ZOOM_DEFAULT);2374 _myAvatar->setBoomLength(MyAvatar::ZOOM_DEFAULT);
2366 }2375 }
2367 }2376 }
2377 } else if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) {
2378 if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
2379 _myCamera.setMode(CAMERA_MODE_INDEPENDENT);
2380 }
2368 }2381 }
2369}2382}
2370 2383
@@ -2458,18 +2471,22 @@ void Application::update(float deltaTime) { · 87 unmodified lines
2458 2471
2459 // Transfer the user inputs to the driveKeys2472 // Transfer the user inputs to the driveKeys
2460 _myAvatar->clearDriveKeys();2473 _myAvatar->clearDriveKeys();
2461 _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));2474 if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
2462 _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));2475 if (!_controllerScriptingInterface.areActionsCaptured()) {
2463 _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));2476 _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));
2464 _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));2477 _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));
2465 _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));2478 _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));
2466 _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));2479 _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
2467 _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));2480 _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
2468 _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));2481 _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));
2469 _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));2482 _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));
2470 _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));2483 _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));
2471 _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));2484 _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));
2472 _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));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 }
2473 2490
2474 updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...2491 updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...
2475 2492
@@ -2486,24 +2503,45 @@ void Application::update(float deltaTime) { · 10 unmodified lines
2486 2503
2487 _entitySimulation.lock();2504 _entitySimulation.lock();
2488 _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete());2505 _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete());
2506 _entitySimulation.unlock();
2507
2508 _entities.getTree()->lockForWrite();
2509 _entitySimulation.lock();
2489 _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd());2510 _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd());
2511 _entitySimulation.unlock();
2512 _entities.getTree()->unlock();
2513
2514 _entities.getTree()->lockForWrite();
2515 _entitySimulation.lock();
2490 _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange());2516 _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange());
2517 _entitySimulation.unlock();
2518 _entities.getTree()->unlock();
2519
2520 _entitySimulation.lock();
2491 _entitySimulation.applyActionChanges();2521 _entitySimulation.applyActionChanges();
2492 _entitySimulation.unlock();2522 _entitySimulation.unlock();
2493 2523
2524
2494 AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();2525 AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();
2495 _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete());2526 _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete());
2496 _physicsEngine.addObjects(avatarManager->getObjectsToAdd());2527 _physicsEngine.addObjects(avatarManager->getObjectsToAdd());
2497 _physicsEngine.changeObjects(avatarManager->getObjectsToChange());2528 _physicsEngine.changeObjects(avatarManager->getObjectsToChange());
2498 2529
2530 _entities.getTree()->lockForWrite();
2499 _physicsEngine.stepSimulation();2531 _physicsEngine.stepSimulation();
2532 _entities.getTree()->unlock();
2500 2533
2501 if (_physicsEngine.hasOutgoingChanges()) {2534 if (_physicsEngine.hasOutgoingChanges()) {
2535 _entities.getTree()->lockForWrite();
2502 _entitySimulation.lock();2536 _entitySimulation.lock();
2503 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());2537 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());
2504 _entitySimulation.unlock();2538 _entitySimulation.unlock();
2539 _entities.getTree()->unlock();
2505 2540
2541 _entities.getTree()->lockForWrite();
2506 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());2542 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());
2543 _entities.getTree()->unlock();
2544
2507 auto collisionEvents = _physicsEngine.getCollisionEvents();2545 auto collisionEvents = _physicsEngine.getCollisionEvents();
2508 avatarManager->handleCollisionEvents(collisionEvents);2546 avatarManager->handleCollisionEvents(collisionEvents);
2509 2547
@@ -3280,6 +3318,11 @@ namespace render { · 770 unmodified lines
3280}3318}
3281 3319
3282void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool selfAvatarOnly, bool billboard) {3320void 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
3283 activeRenderingThread = QThread::currentThread();3326 activeRenderingThread = QThread::currentThread();
3284 PROFILE_RANGE(__FUNCTION__);3327 PROFILE_RANGE(__FUNCTION__);
3285 PerformanceTimer perfTimer("display");3328 PerformanceTimer perfTimer("display");
@@ -3934,6 +3977,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 648 unmodified lines
3934 connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));3977 connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));
3935 3978
3936 connect(scriptEngine, SIGNAL(loadScript(const QString&, bool)), this, SLOT(loadScript(const QString&, bool)));3979 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)));
3937 3981
3938 scriptEngine->registerGlobalObject("Overlays", &_overlays);3982 scriptEngine->registerGlobalObject("Overlays", &_overlays);
3939 qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);3983 qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);
@@ -4149,7 +4193,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 209 unmodified lines
4149}4193}
4150 4194
4151ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,4195ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
4152 bool loadScriptFromEditor, bool activateMainWindow) {4196 bool loadScriptFromEditor, bool activateMainWindow, bool reload) {
4153 4197
4154 if (isAboutToQuit()) {4198 if (isAboutToQuit()) {
4155 return NULL;4199 return NULL;
@@ -4178,7 +4222,7 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 22 unmodified lines
4178 connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &Application::handleScriptLoadError);4222 connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &Application::handleScriptLoadError);
4179 4223
4180 // get the script engine object to load the script at the designated script URL4224 // get the script engine object to load the script at the designated script URL
4181 scriptEngine->loadURL(scriptUrl);4225 scriptEngine->loadURL(scriptUrl, reload);
4182 }4226 }
4183 4227
4184 // restore the main window's active state4228 // restore the main window's active state
@@ -4189,6 +4233,10 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 4 unmodified lines
4189 return scriptEngine;4233 return scriptEngine;
4190}4234}
4191 4235
4236void Application::reloadScript(const QString& scriptName, bool isUserLoaded) {
4237 loadScript(scriptName, isUserLoaded, false, false, true);
4238}
4239
4192void Application::handleScriptEngineLoaded(const QString& scriptFilename) {4240void Application::handleScriptEngineLoaded(const QString& scriptFilename) {
4193 ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());4241 ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
4194 4242
@@ -4216,14 +4264,25 @@ void Application::scriptFinished(const QString& scriptName) { · 21 unmodified lines
4216}4264}
4217 4265
4218void Application::stopAllScripts(bool restart) {4266void Application::stopAllScripts(bool restart) {
4219 // stops all current running scripts4267 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
4220 for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();4279 for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
4221 it != _scriptEnginesHash.constEnd(); it++) {4280 it != _scriptEnginesHash.constEnd(); it++) {
4222 if (it.value()->isFinished()) {4281 if (it.value()->isFinished()) {
4223 continue;4282 continue;
4224 }4283 }
4225 if (restart && it.value()->isUserLoaded()) {4284 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&)));
4227 }4286 }
4228 it.value()->stop();4287 it.value()->stop();
4229 qCDebug(interfaceapp) << "stopping script..." << it.key();4288 qCDebug(interfaceapp) << "stopping script..." << it.key();
@@ -4231,13 +4290,20 @@ void Application::stopAllScripts(bool restart) { · 1 unmodified line
4231 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities4290 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
4232 // whenever a script stops in case it happened to have been setting joint rotations.4291 // whenever a script stops in case it happened to have been setting joint rotations.
4233 // TODO: expose animation priorities and provide a layered animation control system.4292 // TODO: expose animation priorities and provide a layered animation control system.
4293 _myAvatar->clearJointAnimationPriorities();
4234 _myAvatar->clearScriptableSettings();4294 _myAvatar->clearScriptableSettings();
4235}4295}
4236 4296
4237void Application::stopScript(const QString &scriptName) {4297void Application::stopScript(const QString &scriptName, bool restart) {
4238 const QString& scriptURLString = QUrl(scriptName).toString();4298 const QString& scriptURLString = QUrl(scriptName).toString();
4239 if (_scriptEnginesHash.contains(scriptURLString)) {4299 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();
4241 qCDebug(interfaceapp) << "stopping script..." << scriptName;4307 qCDebug(interfaceapp) << "stopping script..." << scriptName;
4242 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities4308 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
4243 // whenever a script stops in case it happened to have been setting joint rotations.4309 // whenever a script stops in case it happened to have been setting joint rotations.
@@ -4253,6 +4319,10 @@ void Application::reloadAllScripts() { · 9 unmodified lines
4253 stopAllScripts(true);4319 stopAllScripts(true);
4254}4320}
4255 4321
4322void Application::reloadOneScript(const QString& scriptName) {
4323 stopScript(scriptName, true);
4324}
4325
4256void Application::loadDefaultScripts() {4326void Application::loadDefaultScripts() {
4257 if (!_scriptEnginesHash.contains(DEFAULT_SCRIPTS_JS_URL)) {4327 if (!_scriptEnginesHash.contains(DEFAULT_SCRIPTS_JS_URL)) {
4258 loadScript(DEFAULT_SCRIPTS_JS_URL);4328 loadScript(DEFAULT_SCRIPTS_JS_URL);