From: Matthijs Kooijman Date: Tue, 12 Jun 2007 05:46:48 +0000 (+0200) Subject: * Make InputTask use SDL. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=669bf7a6d3128f0933f6e783e3d0f3c3587d310c;p=matthijs%2FABM2.git * Make InputTask use SDL. --- diff --git a/ABM2/Engine/InputTask.cpp b/ABM2/Engine/InputTask.cpp index 016b419..54e71cb 100755 --- a/ABM2/Engine/InputTask.cpp +++ b/ABM2/Engine/InputTask.cpp @@ -19,9 +19,9 @@ //unsigned char *CInputTask::keys=0; //CMMPointer > CInputTask::oldKeys=0; -//int CInputTask::keyCount=0; -BYTE CInputTask::keys[256]; -BYTE CInputTask::oldKeys[256]; +int CInputTask::keyCount=0; +BYTE *CInputTask::keys; +BYTE *CInputTask::oldKeys; int CInputTask::dX=0; int CInputTask::dY=0; unsigned int CInputTask::buttons=0; @@ -29,72 +29,36 @@ unsigned int CInputTask::oldButtons=0; CInputTask::CInputTask(CKernel* kernel) : ITask(kernel) { -#ifdef WIN32 - din = NULL; - dinkeyboard = NULL; - memset(keys, 0, 256); - memset(oldKeys, 0, 256); - - // create the DirectInput interface - DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL); - - assert(din != NULL); - - // create the keyboard device - din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, NULL); - - dinkeyboard->SetDataFormat(&c_dfDIKeyboard); // set the data format to keyboard format - - // set the control you will have over the keyboard - dinkeyboard->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); -#endif // WIN32 + keys=0; + oldKeys=0; } CInputTask::~CInputTask() { -#ifdef WIN32 - if (dinkeyboard != NULL) - { - dinkeyboard->Unacquire(); - dinkeyboard->Release(); - } - if (din != NULL) din->Release(); -#endif // WIN32 } bool CInputTask::Start() { -#ifdef WIN32 - dinkeyboard->Acquire(); -#endif // WIN32 - - -// keys=SDL_GetKeyState(&keyCount); -// oldKeys=new CMMDynamicBlob(keyCount); -// dX=dY=0; -// SDL_PumpEvents(); SDL_PumpEvents(); + keys=SDL_GetKeyState(&keyCount); + oldKeys=new BYTE[keyCount]; + dX=dY=0; + SDL_PumpEvents(); SDL_PumpEvents(); return true; } void CInputTask::Update() { -#ifdef WIN32 - dinkeyboard->Acquire(); - memcpy(oldKeys, keys, 256*sizeof(BYTE)); - dinkeyboard->GetDeviceState(256, (LPVOID)keys); - -#endif // WIN32 -// SDL_PumpEvents(); -// oldButtons=buttons; -// buttons=SDL_GetRelativeMouseState(&dX,&dY); -// memcpy((unsigned char*)(*oldKeys),keys,sizeof(unsigned char)*keyCount); -// keys=SDL_GetKeyState(&keyCount); + SDL_PumpEvents(); + oldButtons=buttons; + buttons=SDL_GetRelativeMouseState(&dX,&dY); + memcpy((unsigned char*)(*oldKeys),keys,sizeof(unsigned char)*keyCount); + keys=SDL_GetKeyState(&keyCount); } void CInputTask::Stop() { - //keys=0; - //oldKeys=0; - memset(keys, 0, 256); - memset(oldKeys, 0, 256); + if (oldKeys) + delete oldKeys; + keys=0; + oldKeys=0; } diff --git a/ABM2/Engine/InputTask.h b/ABM2/Engine/InputTask.h index b81f80a..897e660 100755 --- a/ABM2/Engine/InputTask.h +++ b/ABM2/Engine/InputTask.h @@ -24,10 +24,10 @@ public: bool Start(); void Update(); void Stop(); - - static BYTE keys[256], oldKeys[256]; + /* XXX: Yuck, static crapjes */ + static BYTE *keys, *oldKeys; //static CMMPointer > oldKeys; - //static int keyCount; + static int keyCount; static int dX,dY; static unsigned int buttons;