IrrlichtDevice.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. #ifndef IRR_I_IRRLICHT_DEVICE_H_INCLUDED
  5. #define IRR_I_IRRLICHT_DEVICE_H_INCLUDED
  6. #include "IReferenceCounted.h"
  7. #include "dimension2d.h"
  8. #include "IVideoDriver.h"
  9. #include "EDriverTypes.h"
  10. #include "EDeviceTypes.h"
  11. #include "IEventReceiver.h"
  12. #include "ICursorControl.h"
  13. #include "IVideoModeList.h"
  14. #include "ITimer.h"
  15. #include "IOSOperator.h"
  16. namespace irr
  17. {
  18. class ILogger;
  19. class IEventReceiver;
  20. class IRandomizer;
  21. namespace io {
  22. class IFileSystem;
  23. } // end namespace io
  24. namespace gui {
  25. class IGUIEnvironment;
  26. } // end namespace gui
  27. namespace scene {
  28. class ISceneManager;
  29. } // end namespace scene
  30. namespace video {
  31. class IContextManager;
  32. } // end namespace video
  33. //! The Irrlicht device. You can create it with createDevice() or createDeviceEx().
  34. /** This is the most important class of the Irrlicht Engine. You can
  35. access everything in the engine if you have a pointer to an instance of
  36. this class. There should be only one instance of this class at any
  37. time.
  38. */
  39. class IrrlichtDevice : public virtual IReferenceCounted
  40. {
  41. public:
  42. //! Runs the device.
  43. /** Also increments the virtual timer by calling
  44. ITimer::tick();. You can prevent this
  45. by calling ITimer::stop(); before and ITimer::start() after
  46. calling IrrlichtDevice::run(). Returns false if device wants
  47. to be deleted. Use it in this way:
  48. \code
  49. while(device->run())
  50. {
  51. // draw everything here
  52. }
  53. \endcode
  54. If you want the device to do nothing if the window is inactive
  55. (recommended), use the slightly enhanced code shown at isWindowActive().
  56. Note if you are running Irrlicht inside an external, custom
  57. created window: Calling Device->run() will cause Irrlicht to
  58. dispatch windows messages internally.
  59. If you are running Irrlicht in your own custom window, you can
  60. also simply use your own message loop using GetMessage,
  61. DispatchMessage and whatever and simply don't use this method.
  62. But note that Irrlicht will not be able to fetch user input
  63. then. See irr::SIrrlichtCreationParameters::WindowId for more
  64. information and example code.
  65. */
  66. virtual bool run() = 0;
  67. //! Cause the device to temporarily pause execution and let other processes run.
  68. /** This should bring down processor usage without major performance loss for Irrlicht.
  69. But this is system dependent, so there's a chance your thread won't get control back quickly.
  70. */
  71. virtual void yield() = 0;
  72. //! Pause execution and let other processes to run for a specified amount of time.
  73. /** It may not wait the full given time, as sleep may be interrupted and also may wait longer on some OS.
  74. \param timeMs: Time to sleep for in milliseconds. Note that the OS can round up this number.
  75. On Windows you usually get at least 15ms sleep time minium for any value > 0.
  76. So if you call this in your main loop you can't get more than 65 FPS anymore in your game.
  77. On most Linux systems it's relatively exact, but also no guarantee.
  78. \param pauseTimer: If true, pauses the device timer while sleeping
  79. */
  80. virtual void sleep(u32 timeMs, bool pauseTimer=false) = 0;
  81. //! Provides access to the video driver for drawing 3d and 2d geometry.
  82. /** \return Pointer the video driver. */
  83. virtual video::IVideoDriver* getVideoDriver() = 0;
  84. //! Provides access to the virtual file system.
  85. /** \return Pointer to the file system. */
  86. virtual io::IFileSystem* getFileSystem() = 0;
  87. //! Provides access to the 2d user interface environment.
  88. /** \return Pointer to the gui environment. */
  89. virtual gui::IGUIEnvironment* getGUIEnvironment() = 0;
  90. //! Provides access to the scene manager.
  91. /** \return Pointer to the scene manager. */
  92. virtual scene::ISceneManager* getSceneManager() = 0;
  93. //! Provides access to the cursor control.
  94. /** \return Pointer to the mouse cursor control interface. */
  95. virtual gui::ICursorControl* getCursorControl() = 0;
  96. //! Provides access to the message logger.
  97. /** \return Pointer to the logger. */
  98. virtual ILogger* getLogger() = 0;
  99. //! Gets a list with all video modes available.
  100. /** You only need a null driver (ED_NULL) to access
  101. those video modes. So you can get the available modes
  102. before starting any other video driver.
  103. \return Pointer to a list with all video modes supported
  104. by the gfx adapter. */
  105. virtual video::IVideoModeList* getVideoModeList() = 0;
  106. //! Get context manager
  107. virtual video::IContextManager* getContextManager() = 0;
  108. //! Provides access to the operation system operator object.
  109. /** The OS operator provides methods for
  110. getting system specific information and doing system
  111. specific operations, such as exchanging data with the clipboard
  112. or reading the operation system version.
  113. \return Pointer to the OS operator. */
  114. virtual IOSOperator* getOSOperator() = 0;
  115. //! Provides access to the engine's timer.
  116. /** The system time can be retrieved by it as
  117. well as the virtual time, which also can be manipulated.
  118. \return Pointer to the ITimer object. */
  119. virtual ITimer* getTimer() = 0;
  120. //! Provides access to the engine's currently set randomizer.
  121. /** \return Pointer to the IRandomizer object. */
  122. virtual IRandomizer* getRandomizer() const =0;
  123. //! Sets a new randomizer.
  124. /** \param r Pointer to the new IRandomizer object. This object is
  125. grab()'ed by the engine and will be released upon the next setRandomizer
  126. call or upon device destruction. */
  127. virtual void setRandomizer(IRandomizer* r) =0;
  128. //! Creates a new default randomizer.
  129. /** The default randomizer provides the random sequence known from previous
  130. Irrlicht versions and is the initial randomizer set on device creation.
  131. \return Pointer to the default IRandomizer object. */
  132. virtual IRandomizer* createDefaultRandomizer() const =0;
  133. //! Sets the caption of the window.
  134. /** \param text: New text of the window caption. */
  135. virtual void setWindowCaption(const wchar_t* text) = 0;
  136. //! Returns if the window is active.
  137. /** If the window is inactive,
  138. nothing needs to be drawn. So if you don't want to draw anything
  139. when the window is inactive, create your drawing loop this way:
  140. \code
  141. while(device->run())
  142. {
  143. if (device->isWindowActive())
  144. {
  145. // draw everything here
  146. }
  147. else
  148. device->yield();
  149. }
  150. \endcode
  151. \return True if window is active. */
  152. virtual bool isWindowActive() const = 0;
  153. //! Checks if the Irrlicht window has the input focus
  154. /** \return True if window has focus. */
  155. virtual bool isWindowFocused() const = 0;
  156. //! Checks if the Irrlicht window is minimized
  157. /** \return True if window is minimized. */
  158. virtual bool isWindowMinimized() const = 0;
  159. //! Checks if the Irrlicht window is running in fullscreen mode
  160. /** \return True if window is fullscreen. */
  161. virtual bool isFullscreen() const = 0;
  162. //! Get the current color format of the window
  163. /** \return Color format of the window. */
  164. virtual video::ECOLOR_FORMAT getColorFormat() const = 0;
  165. //! Notifies the device that it should close itself.
  166. /** IrrlichtDevice::run() will always return false after closeDevice() was called. */
  167. virtual void closeDevice() = 0;
  168. //! Get the version of the engine.
  169. /** The returned string
  170. will look like this: "1.2.3" or this: "1.2".
  171. \return String which contains the version. */
  172. virtual const c8* getVersion() const = 0;
  173. //! Sets a new user event receiver which will receive events from the engine.
  174. /** Return true in IEventReceiver::OnEvent to prevent the event from continuing along
  175. the chain of event receivers. The path that an event takes through the system depends
  176. on its type. See irr::EEVENT_TYPE for details.
  177. \param receiver New receiver to be used. */
  178. virtual void setEventReceiver(IEventReceiver* receiver) = 0;
  179. //! Provides access to the current event receiver.
  180. /** \return Pointer to the current event receiver. Returns 0 if there is none. */
  181. virtual IEventReceiver* getEventReceiver() = 0;
  182. //! Sends a user created event to the engine.
  183. /** Is is usually not necessary to use this. However, if you
  184. are using an own input library for example for doing joystick
  185. input, you can use this to post key or mouse input events to
  186. the engine. Internally, this method only delegates the events
  187. further to the scene manager and the GUI environment. */
  188. virtual bool postEventFromUser(const SEvent& event) = 0;
  189. //! Sets the input receiving scene manager.
  190. /** If set to null, the main scene manager (returned by
  191. GetSceneManager()) will receive the input
  192. \param sceneManager New scene manager to be used. */
  193. virtual void setInputReceivingSceneManager(scene::ISceneManager* sceneManager) = 0;
  194. //! Sets if the window should be resizable in windowed mode.
  195. /** The default is false. This method only works in windowed
  196. mode.
  197. \param resize Flag whether the window should be resizable. */
  198. virtual void setResizable(bool resize=false) = 0;
  199. //! Resize the render window.
  200. /** This will only work in windowed mode and is not yet supported on all systems.
  201. It does set the drawing/clientDC size of the window, the window decorations are added to that.
  202. You get the current window size with IVideoDriver::getScreenSize() (might be unified in future)
  203. */
  204. virtual void setWindowSize(const irr::core::dimension2d<u32>& size) = 0;
  205. //! Minimizes the window if possible.
  206. virtual void minimizeWindow() =0;
  207. //! Maximizes the window if possible.
  208. virtual void maximizeWindow() =0;
  209. //! Restore the window to normal size if possible.
  210. virtual void restoreWindow() =0;
  211. //! Get the position of the frame on-screen
  212. virtual core::position2di getWindowPosition() = 0;
  213. //! Activate any joysticks, and generate events for them.
  214. /** Irrlicht contains support for joysticks, but does not generate joystick events by default,
  215. as this would consume joystick info that 3rd party libraries might rely on. Call this method to
  216. activate joystick support in Irrlicht and to receive irr::SJoystickEvent events.
  217. \param joystickInfo On return, this will contain an array of each joystick that was found and activated.
  218. \return true if joysticks are supported on this device and _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
  219. is defined, false if joysticks are not supported or support is compiled out.
  220. */
  221. virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo) =0;
  222. //! Set the current Gamma Value for the Display
  223. virtual bool setGammaRamp(f32 red, f32 green, f32 blue,
  224. f32 relativebrightness, f32 relativecontrast) =0;
  225. //! Get the current Gamma Value for the Display
  226. virtual bool getGammaRamp(f32 &red, f32 &green, f32 &blue,
  227. f32 &brightness, f32 &contrast) =0;
  228. //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.
  229. /** When set to 0 no double- and tripleclicks will be generated.
  230. \param timeMs maximal time in milliseconds for two consecutive clicks to be recognized as double click
  231. */
  232. virtual void setDoubleClickTime(u32 timeMs) =0;
  233. //! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.
  234. /** When return value is 0 no double- and tripleclicks will be generated.
  235. \return maximal time in milliseconds for two consecutive clicks to be recognized as double click
  236. */
  237. virtual u32 getDoubleClickTime() const =0;
  238. //! Remove messages pending in the system message loop
  239. /** This function is usually used after messages have been buffered for a longer time, for example
  240. when loading a large scene. Clearing the message loop prevents that mouse- or buttonclicks which users
  241. have pressed in the meantime will now trigger unexpected actions in the gui. <br>
  242. So far the following messages are cleared:<br>
  243. Win32: All keyboard and mouse messages<br>
  244. Linux: All keyboard and mouse messages<br>
  245. All other devices are not yet supported here.<br>
  246. The function is still somewhat experimental, as the kind of messages we clear is based on just a few use-cases.
  247. If you think further messages should be cleared, or some messages should not be cleared here, then please tell us. */
  248. virtual void clearSystemMessages() = 0;
  249. //! Get the type of the device.
  250. /** This allows the user to check which windowing system is currently being
  251. used. */
  252. virtual E_DEVICE_TYPE getType() const = 0;
  253. //! Check if a driver type is supported by the engine.
  254. /** Even if true is returned the driver may not be available
  255. for a configuration requested when creating the device. */
  256. static bool isDriverSupported(video::E_DRIVER_TYPE driver)
  257. {
  258. switch (driver)
  259. {
  260. case video::EDT_NULL:
  261. return true;
  262. case video::EDT_SOFTWARE:
  263. #ifdef _IRR_COMPILE_WITH_SOFTWARE_
  264. return true;
  265. #else
  266. return false;
  267. #endif
  268. case video::EDT_BURNINGSVIDEO:
  269. #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
  270. return true;
  271. #else
  272. return false;
  273. #endif
  274. case video::EDT_DIRECT3D9:
  275. #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
  276. return true;
  277. #else
  278. return false;
  279. #endif
  280. case video::EDT_OPENGL:
  281. #ifdef _IRR_COMPILE_WITH_OPENGL_
  282. return true;
  283. #else
  284. return false;
  285. #endif
  286. default:
  287. return false;
  288. }
  289. }
  290. };
  291. } // end namespace irr
  292. #endif