From 80fdb0a38fea7d56fb7406ac8c0f21ef78720b95 Mon Sep 17 00:00:00 2001 From: "jean.chalard" Date: Fri, 26 Feb 2010 03:08:20 +0000 Subject: [PATCH] J : * Mostly fix issue 340. * There are still detail problems : - There are still problems when two keys are pressed at the same time. This is not a release blocker ; what happens exactly is : while maintaining two keys, when one is released, the enqueued autorepeat keypresses for the others are flushed too. I don't think anyone will notice but for the sake of correctness I'll fix it. - A bug in xorg prevents the linux version to work correctly at the moment. The bug is current as of 2009/08 and fixed as of 2010/01, but major releases still include the bug at this time, so I'll have to work around it somehow. - I expect the windows version to work, but I can't test it. - I'll test on mac later today. --- JGE/src/JGE.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/JGE/src/JGE.cpp b/JGE/src/JGE.cpp index d12b5affd..16af06b4c 100644 --- a/JGE/src/JGE.cpp +++ b/JGE/src/JGE.cpp @@ -68,7 +68,7 @@ static map oldHolds; #define REPEAT_DELAY 0.5 #define REPEAT_PERIOD 0.07 -static inline bool held(const JButton sym) { return holds.end() == holds.find(sym); } +static inline bool held(const JButton sym) { return holds.end() != holds.find(sym); } static inline pair, bool> triplet(LocalKeySym k, JButton b, bool h) { return make_pair(make_pair(k, b), h); } static inline pair, bool> triplet(pair p, bool h) { return make_pair(p, h); } @@ -91,12 +91,12 @@ void JGE::HoldKey(const LocalKeySym sym) keyBuffer.push(triplet(sym, JGE_BTN_NONE, false)); else for (keycodes_it it = rng.first; it != rng.second; ++it) { - if (held(it->second)) + if (!held(it->second)) { - keyBuffer.push(triplet(*it, true)); + keyBuffer.push(triplet(*it, false)); holds[it->second] = REPEAT_DELAY; } - else keyBuffer.push(triplet(*it, false)); + else keyBuffer.push(triplet(*it, true)); } } void JGE::HoldKey_NoRepeat(const LocalKeySym sym) @@ -106,31 +106,25 @@ void JGE::HoldKey_NoRepeat(const LocalKeySym sym) keyBuffer.push(triplet(sym, JGE_BTN_NONE, false)); else for (keycodes_it it = rng.first; it != rng.second; ++it) { - if (held(it->second)) - { - keyBuffer.push(triplet(*it, false)); - holds[it->second] = std::numeric_limits::quiet_NaN(); - } - else keyBuffer.push(triplet(*it, false)); + keyBuffer.push(triplet(*it, true)); + if (!held(it->second)) + holds[it->second] = std::numeric_limits::quiet_NaN(); } } void JGE::HoldKey(const JButton sym) { - if (held(sym)) + if (!held(sym)) { - keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true)); + keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, false)); holds[sym] = REPEAT_DELAY; } - else keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, false)); + else keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true)); } void JGE::HoldKey_NoRepeat(const JButton sym) { - if (held(sym)) - { - keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true)); - holds[sym] = std::numeric_limits::quiet_NaN(); - } - else keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, false)); + keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true)); + if (!held(sym)) + holds[sym] = std::numeric_limits::quiet_NaN(); } void JGE::ReleaseKey(const LocalKeySym sym) { @@ -138,20 +132,26 @@ void JGE::ReleaseKey(const LocalKeySym sym) for (keycodes_it it = rng.first; it != rng.second; ++it) holds.erase(it->second); - /* queue< pair, bool> > r; while (!keyBuffer.empty()) { pair, bool> q = keyBuffer.front(); keyBuffer.pop(); - if ((q.first.first != sym)) r.push(q); + if ((!q.second)) r.push(q); } keyBuffer = r; - */ } void JGE::ReleaseKey(const JButton sym) { holds.erase(sym); + queue< pair, bool> > r; + while (!keyBuffer.empty()) + { + pair, bool> q = keyBuffer.front(); + keyBuffer.pop(); + if ((!q.second) || (q.first.second != sym)) r.push(q); + } + keyBuffer = r; } void JGE::Update(float dt) {