diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2018-01-13 10:40:25 +0100 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-01-20 16:38:38 +0100 |
commit | f5a006dce7896d9241b7d21df77825c1c5decc88 (patch) | |
tree | db07e94cead6a387e1aaa28a0528cfadecff1974 /src/client/inputhandler.h | |
parent | 64fe79b53b03b80b5a3636dfe0d3a2d325306301 (diff) | |
download | dragonfireclient-f5a006dce7896d9241b7d21df77825c1c5decc88.tar.xz |
Game refactor [3/X]: Move keycache to inputhandler
Diffstat (limited to 'src/client/inputhandler.h')
-rw-r--r-- | src/client/inputhandler.h | 31 |
1 files changed, 31 insertions, 0 deletions
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; |