From 7e610aece52ad547d4ae263aff5297342d5a4bff Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 13 Aug 2011 22:44:31 +0200 Subject: Overhaul the input system This allows us to map the keys which are not considered in irrlicht's EKEY_CODE system, such as \, [, /, ] etc. --- src/main.cpp | 55 +++++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index d93cdba1e..b9a957322 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -563,10 +563,12 @@ public: // Remember whether each key is down or up if(event.EventType == irr::EET_KEY_INPUT_EVENT) { - keyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown; - - if(event.KeyInput.PressedDown) - keyWasDown[event.KeyInput.Key] = true; + if(event.KeyInput.PressedDown) { + keyIsDown.set(event.KeyInput); + keyWasDown.set(event.KeyInput); + } else { + keyIsDown.unset(event.KeyInput); + } } if(event.EventType == irr::EET_MOUSE_INPUT_EVENT) @@ -610,16 +612,17 @@ public: return false; } - bool IsKeyDown(EKEY_CODE keyCode) const + bool IsKeyDown(const KeyPress &keyCode) const { return keyIsDown[keyCode]; } // Checks whether a key was down and resets the state - bool WasKeyDown(EKEY_CODE keyCode) + bool WasKeyDown(const KeyPress &keyCode) { bool b = keyWasDown[keyCode]; - keyWasDown[keyCode] = false; + if (b) + keyWasDown.unset(keyCode); return b; } @@ -632,12 +635,9 @@ public: void clearInput() { - for(u32 i=0; iIsKeyDown(keyCode); } - virtual bool wasKeyDown(EKEY_CODE keyCode) + virtual bool wasKeyDown(const KeyPress &keyCode) { return m_receiver->WasKeyDown(keyCode); } @@ -772,14 +772,13 @@ public: rightclicked = false; leftreleased = false; rightreleased = false; - for(u32 i=0; i