From 01d5d51f13e39a19b81493818ac0a7462dc52401 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 3 Nov 2019 22:46:01 +0100 Subject: [PATCH] - pass key events to the event queue. --- source/blood/src/messages.cpp | 3 +++ source/build/include/baselayer.h | 3 --- source/build/src/baselayer.cpp | 15 ++++++--------- source/build/src/sdlayer.cpp | 10 ---------- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/source/blood/src/messages.cpp b/source/blood/src/messages.cpp index 0315462ec..0a268165b 100644 --- a/source/blood/src/messages.cpp +++ b/source/blood/src/messages.cpp @@ -585,6 +585,8 @@ void CPlayerMsg::Send(void) void CPlayerMsg::ProcessKeys(void) { + if (KB_KeyPressed(sc_Escape)) Term(); +#if 0 int key = keyGetScan(); int ch; if (key != 0) @@ -635,6 +637,7 @@ void CPlayerMsg::ProcessKeys(void) } sub_5A944(key); } +#endif } bool CPlayerMsg::IsWhitespaceOnly(const char * const pzString) diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index c722cc51a..708daa0f2 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -112,8 +112,6 @@ extern char g_keyAsciiFIFO[KEYFIFOSIZ]; extern uint8_t g_keyAsciiPos; extern uint8_t g_keyAsciiEnd; extern uint8_t g_keyFIFOend; -extern char g_keyRemapTable[NUMKEYS]; -extern char g_keyNameTable[NUMKEYS][24]; extern void keySetState(int32_t key, int32_t state); @@ -178,7 +176,6 @@ void uninitinput(void); void keySetCallback(void (*callback)(int32_t,int32_t)); void mouseSetCallback(void (*callback)(int32_t,int32_t)); void joySetCallback(void (*callback)(int32_t,int32_t)); -const char *keyGetName(int32_t num); const char *joyGetName(int32_t what, int32_t num); // what: 0=axis, 1=button, 2=hat void joyScanDevices(void); diff --git a/source/build/src/baselayer.cpp b/source/build/src/baselayer.cpp index 639a68a19..7758e39b4 100644 --- a/source/build/src/baselayer.cpp +++ b/source/build/src/baselayer.cpp @@ -9,6 +9,7 @@ #include "polymost.h" #include "cache1d.h" #include "inputstate.h" +#include "d_event.h" #include "../../glbackend/glbackend.h" // video @@ -31,8 +32,6 @@ uint8_t g_keyFIFOpos; uint8_t g_keyFIFOend; uint8_t g_keyAsciiPos; uint8_t g_keyAsciiEnd; -char g_keyRemapTable[NUMKEYS]; -char g_keyNameTable[NUMKEYS][24]; void (*keypresscallback)(int32_t, int32_t); @@ -40,12 +39,14 @@ void keySetCallback(void (*callback)(int32_t, int32_t)) { keypresscallback = cal void keySetState(int32_t key, int32_t state) { - inputState.SetKeyStatus(g_keyRemapTable[key], state); - //keystatus[g_keyRemapTable[key]] = state; + inputState.SetKeyStatus(key, state); + event_t ev = { (uint8_t)(state ? EV_KeyDown : EV_KeyUp), 0, (uint16_t)key }; + + D_PostEvent(&ev); if (state) { - g_keyFIFO[g_keyFIFOend] = g_keyRemapTable[key]; + g_keyFIFO[g_keyFIFOend] = key; g_keyFIFO[(g_keyFIFOend+1)&(KEYFIFOSIZ-1)] = state; g_keyFIFOend = ((g_keyFIFOend+2)&(KEYFIFOSIZ-1)); } @@ -88,8 +89,6 @@ void keyFlushChars(void) g_keyAsciiPos = g_keyAsciiEnd = 0; } -const char *keyGetName(int32_t num) { return ((unsigned)num >= NUMKEYS) ? NULL : g_keyNameTable[num]; } - vec2_t g_mousePos; vec2_t g_mouseAbs; int32_t g_mouseBits; @@ -263,8 +262,6 @@ int32_t baselayer_init(void) polymost_initosdfuncs(); #endif - for (native_t i = 0; i < NUMKEYS; i++) g_keyRemapTable[i] = i; - return 0; } diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 312dad131..2c7551e4f 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -907,16 +907,6 @@ int32_t initinput(void) inputdevices = 1 | 2; // keyboard (1) and mouse (2) g_mouseGrabbed = 0; - memset(g_keyNameTable, 0, sizeof(g_keyNameTable)); - - for (i = SDL_NUM_SCANCODES - 1; i >= 0; i--) - { - if (!keytranslation[i]) - continue; - - Bstrncpyz(g_keyNameTable[keytranslation[i]], SDL_GetKeyName(SDL_SCANCODE_TO_KEYCODE(i)), sizeof(g_keyNameTable[0])); - } - if (!SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)) { LoadSDLControllerDB();