aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceStub.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceStub.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceStub.cpp429
1 files changed, 429 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceStub.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceStub.cpp
new file mode 100644
index 0000000..d74c929
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceStub.cpp
@@ -0,0 +1,429 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#include "CIrrDeviceStub.h"
6#include "ISceneManager.h"
7#include "IEventReceiver.h"
8#include "IFileSystem.h"
9#include "IGUIEnvironment.h"
10#include "os.h"
11#include "IrrCompileConfig.h"
12#include "CTimer.h"
13#include "CLogger.h"
14#include "irrString.h"
15#include "IRandomizer.h"
16
17namespace irr
18{
19//! constructor
20CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params)
21: IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
22 Timer(0), CursorControl(0), UserReceiver(params.EventReceiver),
23 Logger(0), Operator(0), Randomizer(0), FileSystem(0),
24 InputReceivingSceneManager(0), VideoModeList(0),
25 CreationParams(params), Close(false)
26{
27 Timer = new CTimer(params.UsePerformanceTimer);
28 if (os::Printer::Logger)
29 {
30 os::Printer::Logger->grab();
31 Logger = (CLogger*)os::Printer::Logger;
32 Logger->setReceiver(UserReceiver);
33 }
34 else
35 {
36 Logger = new CLogger(UserReceiver);
37 os::Printer::Logger = Logger;
38 }
39 Logger->setLogLevel(CreationParams.LoggingLevel);
40
41 os::Printer::Logger = Logger;
42 Randomizer = createDefaultRandomizer();
43
44 FileSystem = io::createFileSystem();
45 VideoModeList = new video::CVideoModeList();
46
47 core::stringc s = "Irrlicht Engine version ";
48 s.append(getVersion());
49 os::Printer::log(s.c_str(), ELL_INFORMATION);
50
51 checkVersion(params.SDK_version_do_not_use);
52}
53
54
55CIrrDeviceStub::~CIrrDeviceStub()
56{
57 VideoModeList->drop();
58 FileSystem->drop();
59
60 if (GUIEnvironment)
61 GUIEnvironment->drop();
62
63 if (VideoDriver)
64 VideoDriver->drop();
65
66 if (SceneManager)
67 SceneManager->drop();
68
69 if (InputReceivingSceneManager)
70 InputReceivingSceneManager->drop();
71
72 if (CursorControl)
73 CursorControl->drop();
74
75 if (Operator)
76 Operator->drop();
77
78 if (Randomizer)
79 Randomizer->drop();
80
81 CursorControl = 0;
82
83 if (Timer)
84 Timer->drop();
85
86 if (Logger->drop())
87 os::Printer::Logger = 0;
88}
89
90
91void CIrrDeviceStub::createGUIAndScene()
92{
93 #ifdef _IRR_COMPILE_WITH_GUI_
94 // create gui environment
95 GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator);
96 #endif
97
98 // create Scene manager
99 SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl, GUIEnvironment);
100
101 setEventReceiver(UserReceiver);
102}
103
104
105//! returns the video driver
106video::IVideoDriver* CIrrDeviceStub::getVideoDriver()
107{
108 return VideoDriver;
109}
110
111
112
113//! return file system
114io::IFileSystem* CIrrDeviceStub::getFileSystem()
115{
116 return FileSystem;
117}
118
119
120
121//! returns the gui environment
122gui::IGUIEnvironment* CIrrDeviceStub::getGUIEnvironment()
123{
124 return GUIEnvironment;
125}
126
127
128
129//! returns the scene manager
130scene::ISceneManager* CIrrDeviceStub::getSceneManager()
131{
132 return SceneManager;
133}
134
135
136//! \return Returns a pointer to the ITimer object. With it the
137//! current Time can be received.
138ITimer* CIrrDeviceStub::getTimer()
139{
140 return Timer;
141}
142
143
144//! Returns the version of the engine.
145const char* CIrrDeviceStub::getVersion() const
146{
147 return IRRLICHT_SDK_VERSION;
148}
149
150//! \return Returns a pointer to the mouse cursor control interface.
151gui::ICursorControl* CIrrDeviceStub::getCursorControl()
152{
153 return CursorControl;
154}
155
156
157//! \return Returns a pointer to a list with all video modes supported
158//! by the gfx adapter.
159video::IVideoModeList* CIrrDeviceStub::getVideoModeList()
160{
161 return VideoModeList;
162}
163
164
165//! checks version of sdk and prints warning if there might be a problem
166bool CIrrDeviceStub::checkVersion(const char* version)
167{
168 if (strcmp(getVersion(), version))
169 {
170 core::stringc w;
171 w = "Warning: The library version of the Irrlicht Engine (";
172 w += getVersion();
173 w += ") does not match the version the application was compiled with (";
174 w += version;
175 w += "). This may cause problems.";
176 os::Printer::log(w.c_str(), ELL_WARNING);
177 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
178 return false;
179 }
180
181 return true;
182}
183
184
185//! Compares to the last call of this function to return double and triple clicks.
186u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent )
187{
188 const s32 MAX_MOUSEMOVE = 3;
189
190 irr::u32 clickTime = getTimer()->getRealTime();
191
192 if ( (clickTime-MouseMultiClicks.LastClickTime) < MouseMultiClicks.DoubleClickTime
193 && core::abs_(MouseMultiClicks.LastClick.X - mouseX ) <= MAX_MOUSEMOVE
194 && core::abs_(MouseMultiClicks.LastClick.Y - mouseY ) <= MAX_MOUSEMOVE
195 && MouseMultiClicks.CountSuccessiveClicks < 3
196 && MouseMultiClicks.LastMouseInputEvent == inputEvent
197 )
198 {
199 ++MouseMultiClicks.CountSuccessiveClicks;
200 }
201 else
202 {
203 MouseMultiClicks.CountSuccessiveClicks = 1;
204 }
205
206 MouseMultiClicks.LastMouseInputEvent = inputEvent;
207 MouseMultiClicks.LastClickTime = clickTime;
208 MouseMultiClicks.LastClick.X = mouseX;
209 MouseMultiClicks.LastClick.Y = mouseY;
210
211 return MouseMultiClicks.CountSuccessiveClicks;
212}
213
214
215//! send the event to the right receiver
216bool CIrrDeviceStub::postEventFromUser(const SEvent& event)
217{
218 bool absorbed = false;
219
220 if (UserReceiver)
221 absorbed = UserReceiver->OnEvent(event);
222
223 if (!absorbed && GUIEnvironment)
224 absorbed = GUIEnvironment->postEventFromUser(event);
225
226 scene::ISceneManager* inputReceiver = InputReceivingSceneManager;
227 if (!inputReceiver)
228 inputReceiver = SceneManager;
229
230 if (!absorbed && inputReceiver)
231 absorbed = inputReceiver->postEventFromUser(event);
232
233 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
234 return absorbed;
235}
236
237
238//! Sets a new event receiver to receive events
239void CIrrDeviceStub::setEventReceiver(IEventReceiver* receiver)
240{
241 UserReceiver = receiver;
242 Logger->setReceiver(receiver);
243 if (GUIEnvironment)
244 GUIEnvironment->setUserEventReceiver(receiver);
245}
246
247
248//! Returns poinhter to the current event receiver. Returns 0 if there is none.
249IEventReceiver* CIrrDeviceStub::getEventReceiver()
250{
251 return UserReceiver;
252}
253
254
255//! \return Returns a pointer to the logger.
256ILogger* CIrrDeviceStub::getLogger()
257{
258 return Logger;
259}
260
261
262//! Returns the operation system opertator object.
263IOSOperator* CIrrDeviceStub::getOSOperator()
264{
265 return Operator;
266}
267
268
269//! Provides access to the engine's currently set randomizer.
270IRandomizer* CIrrDeviceStub::getRandomizer() const
271{
272 return Randomizer;
273}
274
275//! Sets a new randomizer.
276void CIrrDeviceStub::setRandomizer(IRandomizer* r)
277{
278 if (r!=Randomizer)
279 {
280 if (Randomizer)
281 Randomizer->drop();
282 Randomizer=r;
283 if (Randomizer)
284 Randomizer->grab();
285 }
286}
287
288namespace
289{
290 struct SDefaultRandomizer : public IRandomizer
291 {
292 virtual void reset(s32 value=0x0f0f0f0f)
293 {
294 os::Randomizer::reset(value);
295 }
296
297 virtual s32 rand() const
298 {
299 return os::Randomizer::rand();
300 }
301
302 virtual f32 frand() const
303 {
304 return os::Randomizer::frand();
305 }
306
307 virtual s32 randMax() const
308 {
309 return os::Randomizer::randMax();
310 }
311 };
312}
313
314//! Creates a new default randomizer.
315IRandomizer* CIrrDeviceStub::createDefaultRandomizer() const
316{
317 IRandomizer* r = new SDefaultRandomizer();
318 if (r)
319 r->reset();
320 return r;
321}
322
323
324//! Sets the input receiving scene manager.
325void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager* sceneManager)
326{
327 if (sceneManager)
328 sceneManager->grab();
329 if (InputReceivingSceneManager)
330 InputReceivingSceneManager->drop();
331
332 InputReceivingSceneManager = sceneManager;
333}
334
335
336//! Checks if the window is running in fullscreen mode
337bool CIrrDeviceStub::isFullscreen() const
338{
339 return CreationParams.Fullscreen;
340}
341
342
343//! returns color format
344video::ECOLOR_FORMAT CIrrDeviceStub::getColorFormat() const
345{
346 return video::ECF_R5G6B5;
347}
348
349//! No-op in this implementation
350bool CIrrDeviceStub::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
351{
352 return false;
353}
354
355/*!
356*/
357void CIrrDeviceStub::calculateGammaRamp ( u16 *ramp, f32 gamma, f32 relativebrightness, f32 relativecontrast )
358{
359 s32 i;
360 s32 value;
361 s32 rbright = (s32) ( relativebrightness * (65535.f / 4 ) );
362 f32 rcontrast = 1.f / (255.f - ( relativecontrast * 127.5f ) );
363
364 gamma = gamma > 0.f ? 1.0f / gamma : 0.f;
365
366 for ( i = 0; i < 256; ++i )
367 {
368 value = (s32)(pow( rcontrast * i, gamma)*65535.f + 0.5f );
369 ramp[i] = (u16) core::s32_clamp ( value + rbright, 0, 65535 );
370 }
371
372}
373
374void CIrrDeviceStub::calculateGammaFromRamp ( f32 &gamma, const u16 *ramp )
375{
376 /* The following is adapted from a post by Garrett Bass on OpenGL
377 Gamedev list, March 4, 2000.
378 */
379 f32 sum = 0.0;
380 s32 i, count = 0;
381
382 gamma = 1.0;
383 for ( i = 1; i < 256; ++i ) {
384 if ( (ramp[i] != 0) && (ramp[i] != 65535) ) {
385 f32 B = (f32)i / 256.f;
386 f32 A = ramp[i] / 65535.f;
387 sum += (f32) ( logf(A) / logf(B) );
388 count++;
389 }
390 }
391 if ( count && sum ) {
392 gamma = 1.0f / (sum / count);
393 }
394
395}
396
397//! Set the current Gamma Value for the Display
398bool CIrrDeviceStub::setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast )
399{
400 return false;
401}
402
403//! Get the current Gamma Value for the Display
404bool CIrrDeviceStub::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast )
405{
406 return false;
407}
408
409//! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.
410void CIrrDeviceStub::setDoubleClickTime( u32 timeMs )
411{
412 MouseMultiClicks.DoubleClickTime = timeMs;
413}
414
415//! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.
416u32 CIrrDeviceStub::getDoubleClickTime() const
417{
418 return MouseMultiClicks.DoubleClickTime;
419}
420
421//! Remove all messages pending in the system message loop
422void CIrrDeviceStub::clearSystemMessages()
423{
424}
425
426
427
428} // end namespace irr
429