1
0

IrrlichtDevice.h 13 KB

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