rendered paste body#include "kbge/kbge.h"#include <math.h>#define BIT_NUM(X) (uint16)pow((uint16)X, 2)InputManager::InputManager() { this->gameKernel = NULL; this->heldKeys = 0;}InputManager::~InputManager() { this->gameKernel = NULL; this->heldKeys = 0;}void InputManager::Initialize(GameKernel* gk) { this->gameKernel = gk; this->heldKeys = 0;}boolean InputManager::HandleEvent(AEEEvent eCode, uint16 wParam, uint32 dwParam) { switch(eCode) { case EVT_KEY_PRESS: this->HandleKeyDownEvent(wParam, dwParam); break; case EVT_KEY_RELEASE: this->HandleKeyUpEvent(wParam, dwParam); break; } return true;}void InputManager::HandleKeyDownEvent(uint16 wParam, uint32 dwParam) { if (!IsKeyHeld((AVKType)wParam)) { this->heldKeys |= BIT_NUM(wParam); LOG("HandleKeyDownEvent: %u, heldKeys: %u", wParam, this->heldKeys); this->gameKernel->GetApplication()->KeyPressed((AVKType)wParam); }}void InputManager::HandleKeyUpEvent(uint16 wParam, uint32 dwParam) { if (IsKeyHeld((AVKType)wParam)) { this->heldKeys ^= BIT_NUM(wParam); LOG("HandleKeyUpEvent: %u, heldKeys: %u", wParam, this->heldKeys); this->gameKernel->GetApplication()->KeyReleased((AVKType)wParam); }}boolean InputManager::IsKeyHeld(AVKType key) { uint32 keyNum = BIT_NUM(key); return (BIT_NUM(key) & this->heldKeys) == BIT_NUM(key);}