History

Merge branch 'master' of https://github.com/worklist/hifi into 20224

Thijs Wenker committed 11 years ago

Commit e3ca1ef2 parents d270979 d3b387c168 files · +100204 −1348Browse files

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

Unified · Split

interface/src/Application.cpp+88−76
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 // include this before QGLWidget, which includes an earlier version of OpenGL
2424 #include "InterfaceConfig.h"
2525
26+#include <QAbstractNativeEventFilter>
2627 #include <QActionGroup>
2728 #include <QColorDialog>
2829 #include <QDesktopWidget>
@@ -73,6 +74,7 @@ · 44 unmodified lines
7374 #include <PhysicsEngine.h>
7475 #include <ProgramObject.h>
7576 #include <ResourceCache.h>
77+#include <ScriptCache.h>
7678 #include <SettingHandle.h>
7779 #include <SoundCache.h>
7880 #include <TextRenderer.h>
@@ -80,13 +82,15 @@ · 1 unmodified line
8082 #include <UUID.h>
8183
8284 #include "Application.h"
83−#include "Audio.h"
85+#include "AudioClient.h"
8486 #include "InterfaceVersion.h"
8587 #include "LODManager.h"
8688 #include "Menu.h"
8789 #include "ModelUploader.h"
8890 #include "Util.h"
8991
92+#include "avatar/AvatarManager.h"
93+
9094 #include "audio/AudioToolBox.h"
9195 #include "audio/AudioIOStatsRenderer.h"
9296 #include "audio/AudioScope.h"
@@ -127,17 +131,12 @@ · 34 unmodified lines
127131 #include "ui/StandAloneJSConsole.h"
128132 #include "ui/Stats.h"
129133
130−
131−
132134 using namespace std;
133135
134136 // Starfield information
135137 static unsigned STARFIELD_NUM_STARS = 50000;
136138 static unsigned STARFIELD_SEED = 1;
137139
138−static const int BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH = 6; // farther dragged clicks are ignored
139−
140−
141140 const qint64 MAXIMUM_CACHE_SIZE = 10737418240; // 10GB
142141
143142 static QTimer* idleTimer = NULL;
@@ -147,6 +146,37 @@ const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::D · 3 unmodified lines
147146
148147 const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js";
149148
149+#ifdef Q_OS_WIN
150+class MyNativeEventFilter : public QAbstractNativeEventFilter {
151+public:
152+ static MyNativeEventFilter& getInstance() {
153+ static MyNativeEventFilter staticInstance;
154+ return staticInstance;
155+ }
156+
157+ bool nativeEventFilter(const QByteArray &eventType, void* msg, long* result) Q_DECL_OVERRIDE {
158+ if (eventType == "windows_generic_MSG") {
159+ MSG* message = (MSG*)msg;
160+ if (message->message == UWM_IDENTIFY_INSTANCES) {
161+ *result = UWM_IDENTIFY_INSTANCES;
162+ return true;
163+ }
164+ if (message->message == WM_SHOWWINDOW) {
165+ Application::getInstance()->getWindow()->showNormal();
166+ }
167+ if (message->message == WM_COPYDATA) {
168+ COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam);
169+ QUrl url = QUrl((const char*)(pcds->lpData));
170+ if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) {
171+ DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
172+ }
173+ }
174+ }
175+ return false;
176+ }
177+};
178+#endif
179+
150180 void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
151181 QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message);
152182
@@ -166,6 +196,7 @@ bool setupEssentials(int& argc, char** argv) { · 13 unmodified lines
166196 QCoreApplication::setApplicationVersion(BUILD_VERSION);
167197
168198 DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
199+ DependencyManager::registerInheritance<AvatarHashMap, AvatarManager>();
169200
170201 // Set dependencies
171202 auto glCanvas = DependencyManager::set<GLCanvas>();
@@ -174,7 +205,7 @@ bool setupEssentials(int& argc, char** argv) { · 2 unmodified lines
174205 auto geometryCache = DependencyManager::set<GeometryCache>();
175206 auto glowEffect = DependencyManager::set<GlowEffect>();
176207 auto faceshift = DependencyManager::set<Faceshift>();
177− auto audio = DependencyManager::set<Audio>();
208+ auto audio = DependencyManager::set<AudioClient>();
178209 auto audioScope = DependencyManager::set<AudioScope>();
179210 auto audioIOStatsRenderer = DependencyManager::set<AudioIOStatsRenderer>();
180211 auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>();
@@ -185,10 +216,12 @@ bool setupEssentials(int& argc, char** argv) { · 4 unmodified lines
185216 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();
186217 auto modelBlender = DependencyManager::set<ModelBlender>();
187218 auto audioToolBox = DependencyManager::set<AudioToolBox>();
219+ auto avatarManager = DependencyManager::set<AvatarManager>();
188220 auto lodManager = DependencyManager::set<LODManager>();
189221 auto jsConsole = DependencyManager::set<StandAloneJSConsole>();
190222 auto dialogsManager = DependencyManager::set<DialogsManager>();
191223 auto bandwidthRecorder = DependencyManager::set<BandwidthRecorder>();
224+ auto resouceCacheSharedItems = DependencyManager::set<ResouceCacheSharedItems>();
192225 #if defined(Q_OS_MAC) || defined(Q_OS_WIN)
193226 auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
194227 #endif
@@ -224,6 +257,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 29 unmodified lines
224257 _scaleMirror(1.0f),
225258 _rotateMirror(0.0f),
226259 _raiseMirror(0.0f),
260+ _cursorVisible(true),
227261 _lastMouseMove(usecTimestampNow()),
228262 _lastMouseMoveWasSimulated(false),
229263 _touchAvgX(0.0f),
@@ -243,9 +277,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 13 unmodified lines
243277 _aboutToQuit(false),
244278 _notifiedPacketVersionMismatchThisDomain(false)
245279 {
280+#ifdef Q_OS_WIN
281+ installNativeEventFilter(&MyNativeEventFilter::getInstance());
282+#endif
283+
246284 _logger = new FileLogger(this); // After setting organization name in order to get correct directory
247285 qInstallMessageHandler(messageHandler);
248−
286+
249287 QFontDatabase::addApplicationFont(PathUtils::resourcesPath() + "styles/Inconsolata.otf");
250288 _window->setWindowTitle("Interface");
251289
@@ -254,7 +292,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 2 unmodified lines
254292 auto glCanvas = DependencyManager::get<GLCanvas>();
255293 auto nodeList = DependencyManager::get<NodeList>();
256294
257− _myAvatar = _avatarManager.getMyAvatar();
295+ _myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
258296
259297 _applicationStartupTime = startup_time;
260298
@@ -285,9 +323,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 24 unmodified lines
285323 QThread* audioThread = new QThread(this);
286324 audioThread->setObjectName("Audio Thread");
287325
288− auto audioIO = DependencyManager::get<Audio>();
326+ auto audioIO = DependencyManager::get<AudioClient>();
327+
328+ audioIO->setPositionGetter(getPositionForAudio);
329+ audioIO->setOrientationGetter(getOrientationForAudio);
330+
289331 audioIO->moveToThread(audioThread);
290− connect(audioThread, &QThread::started, audioIO.data(), &Audio::start);
332+ connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
291333 connect(audioIO.data(), SIGNAL(muteToggled()), this, SLOT(audioMuteToggled()));
292334
293335 audioThread->start();
@@ -331,9 +373,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 37 unmodified lines
331373 auto dialogsManager = DependencyManager::get<DialogsManager>();
332374 connect(&accountManager, &AccountManager::authRequired, dialogsManager.data(), &DialogsManager::showLoginDialog);
333375 connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle);
334−
335− // once we have a profile in account manager make sure we generate a new keypair
336− connect(&accountManager, &AccountManager::profileChanged, &accountManager, &AccountManager::generateNewKeypair);
337376
338377 // set the account manager's root URL and trigger a login request if we don't have the access token
339378 accountManager.setAuthURL(DEFAULT_NODE_AUTH_URL);
@@ -498,7 +537,7 @@ Application::~Application() { · 158 unmodified lines
498537 // kill any audio injectors that are still around
499538 AudioScriptingInterface::getInstance().stopAllInjectors();
500539
501− auto audioIO = DependencyManager::get<Audio>();
540+ auto audioIO = DependencyManager::get<AudioClient>();
502541
503542 // stop the audio process
504543 QMetaObject::invokeMethod(audioIO.data(), "stop", Qt::BlockingQueuedConnection);
@@ -515,6 +554,11 @@ Application::~Application() { · 10 unmodified lines
515554 _myAvatar = NULL;
516555
517556 DependencyManager::destroy<GLCanvas>();
557+ DependencyManager::destroy<AnimationCache>();
558+ DependencyManager::destroy<TextureCache>();
559+ DependencyManager::destroy<GeometryCache>();
560+ DependencyManager::destroy<ScriptCache>();
561+ DependencyManager::destroy<SoundCache>();
518562 }
519563
520564 void Application::initializeGL() {
@@ -702,7 +746,7 @@ void Application::runTests() { · 181 unmodified lines
702746 void Application::audioMuteToggled() {
703747 QAction* muteAction = Menu::getInstance()->getActionForOption(MenuOption::MuteAudio);
704748 Q_CHECK_PTR(muteAction);
705− muteAction->setChecked(DependencyManager::get<Audio>()->isMuted());
749+ muteAction->setChecked(DependencyManager::get<AudioClient>()->isMuted());
706750 }
707751
708752 void Application::aboutApp() {
@@ -1474,6 +1518,8 @@ void Application::setEnableVRMode(bool enableVRMode) { · 765 unmodified lines
14741518
14751519 auto glCanvas = DependencyManager::get<GLCanvas>();
14761520 resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight());
1521+
1522+ updateCursorVisibility();
14771523 }
14781524
14791525 void Application::setLowVelocityFilter(bool lowVelocityFilter) {
@@ -1560,13 +1606,16 @@ bool Application::exportEntities(const QString& filename, float x, float y, floa · 80 unmodified lines
15601606 }
15611607
15621608 void Application::loadSettings() {
1563− DependencyManager::get<Audio>()->loadSettings();
1609+
1610+ DependencyManager::get<AudioClient>()->loadSettings();
1611+
15641612 Menu::getInstance()->loadSettings();
15651613 _myAvatar->loadData();
15661614 }
15671615
15681616 void Application::saveSettings() {
1569− DependencyManager::get<Audio>()->saveSettings();
1617+ DependencyManager::get<AudioClient>()->saveSettings();
1618+
15701619 Menu::getInstance()->saveSettings();
15711620 _myAvatar->saveData();
15721621 }
@@ -1600,7 +1649,7 @@ void Application::init() { · 27 unmodified lines
16001649 DependencyManager::get<AmbientOcclusionEffect>()->init(this);
16011650
16021651 // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager
1603− _avatarManager.init();
1652+ DependencyManager::get<AvatarManager>()->init();
16041653 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
16051654
16061655 _mirrorCamera.setMode(CAMERA_MODE_MIRROR);
@@ -1941,35 +1990,22 @@ void Application::updateCursor(float deltaTime) { · 334 unmodified lines
19411990
19421991 static QPoint lastMousePos = QPoint();
19431992 _lastMouseMove = (lastMousePos == QCursor::pos()) ? _lastMouseMove : usecTimestampNow();
1944− bool hideMouse = false;
1945− bool underMouse = QGuiApplication::topLevelAt(QCursor::pos()) ==
1946− Application::getInstance()->getWindow()->windowHandle();
1947−
1948− static const int HIDE_CURSOR_TIMEOUT = 3 * USECS_PER_SECOND; // 3 second
1949− int elapsed = usecTimestampNow() - _lastMouseMove;
1950− if ((elapsed > HIDE_CURSOR_TIMEOUT) ||
1951− (OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) {
1952− hideMouse = underMouse;
1953− }
1954−
1955− setCursorVisible(!hideMouse);
19561993 lastMousePos = QCursor::pos();
19571994 }
19581995
1959−void Application::setCursorVisible(bool visible) {
1960− if (visible) {
1961− if (overrideCursor() != NULL) {
1962− restoreOverrideCursor();
1963− }
1996+void Application::updateCursorVisibility() {
1997+ if (!_cursorVisible || Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) {
1998+ DependencyManager::get<GLCanvas>()->setCursor(Qt::BlankCursor);
19641999 } else {
1965− if (overrideCursor() != NULL) {
1966− changeOverrideCursor(Qt::BlankCursor);
1967− } else {
1968− setOverrideCursor(Qt::BlankCursor);
1969− }
2000+ DependencyManager::get<GLCanvas>()->unsetCursor();
19702001 }
19712002 }
19722003
2004+void Application::setCursorVisible(bool visible) {
2005+ _cursorVisible = visible;
2006+ updateCursorVisibility();
2007+}
2008+
19732009 void Application::update(float deltaTime) {
19742010 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
19752011 PerformanceWarning warn(showWarnings, "Application::update()");
@@ -1992,7 +2028,7 @@ void Application::update(float deltaTime) { · 16 unmodified lines
19922028
19932029 updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...
19942030
1995− _avatarManager.updateOtherAvatars(deltaTime); //loop through all the other avatars and simulate them...
2031+ DependencyManager::get<AvatarManager>()->updateOtherAvatars(deltaTime); //loop through all the other avatars and simulate them...
19962032
19972033 updateMetavoxels(deltaTime); // update metavoxels
19982034 updateCamera(deltaTime); // handle various camera tweaks like off axis projection
@@ -2019,7 +2055,7 @@ void Application::update(float deltaTime) { · 20 unmodified lines
20192055 {
20202056 PerformanceTimer perfTimer("myAvatar");
20212057 updateMyAvatarLookAtPosition();
2022− updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes
2058+ DependencyManager::get<AvatarManager>()->updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes
20232059 }
20242060
20252061 {
@@ -2076,31 +2112,11 @@ void Application::update(float deltaTime) { · 50 unmodified lines
20762112 if (sinceLastNack > TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS) {
20772113 _lastSendDownstreamAudioStats = now;
20782114
2079− QMetaObject::invokeMethod(DependencyManager::get<Audio>().data(), "sendDownstreamAudioStatsPacket", Qt::QueuedConnection);
2115+ QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "sendDownstreamAudioStatsPacket", Qt::QueuedConnection);
20802116 }
20812117 }
20822118 }
20832119
2084−void Application::updateMyAvatar(float deltaTime) {
2085− bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
2086− PerformanceWarning warn(showWarnings, "Application::updateMyAvatar()");
2087−
2088− _myAvatar->update(deltaTime);
2089−
2090− quint64 now = usecTimestampNow();
2091− quint64 dt = now - _lastSendAvatarDataTime;
2092−
2093− if (dt > MIN_TIME_BETWEEN_MY_AVATAR_DATA_SENDS) {
2094− // send head/hand data to the avatar mixer and voxel server
2095− PerformanceTimer perfTimer("send");
2096− QByteArray packet = byteArrayWithPopulatedHeader(PacketTypeAvatarData);
2097− packet.append(_myAvatar->toByteArray());
2098− controlledBroadcastToNodes(packet, NodeSet() << NodeType::AvatarMixer);
2099−
2100− _lastSendAvatarDataTime = now;
2101− }
2102−}
2103−
21042120 int Application::sendNackPackets() {
21052121
21062122 if (Menu::getInstance()->isOptionChecked(MenuOption::DisableNackPackets)) {
@@ -2540,7 +2556,7 @@ void Application::updateShadowMap() { · 433 unmodified lines
25402556
25412557 {
25422558 PerformanceTimer perfTimer("avatarManager");
2543− _avatarManager.renderAvatars(Avatar::SHADOW_RENDER_MODE);
2559+ DependencyManager::get<AvatarManager>()->renderAvatars(Avatar::SHADOW_RENDER_MODE);
25442560 }
25452561
25462562 {
@@ -2792,7 +2808,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 245 unmodified lines
27922808 bool mirrorMode = (theCamera.getMode() == CAMERA_MODE_MIRROR);
27932809 {
27942810 PerformanceTimer perfTimer("avatars");
2795− _avatarManager.renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE,
2811+ DependencyManager::get<AvatarManager>()->renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE,
27962812 false, selfAvatarOnly);
27972813 }
27982814
@@ -2807,7 +2823,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 8 unmodified lines
28072823
28082824 {
28092825 PerformanceTimer perfTimer("avatarsPostLighting");
2810− _avatarManager.renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE,
2826+ DependencyManager::get<AvatarManager>()->renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE,
28112827 true, selfAvatarOnly);
28122828 }
28132829
@@ -3071,7 +3087,7 @@ void Application::resetSensors() { · 257 unmodified lines
30713087
30723088 _myAvatar->reset();
30733089
3074− QMetaObject::invokeMethod(DependencyManager::get<Audio>().data(), "reset", Qt::QueuedConnection);
3090+ QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "reset", Qt::QueuedConnection);
30753091 }
30763092
30773093 static void setShortcutsEnabled(QWidget* widget, bool enabled) {
@@ -3211,7 +3227,7 @@ void Application::nodeKilled(SharedNodePointer node) { · 133 unmodified lines
32113227 _entityEditSender.nodeKilled(node);
32123228
32133229 if (node->getType() == NodeType::AudioMixer) {
3214− QMetaObject::invokeMethod(DependencyManager::get<Audio>().data(), "audioMixerKilled");
3230+ QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "audioMixerKilled");
32153231 }
32163232
32173233 if (node->getType() == NodeType::EntityServer) {
@@ -3254,7 +3270,7 @@ void Application::nodeKilled(SharedNodePointer node) { · 36 unmodified lines
32543270
32553271 } else if (node->getType() == NodeType::AvatarMixer) {
32563272 // our avatar mixer has gone away - clear the hash of avatars
3257− _avatarManager.clearOtherAvatars();
3273+ DependencyManager::get<AvatarManager>()->clearOtherAvatars();
32583274 }
32593275 }
32603276
@@ -3403,7 +3419,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 142 unmodified lines
34033419
34043420 // hook our avatar and avatar hash map object into this script engine
34053421 scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features
3406− scriptEngine->setAvatarHashMap(&_avatarManager, "AvatarList");
3422+ scriptEngine->setAvatarHashMap(DependencyManager::get<AvatarManager>().data(), "AvatarList");
34073423
34083424 scriptEngine->registerGlobalObject("Camera", &_myCamera);
34093425
@@ -3444,7 +3460,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 34 unmodified lines
34443460 scriptEngine->registerGlobalObject("GlobalServices", GlobalServicesScriptingInterface::getInstance());
34453461 qScriptRegisterMetaType(scriptEngine, DownloadInfoResultToScriptValue, DownloadInfoResultFromScriptValue);
34463462
3447− scriptEngine->registerGlobalObject("AvatarManager", &_avatarManager);
3463+ scriptEngine->registerGlobalObject("AvatarManager", DependencyManager::get<AvatarManager>().data());
34483464
34493465 scriptEngine->registerGlobalObject("Joysticks", &JoystickScriptingInterface::getInstance());
34503466 qScriptRegisterMetaType(scriptEngine, joystickToScriptValue, joystickFromScriptValue);
@@ -3746,10 +3762,6 @@ void Application::toggleLogDialog() { · 295 unmodified lines
37463762 }
37473763 }
37483764
3749−void Application::initAvatarAndViewFrustum() {
3750− updateMyAvatar(0.0f);
3751−}
3752−
37533765 void Application::checkVersion() {
37543766 QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL)));
37553767 latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t