* Fix wrong pointer dereference in InputTask.
[matthijs/ABM2.git] / ABM2 / Engine / InputTask.cpp
1 // InputTask.cpp: implementation of the CInputTask class.\r
2 //\r
3 //////////////////////////////////////////////////////////////////////\r
4 \r
5 #include "InputTask.h"\r
6 #include "../main.h"\r
7 \r
8 #ifdef WIN32\r
9 // include the DirectX Library files\r
10 #pragma comment (lib, "dinput.lib")\r
11 #pragma comment (lib, "dinput8.lib")\r
12 #pragma comment (lib, "dxguid.lib")\r
13 \r
14 #endif // WIN32\r
15 \r
16 //////////////////////////////////////////////////////////////////////\r
17 // Construction/Destruction\r
18 //////////////////////////////////////////////////////////////////////\r
19 \r
20 //unsigned char *CInputTask::keys=0;\r
21 //CMMPointer<CMMDynamicBlob<unsigned char> > CInputTask::oldKeys=0;\r
22 int CInputTask::keyCount=0;\r
23 BYTE *CInputTask::keys;\r
24 BYTE *CInputTask::oldKeys;\r
25 int CInputTask::dX=0;\r
26 int CInputTask::dY=0;\r
27 unsigned int CInputTask::buttons=0;\r
28 unsigned int CInputTask::oldButtons=0;\r
29 \r
30 CInputTask::CInputTask(CKernel* kernel) : ITask(kernel)\r
31 {\r
32         keys=0;\r
33         oldKeys=0;\r
34 }\r
35 \r
36 CInputTask::~CInputTask()\r
37 {\r
38 }\r
39 \r
40 bool CInputTask::Start()\r
41 {\r
42         keys=SDL_GetKeyState(&keyCount);\r
43         oldKeys=new BYTE[keyCount];\r
44         dX=dY=0;\r
45         SDL_PumpEvents(); SDL_PumpEvents();\r
46         return true;\r
47 }\r
48 \r
49 void CInputTask::Update()\r
50 {\r
51         SDL_PumpEvents();\r
52         oldButtons=buttons;\r
53         buttons=SDL_GetRelativeMouseState(&dX,&dY);\r
54         memcpy(oldKeys,keys,sizeof(unsigned char)*keyCount);\r
55         keys=SDL_GetKeyState(&keyCount);\r
56 }\r
57 \r
58 void CInputTask::Stop()\r
59 {\r
60         if (oldKeys)\r
61                 delete oldKeys;\r
62         keys=0;\r
63         oldKeys=0;\r
64 }\r