00001
00002 #include "Core/precomp.h"
00003
00004 #include "API/Core/System/cl_assert.h"
00005
00006 #include "input_dx.h"
00007 #include "input_keyboard.h"
00008 #include "input_mouse.h"
00009 #include "input_joystick.h"
00010
00011 LPDIRECTINPUT CL_Input_DX::dinput = NULL;
00012
00013 CL_Input_DX::CL_Input_DX()
00014 {
00015 HRESULT err = DirectInputCreate(CL_System_Win32::hInstance, 0x0300, &dinput, NULL);
00016 cl_assert(err == DI_OK);
00017
00018 CL_Input::keyboards.push_back(new CL_Keyboard_Win32);
00019 CL_Input::pointers.push_back(new CL_Mouse_Win32);
00020
00021 int num_devs = joyGetNumDevs();
00022 for (int i=0; i<num_devs; i++)
00023 {
00024 JOYCAPS joycaps;
00025 MMRESULT err = joyGetDevCaps(i, &joycaps, sizeof(joycaps));
00026 if (err == JOYERR_NOERROR) CL_Input::joysticks.push_back(new CL_Joystick_Win32(i));
00027 }
00028 }
00029
00030 CL_Input_DX::~CL_Input_DX()
00031 {
00032 dinput->Release();
00033
00034 for (std::vector<CL_Keyboard*>::iterator k_it=CL_Input::keyboards.begin();
00035 k_it!=CL_Input::keyboards.end();k_it++)
00036 {
00037 delete *k_it;
00038 }
00039
00040 for (std::vector<CL_InputDevice*>::iterator m_it=CL_Input::pointers.begin();
00041 m_it!=CL_Input::pointers.end();m_it++)
00042 {
00043 delete *m_it;
00044 }
00045
00046 for (std::vector<CL_InputDevice*>::iterator j_it=CL_Input::joysticks.begin();
00047 j_it!=CL_Input::joysticks.end();j_it++)
00048 {
00049 delete *j_it;
00050 }
00051 }