123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "client/engine/KeyManager.h"
- KeyManager::KeyManager()
- {
- for(int i = 0; i < NUMBER_OF_KEYS; i++)
- {
- mappingArray[i] = 0;
- }
- }
- bool KeyManager::isDown(int mapping)
- {
- return isInRange(mapping) && keyArray[mappingArray[mapping]].down;
- }
- bool KeyManager::isReleased(int mapping)
- {
- return isInRange(mapping) && keyArray[mappingArray[mapping]].shouldRelease;
- }
- unsigned int KeyManager::getDownTime(int mapping)
- {
- bool m = isInRange(mapping);
- return m * keyArray[mappingArray[mapping * m]].downTime;
- }
- void KeyManager::resetDownTime(int mapping)
- {
- keyArray[mappingArray[mapping * isInRange(mapping)]].downTime = 0;
- }
- bool KeyManager::map(int mapping, int key)
- {
- bool b = isInRange(mapping) && isInRange(key);
- mappingArray[mapping * b] = b * key;
- return b;
- }
- bool KeyManager::isInRange(int i)
- {
- return i >= 0 && i < NUMBER_OF_KEYS;
- }
- void KeyManager::tick()
- {
- for(int i = 0; i < NUMBER_OF_KEYS; i++)
- {
- keyArray[i].downTime += keyArray[i].down;
-
- keyArray[i].down = keyArray[i].down && !keyArray[i].shouldRelease;
- keyArray[i].downTime *= !keyArray[i].shouldRelease;
- keyArray[i].shouldRelease = false;
- }
- }
- void KeyManager::press(int key)
- {
- int index = isInRange(key) * key;
- keyArray[index].down = true;
- keyArray[index].shouldRelease = false;
- }
- void KeyManager::release(int key)
- {
- int index = isInRange(key) * key;
- keyArray[index].shouldRelease = true;
- }
|