-
-
Save xyzz/b7b8e8a85408c52f4a98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/game.h b/src/game.h | |
index b74a7a8..90a1ba6 100644 | |
--- a/src/game.h | |
+++ b/src/game.h | |
@@ -23,60 +23,33 @@ | |
#include "irrlichttypes_extrabloated.h" | |
#include <string> | |
#include "keycode.h" | |
+#include <set> | |
-class KeyList : protected core::list<KeyPress> | |
+class KeyList : protected std::set<KeyPress> | |
{ | |
- typedef core::list<KeyPress> super; | |
- typedef super::Iterator Iterator; | |
- typedef super::ConstIterator ConstIterator; | |
- | |
- virtual ConstIterator find(const KeyPress &key) const | |
- { | |
- ConstIterator f(begin()); | |
- ConstIterator e(end()); | |
- while (f!=e) { | |
- if (*f == key) | |
- return f; | |
- ++f; | |
- } | |
- return e; | |
- } | |
- | |
- virtual Iterator find(const KeyPress &key) | |
- { | |
- Iterator f(begin()); | |
- Iterator e(end()); | |
- while (f!=e) { | |
- if (*f == key) | |
- return f; | |
- ++f; | |
- } | |
- return e; | |
- } | |
public: | |
- void clear() { super::clear(); } | |
- | |
void set(const KeyPress &key) | |
{ | |
- if (find(key) == end()) | |
- push_back(key); | |
+ insert(key); | |
} | |
void unset(const KeyPress &key) | |
{ | |
- Iterator p(find(key)); | |
- if (p != end()) | |
- erase(p); | |
+ erase(key); | |
} | |
void toggle(const KeyPress &key) | |
{ | |
- Iterator p(this->find(key)); | |
- if (p != end()) | |
- erase(p); | |
+ if (find(key) != end()) | |
+ erase(key); | |
else | |
- push_back(key); | |
+ insert(key); | |
+ } | |
+ | |
+ void clear() | |
+ { | |
+ std::set<KeyPress>::clear(); | |
} | |
bool operator[](const KeyPress &key) const | |
diff --git a/src/keycode.h b/src/keycode.h | |
index a0b1e35..2646348 100644 | |
--- a/src/keycode.h | |
+++ b/src/keycode.h | |
@@ -41,6 +41,11 @@ class KeyPress | |
(valid_kcode(Key) && Key == o.Key); | |
} | |
+ bool operator<(const KeyPress &o) const | |
+ { | |
+ return Key < o.Key; | |
+ } | |
+ | |
const char *sym() const; | |
const char *name() const; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment