History

Setup DependencyManager before any member of Application

Atlante45 committed 11 years ago

Commit 36db5471 parent 27cc3d22 files · +43 −11Browse files

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

Unified · Split

interface/src/Application.cpp+42−11
@@ -85,6 +85,8 @@ · 84 unmodified lines
85#include "Util.h"85#include "Util.h"
86 86
87#include "audio/AudioToolBox.h"87#include "audio/AudioToolBox.h"
88#include "audio/AudioIOStatsRenderer.h"
89#include "audio/AudioScope.h"
88 90
89#include "devices/DdeFaceTracker.h"91#include "devices/DdeFaceTracker.h"
90#include "devices/Faceshift.h"92#include "devices/Faceshift.h"
@@ -142,8 +144,43 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt · 51 unmodified lines
142 }144 }
143}145}
144 146
147bool setupEssentials(int& argc, char** argv) {
148 unsigned int listenPort = 0; // bind to an ephemeral port by default
149 const char** constArgv = const_cast<const char**>(argv);
150 const char* portStr = getCmdOption(argc, constArgv, "--listenPort");
151 if (portStr) {
152 listenPort = atoi(portStr);
153 }
154
155 DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
156
157 // Set dependencies
158 DependencyManager::get<GLCanvas>();
159 auto glCanvas = DependencyManager::set<GLCanvas>();
160 auto addressManager = DependencyManager::set<AddressManager>();
161 auto nodeList = DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
162 auto geometryCache = DependencyManager::set<GeometryCache>();
163 auto glowEffect = DependencyManager::set<GlowEffect>();
164 auto faceshift = DependencyManager::set<Faceshift>();
165 auto audio = DependencyManager::set<Audio>();
166 auto audioScope = DependencyManager::set<AudioScope>();
167 auto audioIOStatsRenderer = DependencyManager::set<AudioIOStatsRenderer>();
168 auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>();
169 auto ambientOcclusionEffect = DependencyManager::set<AmbientOcclusionEffect>();
170 auto textureCache = DependencyManager::set<TextureCache>();
171 auto animationCache = DependencyManager::set<AnimationCache>();
172 auto visage = DependencyManager::set<Visage>();
173 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();
174 auto modelBlender = DependencyManager::set<ModelBlender>();
175 auto audioToolBox = DependencyManager::set<AudioToolBox>();
176
177 return true;
178}
179
180
145Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :181Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
146 QApplication(argc, argv),182 QApplication(argc, argv),
183 _dependencyManagerIsSetup(setupEssentials(argc, argv)),
147 _window(new MainWindow(desktop())),184 _window(new MainWindow(desktop())),
148 _toolWindow(NULL),185 _toolWindow(NULL),
149 _nodeThread(new QThread(this)),186 _nodeThread(new QThread(this)),
@@ -189,7 +226,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 39 unmodified lines
189 _isVSyncOn(true),226 _isVSyncOn(true),
190 _aboutToQuit(false)227 _aboutToQuit(false)
191{228{
192 auto glCanvas = DependencyManager::set<GLCanvas>();229 auto glCanvas = DependencyManager::get<GLCanvas>();
230 auto nodeList = DependencyManager::get<NodeList>();
193 Model::setAbstractViewStateInterface(this); // The model class will sometimes need to know view state details from us231 Model::setAbstractViewStateInterface(this); // The model class will sometimes need to know view state details from us
194 232
195 233
@@ -223,23 +261,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 27 unmodified lines
223 _window->setMenuBar(Menu::getInstance());261 _window->setMenuBar(Menu::getInstance());
224 262
225 _runningScriptsWidget = new RunningScriptsWidget(_window);263 _runningScriptsWidget = new RunningScriptsWidget(_window);
226
227 unsigned int listenPort = 0; // bind to an ephemeral port by default
228 const char** constArgv = const_cast<const char**>(argv);
229 const char* portStr = getCmdOption(argc, constArgv, "--listenPort");
230 if (portStr) {
231 listenPort = atoi(portStr);
232 }
233 264
234 // start the nodeThread so its event loop is running265 // start the nodeThread so its event loop is running
235 _nodeThread->start();266 _nodeThread->start();
236 267
237 // make sure the node thread is given highest priority268 // make sure the node thread is given highest priority
238 _nodeThread->setPriority(QThread::TimeCriticalPriority);269 _nodeThread->setPriority(QThread::TimeCriticalPriority);
239
240 // put the NodeList and datagram processing on the node thread
241 auto nodeList = DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
242 270
271 // put the NodeList and datagram processing on the node thread
243 nodeList->moveToThread(_nodeThread);272 nodeList->moveToThread(_nodeThread);
244 _datagramProcessor.moveToThread(_nodeThread);273 _datagramProcessor.moveToThread(_nodeThread);
245 274
@@ -460,6 +489,8 @@ Application::~Application() { · 214 unmodified lines
460 Menu::getInstance()->deleteLater();489 Menu::getInstance()->deleteLater();
461 490
462 _myAvatar = NULL;491 _myAvatar = NULL;
492
493 DependencyManager::destroy<GLCanvas>();
463}494}
464 495
465void Application::saveSettings() {496void Application::saveSettings() {

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