-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputProcessor.cpp
More file actions
81 lines (60 loc) · 1.87 KB
/
InputProcessor.cpp
File metadata and controls
81 lines (60 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "InputProcessor.h"
bool CInputProcessor::_quitGame = false;
CInputProcessor::CInputProcessor(OIS::ParamList pl)
{
_inputManager = OIS::InputManager::createInputSystem(pl);
_keyboard = (OIS::Keyboard*)_inputManager->createInputObject(OIS::OISKeyboard, true);
_mouse = (OIS::Mouse*)_inputManager->createInputObject(OIS::OISMouse, true);
_keyboard->setEventCallback(this);
_mouse->setEventCallback(this);
}
CInputProcessor::~CInputProcessor()
{
_inputManager->destroyInputObject(_keyboard);
OIS::InputManager::destroyInputSystem(_inputManager);
}
void CInputProcessor::processInput()
{
static int cleanUp = 0;
_keyReleasedBuffer.clear();
_keyboard->capture();
_mouse->capture();
if (cleanUp++ == 30)
{
cleanUp = 0;
_keyBuffer.shrink_to_fit();
}
}
bool CInputProcessor::keyPressed(const OIS::KeyEvent & arg)
{
if (std::find(_keyBuffer.begin(), _keyBuffer.end(), arg.key) == _keyBuffer.end())
{
_keyBuffer.push_back(arg.key);
}
_quitGame = arg.key == OIS::KC_ESCAPE;
return true;
}
bool CInputProcessor::keyReleased(const OIS::KeyEvent & arg)
{
_keyBuffer.erase(std::remove(_keyBuffer.begin(), _keyBuffer.end(), arg.key), _keyBuffer.end());
_keyReleasedBuffer.push_back(arg.key);
return true;
}
bool CInputProcessor::mouseMoved(const OIS::MouseEvent & arg)
{
_mouseCoords.x = arg.state.X.rel;
_mouseCoords.y = arg.state.Y.rel;
return true;
}
bool CInputProcessor::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
if (std::find(_mouseButtonBuffer.begin(), _mouseButtonBuffer.end(), id) == _mouseButtonBuffer.end())
_mouseButtonBuffer.push_back(id);
return true;
}
bool CInputProcessor::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
_mouseButtonBuffer.erase(std::remove(_mouseButtonBuffer.begin(), _mouseButtonBuffer.end(), id), _mouseButtonBuffer.end());
_mouseReleasedBuffer.push_back(id);
return true;
}