From 81a16c925baac18b2af389b8636401efeae4a64d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 10 Dec 2011 14:21:12 +0900 Subject: [PATCH] Add IMT_DEMO for demo playback bindings. This will allow special key bindings for use during demo playback without interfering with normal keys. --- include/QF/keys.h | 2 ++ libs/video/targets/keys.c | 53 ++++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/include/QF/keys.h b/include/QF/keys.h index ecc208ada..b15e36321 100644 --- a/include/QF/keys.h +++ b/include/QF/keys.h @@ -369,6 +369,7 @@ typedef enum { typedef enum { IMT_CONSOLE, + IMT_DEMO, IMT_MOD, IMT_0, IMT_1, @@ -393,6 +394,7 @@ typedef enum { // key_none should, preferably, be last typedef enum { key_game, + key_demo, key_console, key_message, key_menu, diff --git a/libs/video/targets/keys.c b/libs/video/targets/keys.c index 10160a8a5..f08bebcde 100644 --- a/libs/video/targets/keys.c +++ b/libs/video/targets/keys.c @@ -76,6 +76,7 @@ typedef struct { imtname_t imtnames[] = { {"IMT_CONSOLE", IMT_CONSOLE}, + {"IMT_DEMO", IMT_DEMO}, {"IMT_MOD", IMT_MOD}, {"IMT_0", IMT_0}, {"IMT_1", IMT_1}, @@ -409,6 +410,23 @@ keyname_t keynames[] = { }; +static void +process_binding (knum_t key, const char *kb) +{ + char cmd[1024]; + + if (kb[0] == '+') { + if (keydown[key]) + snprintf (cmd, sizeof (cmd), "%s %d\n", kb, key); + else + snprintf (cmd, sizeof (cmd), "-%s %d\n", kb + 1, key); + } else { + if (!keydown[key]) + return; + snprintf (cmd, sizeof (cmd), "%s\n", kb); + } + Cbuf_AddText (cbuf, cmd); +} /* Key_Game @@ -418,7 +436,6 @@ static qboolean Key_Game (knum_t key, short unicode) { const char *kb; - char cmd[1024]; kb = Key_GetBinding (game_target, key); if (!kb && (game_target > IMT_0)) @@ -436,20 +453,29 @@ Key_Game (knum_t key, short unicode) if (keydown[key] > 1) return true; - if (kb[0] == '+') { - if (keydown[key]) - snprintf (cmd, sizeof (cmd), "%s %d\n", kb, key); - else - snprintf (cmd, sizeof (cmd), "-%s %d\n", kb + 1, key); - } else { - if (!keydown[key]) - return true; - snprintf (cmd, sizeof (cmd), "%s\n", kb); - } - Cbuf_AddText (cbuf, cmd); + process_binding (key, kb); return true; } +/* + Key_Demo + + Interactive line editing and console scrollback +*/ +static void +Key_Demo (knum_t key, short unicode) +{ + const char *kb; + + // escape is un-bindable + if (keydown[key] == 1 && key && Key_Game (key, unicode)) + return; + + kb = Key_GetBinding (IMT_DEMO, key); + if (kb) + process_binding (key, kb); +} + /* Key_Console @@ -851,6 +877,9 @@ Key_Event (knum_t key, short unicode, qboolean down) case key_game: Key_Game (key, unicode); break; + case key_demo: + Key_Demo (key, unicode); + break; case key_message: case key_menu: case key_console: