aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/inputhandler.cpp75
-rw-r--r--src/client/inputhandler.h31
2 files changed, 106 insertions, 0 deletions
diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp
index 48b94ae95..3b01f5d93 100644
--- a/src/client/inputhandler.cpp
+++ b/src/client/inputhandler.cpp
@@ -22,6 +22,81 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "inputhandler.h"
#include "gui/mainmenumanager.h"
+void KeyCache::populate_nonchanging()
+{
+ key[KeyType::ESC] = EscapeKey;
+}
+
+void KeyCache::populate()
+{
+ key[KeyType::FORWARD] = getKeySetting("keymap_forward");
+ key[KeyType::BACKWARD] = getKeySetting("keymap_backward");
+ key[KeyType::LEFT] = getKeySetting("keymap_left");
+ key[KeyType::RIGHT] = getKeySetting("keymap_right");
+ key[KeyType::JUMP] = getKeySetting("keymap_jump");
+ key[KeyType::SPECIAL1] = getKeySetting("keymap_special1");
+ key[KeyType::SNEAK] = getKeySetting("keymap_sneak");
+
+ key[KeyType::AUTOFORWARD] = getKeySetting("keymap_autoforward");
+
+ key[KeyType::DROP] = getKeySetting("keymap_drop");
+ key[KeyType::INVENTORY] = getKeySetting("keymap_inventory");
+ key[KeyType::CHAT] = getKeySetting("keymap_chat");
+ key[KeyType::CMD] = getKeySetting("keymap_cmd");
+ key[KeyType::CMD_LOCAL] = getKeySetting("keymap_cmd_local");
+ key[KeyType::CONSOLE] = getKeySetting("keymap_console");
+ key[KeyType::MINIMAP] = getKeySetting("keymap_minimap");
+ key[KeyType::FREEMOVE] = getKeySetting("keymap_freemove");
+ key[KeyType::FASTMOVE] = getKeySetting("keymap_fastmove");
+ key[KeyType::NOCLIP] = getKeySetting("keymap_noclip");
+ key[KeyType::HOTBAR_PREV] = getKeySetting("keymap_hotbar_previous");
+ key[KeyType::HOTBAR_NEXT] = getKeySetting("keymap_hotbar_next");
+ key[KeyType::MUTE] = getKeySetting("keymap_mute");
+ key[KeyType::INC_VOLUME] = getKeySetting("keymap_increase_volume");
+ key[KeyType::DEC_VOLUME] = getKeySetting("keymap_decrease_volume");
+ key[KeyType::CINEMATIC] = getKeySetting("keymap_cinematic");
+ key[KeyType::SCREENSHOT] = getKeySetting("keymap_screenshot");
+ key[KeyType::TOGGLE_HUD] = getKeySetting("keymap_toggle_hud");
+ key[KeyType::TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat");
+ key[KeyType::TOGGLE_FORCE_FOG_OFF]
+ = getKeySetting("keymap_toggle_force_fog_off");
+ key[KeyType::TOGGLE_UPDATE_CAMERA]
+ = getKeySetting("keymap_toggle_update_camera");
+ key[KeyType::TOGGLE_DEBUG]
+ = getKeySetting("keymap_toggle_debug");
+ key[KeyType::TOGGLE_PROFILER]
+ = getKeySetting("keymap_toggle_profiler");
+ key[KeyType::CAMERA_MODE]
+ = getKeySetting("keymap_camera_mode");
+ key[KeyType::INCREASE_VIEWING_RANGE]
+ = getKeySetting("keymap_increase_viewing_range_min");
+ key[KeyType::DECREASE_VIEWING_RANGE]
+ = getKeySetting("keymap_decrease_viewing_range_min");
+ key[KeyType::RANGESELECT]
+ = getKeySetting("keymap_rangeselect");
+ key[KeyType::ZOOM] = getKeySetting("keymap_zoom");
+
+ key[KeyType::QUICKTUNE_NEXT] = getKeySetting("keymap_quicktune_next");
+ key[KeyType::QUICKTUNE_PREV] = getKeySetting("keymap_quicktune_prev");
+ key[KeyType::QUICKTUNE_INC] = getKeySetting("keymap_quicktune_inc");
+ key[KeyType::QUICKTUNE_DEC] = getKeySetting("keymap_quicktune_dec");
+
+ for (int i = 0; i < 23; i++) {
+ std::string slot_key_name = "keymap_slot" + std::to_string(i + 1);
+ key[KeyType::SLOT_1 + i] = getKeySetting(slot_key_name.c_str());
+ }
+
+ if (handler) {
+ // First clear all keys, then re-add the ones we listen for
+ handler->dontListenForKeys();
+ for (const KeyPress &k : key) {
+ handler->listenForKey(k);
+ }
+ handler->listenForKey(EscapeKey);
+ handler->listenForKey(CancelKey);
+ }
+}
+
bool MyEventReceiver::OnEvent(const SEvent &event)
{
/*
diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h
index c7c29510d..91c111134 100644
--- a/src/client/inputhandler.h
+++ b/src/client/inputhandler.h
@@ -29,6 +29,37 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gui/touchscreengui.h"
#endif
+class InputHandler;
+
+/****************************************************************************
+ Fast key cache for main game loop
+ ****************************************************************************/
+
+/* This is faster than using getKeySetting with the tradeoff that functions
+ * using it must make sure that it's initialised before using it and there is
+ * no error handling (for example bounds checking). This is really intended for
+ * use only in the main running loop of the client (the_game()) where the faster
+ * (up to 10x faster) key lookup is an asset. Other parts of the codebase
+ * (e.g. formspecs) should continue using getKeySetting().
+ */
+struct KeyCache {
+
+ KeyCache()
+ {
+ handler = NULL;
+ populate();
+ populate_nonchanging();
+ }
+
+ void populate();
+
+ // Keys that are not settings dependent
+ void populate_nonchanging();
+
+ KeyPress key[KeyType::INTERNAL_ENUM_COUNT];
+ InputHandler *handler;
+};
+
class KeyList : private std::list<KeyPress>
{
typedef std::list<KeyPress> super;