]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CIrrDeviceStub.cpp
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / CIrrDeviceStub.cpp
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #include "CIrrDeviceStub.h"\r
6 #include "ISceneManager.h"\r
7 #include "IEventReceiver.h"\r
8 #include "IFileSystem.h"\r
9 #include "IGUIElement.h"\r
10 #include "IGUIEnvironment.h"\r
11 #include "os.h"\r
12 #include "CTimer.h"\r
13 #include "CLogger.h"\r
14 #include "irrString.h"\r
15 #include "IrrCompileConfig.h" // for IRRLICHT_SDK_VERSION\r
16 \r
17 namespace irr\r
18 {\r
19 //! constructor\r
20 CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params)\r
21 : IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),\r
22         Timer(0), CursorControl(0), UserReceiver(params.EventReceiver),\r
23         Logger(0), Operator(0), FileSystem(0),\r
24         InputReceivingSceneManager(0), ContextManager(0),\r
25         CreationParams(params), Close(false)\r
26 {\r
27         Timer = new CTimer(params.UsePerformanceTimer);\r
28         if (os::Printer::Logger)\r
29         {\r
30                 os::Printer::Logger->grab();\r
31                 Logger = (CLogger*)os::Printer::Logger;\r
32                 Logger->setReceiver(UserReceiver);\r
33         }\r
34         else\r
35         {\r
36                 Logger = new CLogger(UserReceiver);\r
37                 os::Printer::Logger = Logger;\r
38         }\r
39         Logger->setLogLevel(CreationParams.LoggingLevel);\r
40 \r
41         os::Printer::Logger = Logger;\r
42 \r
43         FileSystem = io::createFileSystem();\r
44 \r
45         core::stringc s = "Irrlicht Engine version ";\r
46         s.append(getVersion());\r
47         os::Printer::log(s.c_str(), ELL_INFORMATION);\r
48 \r
49         checkVersion(params.SDK_version_do_not_use);\r
50 }\r
51 \r
52 \r
53 CIrrDeviceStub::~CIrrDeviceStub()\r
54 {\r
55         if (GUIEnvironment)\r
56                 GUIEnvironment->drop();\r
57 \r
58         if (SceneManager)\r
59                 SceneManager->drop();\r
60 \r
61         if (VideoDriver)\r
62                 VideoDriver->drop();\r
63 \r
64         if (ContextManager)\r
65                 ContextManager->drop();\r
66 \r
67         if ( FileSystem )\r
68                 FileSystem->drop();\r
69 \r
70         if (InputReceivingSceneManager)\r
71                 InputReceivingSceneManager->drop();\r
72 \r
73         if (CursorControl)\r
74                 CursorControl->drop();\r
75 \r
76         if (Operator)\r
77                 Operator->drop();\r
78 \r
79         CursorControl = 0;\r
80 \r
81         if (Timer)\r
82                 Timer->drop();\r
83 \r
84         if (Logger->drop())\r
85                 os::Printer::Logger = 0;\r
86 }\r
87 \r
88 \r
89 void CIrrDeviceStub::createGUIAndScene()\r
90 {\r
91         // create gui environment\r
92         GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator);\r
93 \r
94         // create Scene manager\r
95         SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl, GUIEnvironment);\r
96 \r
97         setEventReceiver(UserReceiver);\r
98 }\r
99 \r
100 \r
101 //! returns the video driver\r
102 video::IVideoDriver* CIrrDeviceStub::getVideoDriver()\r
103 {\r
104         return VideoDriver;\r
105 }\r
106 \r
107 \r
108 //! return file system\r
109 io::IFileSystem* CIrrDeviceStub::getFileSystem()\r
110 {\r
111         return FileSystem;\r
112 }\r
113 \r
114 \r
115 \r
116 //! returns the gui environment\r
117 gui::IGUIEnvironment* CIrrDeviceStub::getGUIEnvironment()\r
118 {\r
119         return GUIEnvironment;\r
120 }\r
121 \r
122 \r
123 \r
124 //! returns the scene manager\r
125 scene::ISceneManager* CIrrDeviceStub::getSceneManager()\r
126 {\r
127         return SceneManager;\r
128 }\r
129 \r
130 \r
131 //! \return Returns a pointer to the ITimer object. With it the\r
132 //! current Time can be received.\r
133 ITimer* CIrrDeviceStub::getTimer()\r
134 {\r
135         return Timer;\r
136 }\r
137 \r
138 \r
139 //! Returns the version of the engine.\r
140 const char* CIrrDeviceStub::getVersion() const\r
141 {\r
142         return IRRLICHT_SDK_VERSION;\r
143 }\r
144 \r
145 //! \return Returns a pointer to the mouse cursor control interface.\r
146 gui::ICursorControl* CIrrDeviceStub::getCursorControl()\r
147 {\r
148         return CursorControl;\r
149 }\r
150 \r
151 \r
152 //! return the context manager\r
153 video::IContextManager* CIrrDeviceStub::getContextManager()\r
154 {\r
155         return ContextManager;\r
156 }\r
157 \r
158 //! checks version of sdk and prints warning if there might be a problem\r
159 bool CIrrDeviceStub::checkVersion(const char* version)\r
160 {\r
161         if (strcmp(getVersion(), version))\r
162         {\r
163                 core::stringc w;\r
164                 w = "Warning: The library version of the Irrlicht Engine (";\r
165                 w += getVersion();\r
166                 w += ") does not match the version the application was compiled with (";\r
167                 w += version;\r
168                 w += "). This may cause problems.";\r
169                 os::Printer::log(w.c_str(), ELL_WARNING);\r
170 \r
171                 return false;\r
172         }\r
173 \r
174         return true;\r
175 }\r
176 \r
177 \r
178 //! Compares to the last call of this function to return double and triple clicks.\r
179 u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent )\r
180 {\r
181         const s32 MAX_MOUSEMOVE = 3;\r
182 \r
183         irr::u32 clickTime = getTimer()->getRealTime();\r
184 \r
185         if ( (clickTime-MouseMultiClicks.LastClickTime) < MouseMultiClicks.DoubleClickTime\r
186                 && core::abs_(MouseMultiClicks.LastClick.X - mouseX ) <= MAX_MOUSEMOVE\r
187                 && core::abs_(MouseMultiClicks.LastClick.Y - mouseY ) <= MAX_MOUSEMOVE\r
188                 && MouseMultiClicks.CountSuccessiveClicks < 3\r
189                 && MouseMultiClicks.LastMouseInputEvent == inputEvent\r
190            )\r
191         {\r
192                 ++MouseMultiClicks.CountSuccessiveClicks;\r
193         }\r
194         else\r
195         {\r
196                 MouseMultiClicks.CountSuccessiveClicks = 1;\r
197         }\r
198 \r
199         MouseMultiClicks.LastMouseInputEvent = inputEvent;\r
200         MouseMultiClicks.LastClickTime = clickTime;\r
201         MouseMultiClicks.LastClick.X = mouseX;\r
202         MouseMultiClicks.LastClick.Y = mouseY;\r
203 \r
204         return MouseMultiClicks.CountSuccessiveClicks;\r
205 }\r
206 \r
207 \r
208 //! send the event to the right receiver\r
209 bool CIrrDeviceStub::postEventFromUser(const SEvent& event)\r
210 {\r
211         bool absorbed = false;\r
212 \r
213         if (UserReceiver)\r
214                 absorbed = UserReceiver->OnEvent(event);\r
215 \r
216         if (!absorbed && GUIEnvironment)\r
217                 absorbed = GUIEnvironment->postEventFromUser(event);\r
218 \r
219         scene::ISceneManager* inputReceiver = InputReceivingSceneManager;\r
220         if (!inputReceiver)\r
221                 inputReceiver = SceneManager;\r
222 \r
223         if (!absorbed && inputReceiver)\r
224                 absorbed = inputReceiver->postEventFromUser(event);\r
225 \r
226         return absorbed;\r
227 }\r
228 \r
229 \r
230 //! Sets a new event receiver to receive events\r
231 void CIrrDeviceStub::setEventReceiver(IEventReceiver* receiver)\r
232 {\r
233         UserReceiver = receiver;\r
234         Logger->setReceiver(receiver);\r
235         if (GUIEnvironment)\r
236                 GUIEnvironment->setUserEventReceiver(receiver);\r
237 }\r
238 \r
239 \r
240 //! Returns poinhter to the current event receiver. Returns 0 if there is none.\r
241 IEventReceiver* CIrrDeviceStub::getEventReceiver()\r
242 {\r
243         return UserReceiver;\r
244 }\r
245 \r
246 \r
247 //! \return Returns a pointer to the logger.\r
248 ILogger* CIrrDeviceStub::getLogger()\r
249 {\r
250         return Logger;\r
251 }\r
252 \r
253 \r
254 //! Returns the operation system opertator object.\r
255 IOSOperator* CIrrDeviceStub::getOSOperator()\r
256 {\r
257         return Operator;\r
258 }\r
259 \r
260 \r
261 //! Sets the input receiving scene manager.\r
262 void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager* sceneManager)\r
263 {\r
264         if (sceneManager)\r
265                 sceneManager->grab();\r
266         if (InputReceivingSceneManager)\r
267                 InputReceivingSceneManager->drop();\r
268 \r
269         InputReceivingSceneManager = sceneManager;\r
270 }\r
271 \r
272 \r
273 //! Checks if the window is maximized.\r
274 bool CIrrDeviceStub::isWindowMaximized() const\r
275 {\r
276         return false;\r
277 }\r
278 \r
279 \r
280 //! Checks if the window is running in fullscreen mode\r
281 bool CIrrDeviceStub::isFullscreen() const\r
282 {\r
283         return CreationParams.Fullscreen;\r
284 }\r
285 \r
286 \r
287 //! returns color format\r
288 video::ECOLOR_FORMAT CIrrDeviceStub::getColorFormat() const\r
289 {\r
290         return video::ECF_R5G6B5;\r
291 }\r
292 \r
293 //! No-op in this implementation\r
294 bool CIrrDeviceStub::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)\r
295 {\r
296         return false;\r
297 }\r
298 \r
299 //! No-op in this implementation\r
300 bool CIrrDeviceStub::activateAccelerometer(float updateInterval)\r
301 {\r
302     return false;\r
303 }\r
304 \r
305 //! No-op in this implementation\r
306 bool CIrrDeviceStub::deactivateAccelerometer()\r
307 {\r
308     return false;\r
309 }\r
310 \r
311 //! No-op in this implementation\r
312 bool CIrrDeviceStub::isAccelerometerActive()\r
313 {\r
314     return false;\r
315 }\r
316 \r
317 //! No-op in this implementation\r
318 bool CIrrDeviceStub::isAccelerometerAvailable()\r
319 {\r
320     return false;\r
321 }\r
322 \r
323 //! No-op in this implementation\r
324 bool CIrrDeviceStub::activateGyroscope(float updateInterval)\r
325 {\r
326     return false;\r
327 }\r
328 \r
329 //! No-op in this implementation\r
330 bool CIrrDeviceStub::deactivateGyroscope()\r
331 {\r
332     return false;\r
333 }\r
334 \r
335 //! No-op in this implementation\r
336 bool CIrrDeviceStub::isGyroscopeActive()\r
337 {\r
338     return false;\r
339 }\r
340 \r
341 //! No-op in this implementation\r
342 bool CIrrDeviceStub::isGyroscopeAvailable()\r
343 {\r
344     return false;\r
345 }\r
346 \r
347 //! No-op in this implementation\r
348 bool CIrrDeviceStub::activateDeviceMotion(float updateInterval)\r
349 {\r
350     return false;\r
351 }\r
352 \r
353 //! No-op in this implementation\r
354 bool CIrrDeviceStub::deactivateDeviceMotion()\r
355 {\r
356     return false;\r
357 }\r
358 \r
359 //! No-op in this implementation\r
360 bool CIrrDeviceStub::isDeviceMotionActive()\r
361 {\r
362     return false;\r
363 }\r
364 \r
365 //! No-op in this implementation\r
366 bool CIrrDeviceStub::isDeviceMotionAvailable()\r
367 {\r
368     return false;\r
369 }\r
370 \r
371 //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.\r
372 void CIrrDeviceStub::setDoubleClickTime( u32 timeMs )\r
373 {\r
374         MouseMultiClicks.DoubleClickTime = timeMs;\r
375 }\r
376 \r
377 //! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.\r
378 u32 CIrrDeviceStub::getDoubleClickTime() const\r
379 {\r
380         return MouseMultiClicks.DoubleClickTime;\r
381 }\r
382 \r
383 //! Remove all messages pending in the system message loop\r
384 void CIrrDeviceStub::clearSystemMessages()\r
385 {\r
386 }\r
387 \r
388 //! Checks whether the input device should take input from the IME\r
389 bool CIrrDeviceStub::acceptsIME()\r
390 {\r
391         if (!GUIEnvironment)\r
392                 return false;\r
393         gui::IGUIElement *elem = GUIEnvironment->getFocus();\r
394         return elem && elem->acceptsIME();\r
395 }\r
396 \r
397 \r
398 } // end namespace irr\r
399 \r