00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_DI_GAME_DEVICE_H
00027 #define NL_DI_GAME_DEVICE_H
00028
00029 #include "nel/misc/types_nl.h"
00030
00031 #ifdef NL_OS_WINDOWS
00032
00033 #include "nel/misc/di_event_emitter.h"
00034 #include "nel/misc/game_device.h"
00035
00036 namespace NLMISC
00037 {
00038
00039
00040 typedef DIJOYSTATE2 CDIJoyState;
00041 const DIDATAFORMAT * const pJoyDataFormat = &c_dfDIJoystick2;
00042 const uint MaxNumSliders = 2;
00043 const uint MaxNumPOVs = 4;
00044 const uint MaxNumButtons = 128;
00045
00046
00047 struct EDirectInputGameDeviceNotCreated : EDirectInput
00048 {
00049 EDirectInputGameDeviceNotCreated() : EDirectInput("Unable to create a game device") {}
00050 };
00051
00052
00057 class CDIGameDevice : public IGameDevice
00058 {
00059 public:
00061 static CDIGameDevice *createGameDevice(IDirectInput8 *di8,
00062 HWND hwnd,
00063 CDIEventEmitter *diEventEmitter,
00064 const CGameDeviceDesc &desc,
00065 REFGUID rguid) throw(EDirectInput);
00066 ~CDIGameDevice();
00067
00069
00070 virtual bool setBufferSize(uint size);
00071 virtual uint getBufferSize() const;
00073
00075
00076 virtual const CGameDeviceDesc &getDescription() const { return _Desc; }
00077
00078 virtual uint getNumButtons() const;
00079 virtual bool hasAxis(TAxis axis) const;
00080 virtual uint getNumSliders() const;
00081 virtual uint getNumPOV() const;
00082
00083 virtual const char *getButtonName(uint index) const;
00084 virtual const char *getAxisName(TAxis axis) const;
00085 virtual const char *getSliderName(uint index) const;
00086 virtual const char *getPOVName(uint index) const;
00087
00088 virtual bool getButtonState(uint index) const;
00089 virtual float getAxisValue(TAxis axis) const;
00090 virtual float getSliderPos(uint index) const;
00091 virtual float getPOVAngle(uint index) const;
00093
00094
00097 private:
00098
00099
00100 struct CCtrl
00101 {
00102 std::string Name;
00103 };
00104
00105
00106 struct CButton : public CCtrl
00107 {
00108 bool Pushed;
00109 CButton() : Pushed(false) {}
00110 };
00111
00112
00113 struct CAxis : public CCtrl
00114 {
00115 bool Present;
00116
00117 sint Min, Max;
00118 float Value;
00119 CAxis() : Value(0.f), Present(false) {}
00120 };
00121
00122
00123 struct CSlider : public CCtrl
00124 {
00125 sint Min, Max;
00126 float Pos;
00127 CSlider() : Pos(0.f) {}
00128 };
00129
00130
00131 struct CPOV : public CCtrl
00132 {
00133 bool Centered;
00134 float Angle;
00135 CPOV() : Angle(0.f), Centered(true) {}
00136 };
00137
00138
00139 private:
00140
00141 CDIGameDevice();
00143
00144 virtual void begin(CEventServer *server);
00145 virtual void poll(CInputDeviceServer *dev);
00146 virtual void submit(IInputDeviceEvent *deviceEvent, CEventServer *server);
00148
00150 void querryControls();
00151
00153 BOOL processEnumObject(LPCDIDEVICEOBJECTINSTANCE lpddoi);
00154 friend BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef);
00155 private:
00156 LPDIRECTINPUTDEVICE8 _Device;
00157 CGameDeviceDesc _Desc;
00158 CDIEventEmitter *_EventEmitter;
00159
00161
00162 CAxis _Axis[MaxNumAxis];
00163 std::vector<CButton> _Buttons;
00164 std::vector<CSlider> _Sliders;
00165 std::vector<CPOV> _POVs;
00167 CDIJoyState _CurrentState;
00168
00169 };
00170
00171
00172 }
00173
00174 #endif // NL_OS_WINDOWS
00175
00176
00177 #endif // NL_DI_GAME_DEVICE_H
00178
00179