summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-05-14 16:25:57 +0200
committerest31 <MTest31@outlook.com>2016-05-26 20:33:33 +0200
commitfa6b21a15b415cd82dce6896b94a5341b7dd76f0 (patch)
tree1fc68b1ebb2ce52c81b33e816b0f8f8f827d47a7 /src/client
parentef100f12a1346f7bfd2a05dc606cb22e97179c02 (diff)
downloadminetest-fa6b21a15b415cd82dce6896b94a5341b7dd76f0.tar.gz
minetest-fa6b21a15b415cd82dce6896b94a5341b7dd76f0.tar.bz2
minetest-fa6b21a15b415cd82dce6896b94a5341b7dd76f0.zip
Tell irrlicht if we handle a key or not.
We can remove the function in MtNativeActivity now as it serves precisely that purpose: to tell irrlicht that we handled the esc key. TODO for later: * Perhaps try to find a more performant container than KeyList
Diffstat (limited to 'src/client')
-rw-r--r--src/client/inputhandler.h37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h
index 69e4b25fa..73e507fdc 100644
--- a/src/client/inputhandler.h
+++ b/src/client/inputhandler.h
@@ -42,11 +42,15 @@ public:
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
- if (event.KeyInput.PressedDown) {
- keyIsDown.set(event.KeyInput);
- keyWasDown.set(event.KeyInput);
- } else {
- keyIsDown.unset(event.KeyInput);
+ const KeyPress &keyCode = event.KeyInput;
+ if (keysListenedFor[keyCode]) {
+ if (event.KeyInput.PressedDown) {
+ keyIsDown.set(keyCode);
+ keyWasDown.set(keyCode);
+ } else {
+ keyIsDown.unset(keyCode);
+ }
+ return true;
}
}
@@ -116,6 +120,15 @@ public:
return b;
}
+ void listenForKey(const KeyPress &keyCode)
+ {
+ keysListenedFor.set(keyCode);
+ }
+ void dontListenForKeys()
+ {
+ keysListenedFor.clear();
+ }
+
s32 getMouseWheel()
{
s32 a = mouse_wheel;
@@ -168,6 +181,12 @@ private:
KeyList keyIsDown;
// Whether a key has been pressed or not
KeyList keyWasDown;
+ // List of keys we listen for
+ // TODO perhaps the type of this is not really
+ // performant as KeyList is designed for few but
+ // often changing keys, and keysListenedFor is expected
+ // to change seldomly but contain lots of keys.
+ KeyList keysListenedFor;
};
@@ -192,6 +211,14 @@ public:
{
return m_receiver->WasKeyDown(keyCode);
}
+ virtual void listenForKey(const KeyPress &keyCode)
+ {
+ m_receiver->listenForKey(keyCode);
+ }
+ virtual void dontListenForKeys()
+ {
+ m_receiver->dontListenForKeys();
+ }
virtual v2s32 getMousePos()
{
if (m_device->getCursorControl()) {