From 3c1377fe47cd0d63eb9d27603f83b0b416eab2d1 Mon Sep 17 00:00:00 2001 From: "jean.chalard" Date: Thu, 18 Feb 2010 07:18:21 +0000 Subject: [PATCH] J : * Re-add the ReadLocalKey function that I had forgotten to re-implement with the key bindings. --- JGE/include/JGE.h | 7 ++++++- JGE/src/JGE.cpp | 26 +++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/JGE/include/JGE.h b/JGE/include/JGE.h index 2977184f2..a17754eed 100644 --- a/JGE/include/JGE.h +++ b/JGE/include/JGE.h @@ -28,11 +28,15 @@ #if defined(WIN32) #include typedef WPARAM LocalKeySym; +#define LOCAL_NO_KEY ((WPARAM)-1) #elif defined(LINUX) #include +#include typedef KeySym LocalKeySym; +#define LOCAL_NO_KEY XK_VoidSymbol #else typedef u32 LocalKeySym; +#define LOCAL_NO_KEY ((u32)-1) #endif @@ -97,7 +101,7 @@ class JGE static JGE* mInstance; - static std::queue keyBuffer; + static std::queue< std::pair > keyBuffer; static std::multimap keyBinds; typedef std::multimap::iterator keycodes_it; @@ -171,6 +175,7 @@ class JGE /// @return Next pressed button, or 0 if none. ////////////////////////////////////////////////////////////////////////// JButton ReadButton(); + LocalKeySym ReadLocalKey(); ////////////////////////////////////////////////////////////////////////// /// Bind an actual key to a symbolic button. A key can be bound to diff --git a/JGE/src/JGE.cpp b/JGE/src/JGE.cpp index 63b689b4d..45b2b202d 100644 --- a/JGE/src/JGE.cpp +++ b/JGE/src/JGE.cpp @@ -79,18 +79,18 @@ void JGE::PressKey(const LocalKeySym sym) { const pair rng = keyBinds.equal_range(sym); for (keycodes_it it = rng.first; it != rng.second; ++it) - keyBuffer.push(it->second); + keyBuffer.push(*it); } void JGE::PressKey(const JButton sym) { - keyBuffer.push(sym); + keyBuffer.push(make_pair(LOCAL_NO_KEY, sym)); } void JGE::HoldKey(const LocalKeySym sym) { const pair rng = keyBinds.equal_range(sym); for (keycodes_it it = rng.first; it != rng.second; ++it) { - keyBuffer.push(it->second); + keyBuffer.push(*it); if (holds.end() == holds.find(it->second)) holds[it->second] = REPEAT_DELAY; } @@ -100,19 +100,19 @@ void JGE::HoldKey_NoRepeat(const LocalKeySym sym) const pair rng = keyBinds.equal_range(sym); for (keycodes_it it = rng.first; it != rng.second; ++it) { - keyBuffer.push(it->second); + keyBuffer.push(*it); if (holds.end() == holds.find(it->second)) holds[it->second] = std::numeric_limits::quiet_NaN(); } } void JGE::HoldKey(const JButton sym) { - keyBuffer.push(sym); + keyBuffer.push(make_pair(LOCAL_NO_KEY, sym)); if (holds.end() == holds.find(sym)) holds[sym] = REPEAT_DELAY; } void JGE::HoldKey_NoRepeat(const JButton sym) { - keyBuffer.push(sym); + keyBuffer.push(make_pair(LOCAL_NO_KEY, sym)); if (holds.end() == holds.find(sym)) holds[sym] = std::numeric_limits::quiet_NaN(); } void JGE::ReleaseKey(const LocalKeySym sym) @@ -129,7 +129,7 @@ void JGE::Update(float dt) { for (map::iterator it = holds.begin(); it != holds.end(); ++it) { - if (it->second < 0) { keyBuffer.push(it->first); it->second = REPEAT_PERIOD; } + if (it->second < 0) { keyBuffer.push(make_pair(LOCAL_NO_KEY, it->first)); it->second = REPEAT_PERIOD; } it->second -= dt; } if (mApp != NULL) mApp->Update(); @@ -152,7 +152,15 @@ bool JGE::GetButtonClick(JButton button) JButton JGE::ReadButton() { if (keyBuffer.empty()) return JGE_BTN_NONE; - JButton val = keyBuffer.front(); + JButton val = keyBuffer.front().second; + keyBuffer.pop(); + return val; +} + +LocalKeySym JGE::ReadLocalKey() +{ + if (keyBuffer.empty()) return LOCAL_NO_KEY; + LocalKeySym val = keyBuffer.front().first; keyBuffer.pop(); return val; } @@ -440,5 +448,5 @@ void JGE::Assert(const char *filename, long lineNumber) } -std::queue JGE::keyBuffer; +std::queue< pair > JGE::keyBuffer; std::multimap JGE::keyBinds;