IEventReceiver.h
定义了irrlicht引擎中的事件类型(struct SEvent)和事件接口(class IEventReceiver)
1 struct SEvent 2 { 3 EEVENT_TYPE EventType; 4 union 5 { 6 struct SGUIEvent GUIEvent; //UI响应事件 7 struct SMouseInput MouseInput; //鼠标输入事件 8 struct SKeyInput KeyInput; //键盘输入事件 9 struct SJoystickEvent JoystickEvent; //控制杆输入事件 10 struct SLogEvent LogEvent; //日志事件 11 struct SUserEvent UserEvent; //用户自定义事件 12 }; 13 //! irrlicht用户自定义事件使用的是两个整型 14 //! 通过转型可以用作指针和其他类型 15 struct SUserEvent 16 { 17 //! Some user specified data as int 18 s32 UserData1; 19 20 //! Another user specified data as int 21 s32 UserData2; 22 }; 23 };
ILogger.h
提供了简单的日志输出接口,并定义了日志消息的级别。
IOSOperator.h
提供了简单获取操作系统信息的接口。
1 class IOSOperator : public virtual IReferenceCounted 2 { 3 public: 4 5 //! Destructor 6 virtual ~IOSOperator() {} 7 8 //! 去的操作系统版本(含操作系统名) 9 virtual const wchar_t* getOperationSystemVersion() const = 0; 10 11 //! 把text信息复制到剪贴板 12 virtual void copyToClipboard(const c8* text) const = 0; 13 14 //! 从剪贴板获取信息 15 virtual const c8* getTextFromClipboard() const = 0; 16 17 //! 获取处理器处理速度 18 virtual bool getProcessorSpeedMHz(u32* MHz) const = 0; 19 20 //! 获取机器内存总数和可用内存数 21 virtual bool getSystemMemory(u32* Total, u32* Avail) const = 0; 22 23 };
//因为本人没有这方面的知识所以先看一下如何实现(COSOperator.h和COSOperator.cpp)
IReferenceCounted.h
普通的引用计数类
1 class IReferenceCounted 2 { 3 public: 4 5 //! Constructor. 6 IReferenceCounted() 7 : DebugName(0), ReferenceCounter(1) 8 { 9 } 10 11 //! Destructor. 12 virtual ~IReferenceCounted() 13 { 14 } 15 16 void grab() const { ++ReferenceCounter; } 17 18 19 bool drop() const 20 { 21 // someone is doing bad reference counting. 22 _IRR_DEBUG_BREAK_IF(ReferenceCounter <= 0) 23 24 --ReferenceCounter; 25 if (!ReferenceCounter) 26 { 27 delete this; 28 return true; 29 } 30 31 return false; 32 } 33 34 s32 getReferenceCount() const 35 { 36 return ReferenceCounter; 37 } 38 39 const c8* getDebugName() const 40 { 41 return DebugName; 42 } 43 44 protected: 45 46 //! Sets the debug name of the object. 47 /** The Debugname may only be set and changed by the object 48 itself. This method should only be used in Debug mode. 49 \param newName: New debug name to set. */ 50 void setDebugName(const c8* newName) 51 { 52 DebugName = newName; 53 } 54 55 private: 56 57 const c8* DebugName; 58 59 mutable s32 ReferenceCounter; 60 };
ps:引用计数应设为mutable(const状态下仍可变),ReferenceCounter应为整型指针或把复制函数和复制构造函数设为私有防止复制以避免类复制后引用计数不同步(即使irrlicht仅提供接口,但难以避免用户继承并实现接口导致引用计数问题)
irrlicht.h
包含所有接口和常量定义
IrrlichtDevice.h
//控制游戏运行和窗口的接口
1 class IrrlichtDevice : public virtual IReferenceCounted 2 { 3 public: 4 //控制游戏主线程 5 virtual bool run() = 0; 6 virtual void yield() = 0; 7 virtual void sleep(u32 timeMs, bool pauseTimer=false) = 0; 8 9 //取得各种组件 10 virtual video::IVideoDriver* getVideoDriver() = 0; 11 virtual io::IFileSystem* getFileSystem() = 0; 12 virtual gui::IGUIEnvironment* getGUIEnvironment() = 0; 13 virtual scene::ISceneManager* getSceneManager() = 0; 14 virtual gui::ICursorControl* getCursorControl() = 0; 15 virtual ILogger* getLogger() = 0; 16 virtual video::IVideoModeList* getVideoModeList() = 0; 17 virtual IOSOperator* getOSOperator() = 0; 18 virtual ITimer* getTimer() = 0; 19 20 //控制游戏窗口 21 virtual void setWindowCaption(const wchar_t* text) = 0; 22 virtual bool isWindowActive() const = 0; 23 virtual bool isWindowFocused() const = 0; 24 virtual bool isWindowMinimized() const = 0; 25 virtual bool isFullscreen() const = 0; 26 virtual void setResizable(bool resize=false) = 0; 27 virtual void minimizeWindow() =0; 28 virtual void maximizeWindow() =0; 29 virtual void restoreWindow() =0; 30 //控制消息循环 31 virtualvoid setEventReceiver(IEventReceiver* receiver) = 0; 32 virtual IEventReceiver* getEventReceiver() = 0; 33 virtual bool postEventFromUser(const SEvent& event) = 0; 34 virtual void setInputReceivingSceneManager(scene::ISceneManager* sceneManager) = 0; 35 virtual void clearSystemMessages() = 0; 36 //控制常规信息 37 virtual video::ECOLOR_FORMAT getColorFormat() const = 0; 38 virtualvoid closeDevice() = 0; 39 virtual const c8* getVersion() const = 0; 40 virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo) =0; 41 //控制屏幕gamma值 42 virtual bool setGammaRamp(f32 red, f32 green, f32 blue, 43 f32 relativebrightness, f32 relativecontrast) =0; 44 virtual bool getGammaRamp(f32 &red, f32 &green, f32 &blue, 45 f32 &brightness, f32 &contrast) =0; 46 virtual E_DEVICE_TYPE getType() const = 0; 47 static bool isDriverSupported(video::E_DRIVER_TYPE driver) 48 { 49 switch (driver) 50 { 51 case video::EDT_NULL: 52 return true; 53 case video::EDT_SOFTWARE: 54 #ifdef _IRR_COMPILE_WITH_SOFTWARE_ 55 return true; 56 #else 57 return false; 58 #endif 59 case video::EDT_BURNINGSVIDEO: 60 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ 61 return true; 62 #else 63 return false; 64 #endif 65 case video::EDT_DIRECT3D8: 66 #ifdef _IRR_COMPILE_WITH_DIRECT3D_8_ 67 return true; 68 #else 69 return false; 70 #endif 71 case video::EDT_DIRECT3D9: 72 #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_ 73 return true; 74 #else 75 return false; 76 #endif 77 case video::EDT_OPENGL: 78 #ifdef _IRR_COMPILE_WITH_OPENGL_ 79 return true; 80 #else 81 return false; 82 #endif 83 default: 84 return false; 85 } 86 } 87 };
ITimer.h
//控制游戏的时间类(irrlicht缺少一个时钟事件)
//构想:以一个真实时钟作为游戏运行的主时钟,在主时钟上可以套接多个自定义时钟(拥有一个主时钟指针,来共享主时钟循环)
1 class ITimer : public virtual IReferenceCounted 2 { 3 public: 4 5 //! destructor 6 virtual ~ITimer() {} 7 8 virtual u32 getRealTime() const = 0; 9 10 virtual u32 getTime() const = 0; 11 12 virtual void setTime(u32 time) = 0; 13 14 virtual void stop() = 0; 15 16 virtual void start() = 0; 17 18 virtual void setSpeed(f32 speed = 1.0f) = 0; 19 20 virtual f32 getSpeed() const = 0; 21 22 virtual bool isStopped() const = 0; 23 24 virtual void tick() = 0; 25 };
Keycodes.h
//定义了irrlicht的虚拟键
SIrrCreationParameters.h
//定义了创建irrDevice所需要的属性和默认值
1 struct SIrrlichtCreationParameters 2 { 3 //! Constructs a SIrrlichtCreationParameters structure with default values. 4 SIrrlichtCreationParameters() : 5 DeviceType(EIDT_BEST), 6 DriverType(video::EDT_BURNINGSVIDEO), 7 WindowSize(core::dimension2d<u32>(800, 600)), 8 Bits(16), 9 ZBufferBits(16), 10 Fullscreen(false), 11 Stencilbuffer(false), 12 Vsync(false), 13 AntiAlias(0), 14 WithAlphaChannel(false), 15 Doublebuffer(true), 16 IgnoreInput(false), 17 Stereobuffer(false), 18 HighPrecisionFPU(false), 19 EventReceiver(0), 20 WindowId(0), 21 LoggingLevel(ELL_INFORMATION), 22 SDK_version_do_not_use(IRRLICHT_SDK_VERSION) 23 { 24 } 25 26 SIrrlichtCreationParameters(const SIrrlichtCreationParameters& other) : 27 SDK_version_do_not_use(IRRLICHT_SDK_VERSION) 28 {*this = other;} 29 30 SIrrlichtCreationParameters& operator=(const SIrrlichtCreationParameters& other) 31 { 32 DeviceType = other.DeviceType; 33 DriverType = other.DriverType; 34 WindowSize = other.WindowSize; 35 Bits = other.Bits; 36 ZBufferBits = other.ZBufferBits; 37 Fullscreen = other.Fullscreen; 38 Stencilbuffer = other.Stencilbuffer; 39 Vsync = other.Vsync; 40 AntiAlias = other.AntiAlias; 41 WithAlphaChannel = other.WithAlphaChannel; 42 Doublebuffer = other.Doublebuffer; 43 IgnoreInput = other.IgnoreInput; 44 Stereobuffer = other.Stereobuffer; 45 HighPrecisionFPU = other.HighPrecisionFPU; 46 EventReceiver = other.EventReceiver; 47 WindowId = other.WindowId; 48 LoggingLevel = other.LoggingLevel; 49 return *this; 50 } 51 52 //! Type of the device. 53 /** This setting decides the windowing system used by the device, most device types are native 54 to a specific operating system and so may not be available. 55 EIDT_WIN32 is only available on Windows desktops, 56 EIDT_WINCE is only available on Windows mobile devices, 57 EIDT_COCOA is only available on Mac OSX, 58 EIDT_X11 is available on Linux, Solaris, BSD and other operating systems which use X11, 59 EIDT_SDL is available on most systems if compiled in, 60 EIDT_CONSOLE is usually available but can only render to text, 61 EIDT_BEST will select the best available device for your operating system. 62 Default: EIDT_BEST. */ 63 E_DEVICE_TYPE DeviceType; 64 65 //! Type of video driver used to render graphics. 66 /** This can currently be video::EDT_NULL, video::EDT_SOFTWARE, 67 video::EDT_BURNINGSVIDEO, video::EDT_DIRECT3D8, 68 video::EDT_DIRECT3D9, and video::EDT_OPENGL. 69 Default: Software. */ 70 video::E_DRIVER_TYPE DriverType; 71 72 //! Size of the window or the video mode in fullscreen mode. Default: 800x600 73 core::dimension2d<u32> WindowSize; 74 75 //! Minimum Bits per pixel of the color buffer in fullscreen mode. Ignored if windowed mode. Default: 16. 76 u8 Bits; 77 78 //! Minimum Bits per pixel of the depth buffer. Default: 16. 79 u8 ZBufferBits; 80 81 //! Should be set to true if the device should run in fullscreen. 82 /** Otherwise the device runs in windowed mode. Default: false. */ 83 bool Fullscreen; 84 85 //! Specifies if the stencil buffer should be enabled. 86 /** Set this to true, if you want the engine be able to draw 87 stencil buffer shadows. Note that not all drivers are able to 88 use the stencil buffer, hence it can be ignored during device 89 creation. Without the stencil buffer no shadows will be drawn. 90 Default: false. */ 91 bool Stencilbuffer; 92 93 //! Specifies vertical syncronisation. 94 /** If set to true, the driver will wait for the vertical 95 retrace period, otherwise not. May be silently ignored. 96 Default: false */ 97 bool Vsync; 98 99 //! Specifies if the device should use fullscreen anti aliasing 100 /** Makes sharp/pixelated edges softer, but requires more 101 performance. Also, 2D elements might look blurred with this 102 switched on. The resulting rendering quality also depends on 103 the hardware and driver you are using, your program might look 104 different on different hardware with this. So if you are 105 writing a game/application with AntiAlias switched on, it would 106 be a good idea to make it possible to switch this option off 107 again by the user. 108 The value is the maximal antialiasing factor requested for 109 the device. The cretion method will automatically try smaller 110 values if no window can be created with the given value. 111 Value one is usually the same as 0 (disabled), but might be a 112 special value on some platforms. On D3D devices it maps to 113 NONMASKABLE. 114 Default value: 0 - disabled */ 115 u8 AntiAlias; 116 117 //! Whether the main framebuffer uses an alpha channel. 118 /** In some situations it might be desireable to get a color 119 buffer with an alpha channel, e.g. when rendering into a 120 transparent window or overlay. If this flag is set the device 121 tries to create a framebuffer with alpha channel. 122 If this flag is set, only color buffers with alpha channel 123 are considered. Otherwise, it depends on the actual hardware 124 if the colorbuffer has an alpha channel or not. 125 Default value: false */ 126 bool WithAlphaChannel; 127 128 //! Whether the main framebuffer uses doublebuffering. 129 /** This should be usually enabled, in order to avoid render 130 artifacts on the visible framebuffer. However, it might be 131 useful to use only one buffer on very small devices. If no 132 doublebuffering is available, the drivers will fall back to 133 single buffers. Default value: true */ 134 bool Doublebuffer; 135 136 //! Specifies if the device should ignore input events 137 /** This is only relevant when using external I/O handlers. 138 External windows need to take care of this themselves. 139 Currently only supported by X11. 140 Default value: false */ 141 bool IgnoreInput; 142 143 //! Specifies if the device should use stereo buffers 144 /** Some high-end gfx cards support two framebuffers for direct 145 support of stereoscopic output devices. If this flag is set the 146 device tries to create a stereo context. 147 Currently only supported by OpenGL. 148 Default value: false */ 149 bool Stereobuffer; 150 151 //! Specifies if the device should use high precision FPU setting 152 /** This is only relevant for DirectX Devices, which switch to 153 low FPU precision by default for performance reasons. However, 154 this may lead to problems with the other computations of the 155 application. In this case setting this flag to true should help 156 - on the expense of performance loss, though. 157 Default value: false */ 158 bool HighPrecisionFPU; 159 160 //! A user created event receiver. 161 IEventReceiver* EventReceiver; 162 163 //! Window Id. 164 /** If this is set to a value other than 0, the Irrlicht Engine 165 will be created in an already existing window. For windows, set 166 this to the HWND of the window you want. The windowSize and 167 FullScreen options will be ignored when using the WindowId 168 parameter. Default this is set to 0. 169 To make Irrlicht run inside the custom window, you still will 170 have to draw Irrlicht on your own. You can use this loop, as 171 usual: 172 \code 173 while (device->run()) 174 { 175 driver->beginScene(true, true, 0); 176 smgr->drawAll(); 177 driver->endScene(); 178 } 179 \endcode 180 Instead of this, you can also simply use your own message loop 181 using GetMessage, DispatchMessage and whatever. Calling 182 IrrlichtDevice::run() will cause Irrlicht to dispatch messages 183 internally too. You need not call Device->run() if you want to 184 do your own message dispatching loop, but Irrlicht will not be 185 able to fetch user input then and you have to do it on your own 186 using the window messages, DirectInput, or whatever. Also, 187 you'll have to increment the Irrlicht timer. 188 An alternative, own message dispatching loop without 189 device->run() would look like this: 190 \code 191 MSG msg; 192 while (true) 193 { 194 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 195 { 196 TranslateMessage(&msg); 197 DispatchMessage(&msg); 198 199 if (msg.message == WM_QUIT) 200 break; 201 } 202 203 // increase virtual timer time 204 device->getTimer()->tick(); 205 206 // draw engine picture 207 driver->beginScene(true, true, 0); 208 smgr->drawAll(); 209 driver->endScene(); 210 } 211 \endcode 212 However, there is no need to draw the picture this often. Just 213 do it how you like. */ 214 void* WindowId; 215 216 //! Specifies the logging level used in the logging interface. 217 /** The default value is ELL_INFORMATION. You can access the ILogger interface 218 later on from the IrrlichtDevice with getLogger() and set another level. 219 But if you need more or less logging information already from device creation, 220 then you have to change it here. 221 */ 222 ELOG_LEVEL LoggingLevel; 223 224 //! Don't use or change this parameter. 225 /** Always set it to IRRLICHT_SDK_VERSION, which is done by default. 226 This is needed for sdk version checks. */ 227 const c8* const SDK_version_do_not_use; 228 };