* Make InputTask use SDL.
authorMatthijs Kooijman <m.kooijman@student.utwente.nl>
Tue, 12 Jun 2007 05:46:48 +0000 (07:46 +0200)
committerMatthijs Kooijman <m.kooijman@student.utwente.nl>
Tue, 12 Jun 2007 05:46:48 +0000 (07:46 +0200)
ABM2/Engine/InputTask.cpp
ABM2/Engine/InputTask.h

index 016b419655195e25cddadfe0cad727c9d9953e0f..54e71cbca99d73ae76a637ffcfa38ac3ef57d8c8 100755 (executable)
@@ -19,9 +19,9 @@
 \r
 //unsigned char *CInputTask::keys=0;\r
 //CMMPointer<CMMDynamicBlob<unsigned char> > CInputTask::oldKeys=0;\r
-//int CInputTask::keyCount=0;\r
-BYTE CInputTask::keys[256];\r
-BYTE CInputTask::oldKeys[256];\r
+int CInputTask::keyCount=0;\r
+BYTE *CInputTask::keys;\r
+BYTE *CInputTask::oldKeys;\r
 int CInputTask::dX=0;\r
 int CInputTask::dY=0;\r
 unsigned int CInputTask::buttons=0;\r
@@ -29,72 +29,36 @@ unsigned int CInputTask::oldButtons=0;
 \r
 CInputTask::CInputTask(CKernel* kernel) : ITask(kernel)\r
 {\r
-#ifdef WIN32\r
-       din = NULL;\r
-       dinkeyboard = NULL;\r
-       memset(keys, 0, 256);\r
-       memset(oldKeys, 0, 256);\r
-\r
-       // create the DirectInput interface\r
-       DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL);\r
-\r
-       assert(din != NULL);\r
-\r
-       // create the keyboard device\r
-       din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, NULL);\r
-\r
-       dinkeyboard->SetDataFormat(&c_dfDIKeyboard); // set the data format to keyboard format\r
-\r
-       // set the control you will have over the keyboard\r
-       dinkeyboard->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);\r
-#endif // WIN32\r
+       keys=0;\r
+       oldKeys=0;\r
 }\r
 \r
 CInputTask::~CInputTask()\r
 {\r
-#ifdef WIN32\r
-       if (dinkeyboard != NULL) \r
-       {\r
-               dinkeyboard->Unacquire();\r
-               dinkeyboard->Release();\r
-       }\r
-       if (din != NULL) din->Release();\r
-#endif // WIN32\r
 }\r
 \r
 bool CInputTask::Start()\r
 {\r
-#ifdef WIN32\r
-       dinkeyboard->Acquire();\r
-#endif // WIN32\r
-\r
-\r
-//     keys=SDL_GetKeyState(&keyCount);\r
-//     oldKeys=new CMMDynamicBlob<unsigned char>(keyCount);\r
-//     dX=dY=0;\r
-//     SDL_PumpEvents(); SDL_PumpEvents();\r
+       keys=SDL_GetKeyState(&keyCount);\r
+       oldKeys=new BYTE[keyCount];\r
+       dX=dY=0;\r
+       SDL_PumpEvents(); SDL_PumpEvents();\r
        return true;\r
 }\r
 \r
 void CInputTask::Update()\r
 {\r
-#ifdef WIN32\r
-       dinkeyboard->Acquire();\r
-       memcpy(oldKeys, keys, 256*sizeof(BYTE));\r
-       dinkeyboard->GetDeviceState(256, (LPVOID)keys);\r
-\r
-#endif // WIN32\r
-//     SDL_PumpEvents();\r
-//     oldButtons=buttons;\r
-//     buttons=SDL_GetRelativeMouseState(&dX,&dY);\r
-//     memcpy((unsigned char*)(*oldKeys),keys,sizeof(unsigned char)*keyCount);\r
-//     keys=SDL_GetKeyState(&keyCount);\r
+       SDL_PumpEvents();\r
+       oldButtons=buttons;\r
+       buttons=SDL_GetRelativeMouseState(&dX,&dY);\r
+       memcpy((unsigned char*)(*oldKeys),keys,sizeof(unsigned char)*keyCount);\r
+       keys=SDL_GetKeyState(&keyCount);\r
 }\r
 \r
 void CInputTask::Stop()\r
 {\r
-       //keys=0;\r
-       //oldKeys=0;\r
-       memset(keys, 0, 256);\r
-       memset(oldKeys, 0, 256);\r
+       if (oldKeys)\r
+               delete oldKeys;\r
+       keys=0;\r
+       oldKeys=0;\r
 }\r
index b81f80ab503c6349365d7985813fd66964b283ef..897e6608880c47c117a8c6ec3add2a8dd20deb22 100755 (executable)
@@ -24,10 +24,10 @@ public:
        bool Start();\r
        void Update();\r
        void Stop();\r
-\r
-       static BYTE keys[256], oldKeys[256];\r
+       /* XXX: Yuck, static crapjes */\r
+       static BYTE *keys, *oldKeys;\r
        //static CMMPointer<CMMDynamicBlob<unsigned char> > oldKeys;\r
-       //static int keyCount;\r
+       static int keyCount;\r
        \r
        static int dX,dY;\r
        static unsigned int buttons;\r