This commit is contained in:
Christoph Oelckers 2019-10-28 01:12:31 +01:00
parent 113b5d9037
commit e7f75cbf4d
23 changed files with 122 additions and 105 deletions

View file

@ -811,9 +811,9 @@ static void DoQuickSave(void)
void LocalKeys(void)
{
char alt = keystatus[sc_LeftAlt] | keystatus[sc_RightAlt];
char ctrl = keystatus[sc_LeftControl] | keystatus[sc_RightControl];
char shift = keystatus[sc_LeftShift] | keystatus[sc_RightShift];
bool alt = inputState.AltPressed();
bool ctrl = inputState.CtrlPressed();
bool shift = inputState.ShiftPressed();
if (BUTTON(gamefunc_See_Chase_View) && !alt && !shift)
{
CONTROL_ClearButton(gamefunc_See_Chase_View);
@ -877,7 +877,7 @@ void LocalKeys(void)
gPlayerMsg.Send();
}
keyFlushScans();
keystatus[key] = 0;
inputState.ClearKeyStatus(key);
CONTROL_ClearButton(gamefunc_See_Chase_View);
return;
}
@ -1679,7 +1679,7 @@ RESTART:
{
if (handleevents() && quitevent)
{
KB_KeyDown[sc_Escape] = 1;
inputState.SetKeyStatus(sc_Escape, 1);
quitevent = 0;
}
netUpdate();

View file

@ -99,7 +99,7 @@ char DoUnFade(int nTicks)
void credLogosDos(void)
{
char bShift = keystatus[sc_LeftShift] | keystatus[sc_RightShift];
char bShift = inputState.ShiftPressed();
videoSetViewableArea(0, 0, xdim-1, ydim-1);
DoUnFade(1);
videoClearScreen(0);

View file

@ -289,8 +289,6 @@ void CDemo::ProcessKeys(void)
char nKey;
while ((nKey = keyGetScan()) != 0)
{
char UNUSED(alt) = keystatus[0x38] | keystatus[0xb8];
char UNUSED(ctrl) = keystatus[0x1d] | keystatus[0x9d];
switch (nKey)
{
case 1:
@ -333,8 +331,8 @@ _DEMOPLAYBACK:
{
if (handleevents() && quitevent)
{
KB_KeyDown[sc_Escape] = 1;
quitevent = 0;
inputState.SetKeyStatus(sc_Escape, 1);
quitevent = 0;
}
MUSIC_Update();
while (totalclock >= gNetFifoClock && !gQuitGame)

View file

@ -240,7 +240,7 @@ void CGameMenuMgr::Process(void)
event.at0 = kMenuEventEscape;
break;
case sc_Tab:
if (keystatus[sc_LeftShift] || keystatus[sc_RightShift])
if (inputState.ShiftPressed())
event.at0 = kMenuEventUp;
else
event.at0 = kMenuEventDown;
@ -1906,7 +1906,7 @@ bool CGameMenuItemZEdit::Event(CGameMenuEvent &event)
char key;
if (event.at2 < 128)
{
if (keystatus[sc_LeftShift] || keystatus[sc_RightShift])
if (inputState.ShiftPressed())
key = g_keyAsciiTableShift[event.at2];
else
key = g_keyAsciiTable[event.at2];
@ -2099,7 +2099,7 @@ bool CGameMenuItemZEditBitmap::Event(CGameMenuEvent &event)
char key;
if (bScan && event.at2 < 128)
{
if (keystatus[sc_LeftShift] || keystatus[sc_RightShift])
if (inputState.ShiftPressed())
key = g_keyAsciiTableShift[event.at2];
else
key = g_keyAsciiTable[event.at2];

View file

@ -595,9 +595,8 @@ void CPlayerMsg::ProcessKeys(void)
char ch;
if (key != 0)
{
bool UNUSED(alt) = keystatus[sc_LeftAlt] || keystatus[sc_RightAlt];
bool ctrl = keystatus[sc_LeftControl] || keystatus[sc_RightControl];
bool shift = keystatus[sc_LeftShift] || keystatus[sc_RightShift];
bool ctrl = (inputState.CtrlPressed());
bool shift = (inputState.ShiftPressed());
switch (key)
{
case sc_Escape:
@ -616,8 +615,9 @@ void CPlayerMsg::ProcessKeys(void)
CONTROL_ClearButton(gamefunc_See_Chase_View);
Set(*CombatMacros[key-sc_F1]);
Send();
keystatus[key] = 0;
break;
inputState.ClearKeyStatus(key);
}
break;
case sc_BackSpace:
if (ctrl)
Clear();

View file

@ -540,7 +540,7 @@ void netGetPackets(void)
gStartNewGame = 1;
break;
case 255:
keystatus[1] = 1;
inputState.SetKeyStatus(sc_Escape, 1);
break;
}
}
@ -637,8 +637,8 @@ void netWaitForEveryone(char a1)
int p;
do
{
if (keystatus[sc_Escape] && a1)
exit(0);
if (inputState.EscapePressed() && a1)
Bexit(0);
gameHandleEvents();
faketimerhandler();
for (p = connecthead; p >= 0; p = connectpoint2[p])

View file

@ -842,7 +842,8 @@ void GAME_onshowosd(int shown)
// XXX: it's weird to fake a keypress like this.
// if (numplayers == 1 && ((shown && !ud.pause_on) || (!shown && ud.pause_on)))
// KB_KeyDown[sc_Pause] = 1;
// inputState.SetKeyStatus(sc_Escape, 1);
}
void GAME_clearbackground(int numcols, int numrows)

View file

@ -11,6 +11,7 @@
#include "osd.h"
#include "timer.h"
#include "c_cvars.h"
#include "inputstate.h"
#ifdef DEBUGGINGAIDS
@ -88,7 +89,6 @@ vec2_t CONSTEXPR const g_defaultVideoModes []
extern char inputdevices;
// keys
#define NUMKEYS 256
#define KEYFIFOSIZ 64
char CONSTEXPR const g_keyAsciiTable[128] = {
@ -107,7 +107,6 @@ char CONSTEXPR const g_keyAsciiTableShift[128] = {
0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
extern char keystatus[NUMKEYS];
extern char g_keyFIFO[KEYFIFOSIZ];
extern char g_keyAsciiFIFO[KEYFIFOSIZ];
extern uint8_t g_keyAsciiPos;
@ -116,7 +115,6 @@ extern uint8_t g_keyFIFOend;
extern char g_keyRemapTable[NUMKEYS];
extern char g_keyNameTable[NUMKEYS][24];
extern int32_t keyGetState(int32_t key);
extern void keySetState(int32_t key, int32_t state);
// mouse

View file

@ -8,6 +8,7 @@
#include "a.h"
#include "polymost.h"
#include "cache1d.h"
#include "inputstate.h"
#include "../../glbackend/glbackend.h"
// video
@ -24,7 +25,6 @@ int32_t g_borderless=2;
// input
char inputdevices = 0;
char keystatus[NUMKEYS];
char g_keyFIFO[KEYFIFOSIZ];
char g_keyAsciiFIFO[KEYFIFOSIZ];
uint8_t g_keyFIFOpos;
@ -38,11 +38,10 @@ void (*keypresscallback)(int32_t, int32_t);
void keySetCallback(void (*callback)(int32_t, int32_t)) { keypresscallback = callback; }
int32_t keyGetState(int32_t key) { return keystatus[g_keyRemapTable[key]]; }
void keySetState(int32_t key, int32_t state)
{
keystatus[g_keyRemapTable[key]] = state;
inputState.SetKeyStatus(g_keyRemapTable[key], state);
//keystatus[g_keyRemapTable[key]] = state;
if (state)
{

View file

@ -11,6 +11,7 @@
#include "scancodes.h"
#include "common.h"
#include "c_cvars.h"
#include "inputstate.h"
#define XXH_STATIC_LINKING_ONLY
#include "xxhash.h"
@ -1217,7 +1218,7 @@ int OSD_HandleScanCode(uint8_t scanCode, int keyDown)
osddraw_t &draw = osd->draw;
if (scanCode == osd->keycode && (keystatus[sc_LeftShift] || (osd->flags & OSD_CAPTURE) || (osd->flags & OSD_PROTECTED) != OSD_PROTECTED))
if (scanCode == osd->keycode && (inputState.ShiftPressed() || (osd->flags & OSD_CAPTURE) || (osd->flags & OSD_PROTECTED) != OSD_PROTECTED))
{
if (keyDown)
{

View file

@ -28,6 +28,7 @@
#include "resourcefile.h"
#include "sc_man.h"
#include "i_specialpaths.h"
#include "inputstate.h"
#include "c_cvars.h"
#include "../../glbackend/glbackend.h"
@ -2223,7 +2224,7 @@ int32_t handleevents_pollsdl(void)
{
for (j = 0; j < NUMKEYS; ++j)
{
if (keyGetState(j))
if (inputState.GetKeyStatus(j))
{
if (keypresscallback)
keypresscallback(j, 0);
@ -2236,7 +2237,7 @@ int32_t handleevents_pollsdl(void)
if (ev.key.type == SDL_KEYDOWN)
{
if (!keyGetState(code))
if (!inputState.GetKeyStatus(code))
{
if (keypresscallback)
keypresscallback(code, 1);

View file

@ -1,7 +1,19 @@
#pragma once
#include "keyboard.h"
#include "control.h"
#include "scancodes.h"
extern kb_scancode KB_LastScan;
// This encapsulates the entire game-readable input state which previously was spread out across several files.
enum
{
NUMKEYS = 256,
};
// Order is that of EDuke32 by necessity because it exposes the key binds to scripting by index instead of by name.
enum GameFunction_t
{
@ -99,6 +111,8 @@ class InputState
{
FixedBitArray<NUMGAMEFUNCTIONS> ButtonState, ButtonHeldState;
uint8_t KeyStatus[NUMKEYS];
public:
bool BUTTON(int x)
@ -145,6 +159,45 @@ public:
ButtonState.Zero();
}
uint8_t GetKeyStatus(int key)
{
return KeyStatus[key];
}
void SetKeyStatus(int key, int state)
{
KeyStatus[key] = (uint8_t)state;
}
void ClearKeyStatus(int key)
{
KeyStatus[key] = 0;
}
void ClearAllKeyStatus()
{
memset(KeyStatus, 0, sizeof(KeyStatus));
}
bool AltPressed()
{
return KeyStatus[sc_LeftAlt] || KeyStatus[sc_RightAlt];
}
bool CtrlPressed()
{
KeyStatus[sc_LeftControl] || KeyStatus[sc_RightControl];
}
bool ShiftPressed()
{
return KeyStatus[sc_LeftShift] || KeyStatus[sc_RightShift];
}
bool EscapePressed()
{
return !!KeyStatus[sc_Escape];
}
};
@ -175,3 +228,29 @@ inline bool BUTTONSTATECHANGED(int x)
{
return (BUTTON(x) != BUTTONHELD(x));
}
inline uint8_t KB_KeyPressed(int scan)
{
return inputState.GetKeyStatus(scan);
}
inline void KB_ClearKeyDown(int scan)
{
inputState.ClearKeyStatus(scan);
}
inline bool KB_UnBoundKeyPressed(int scan)
{
return (inputState.GetKeyStatus(scan) != 0 && !CONTROL_KeyBinds[scan].cmdstr);
}
inline uint8_t KEY_PRESSED(int scan) // Shadow Warrior uses different names for many things.
{
return inputState.GetKeyStatus(scan);
}
inline void KB_ClearKeysDown(void)
{
KB_LastScan = 0;
inputState.ClearAllKeyStatus();
}

View file

@ -6684,7 +6684,7 @@ MAIN_LOOP_RESTART:
}
ud.warp_on = 0;
KB_KeyDown[sc_Pause] = 0; // JBF: I hate the pause key
inputState.ClearKeyStatus(sc_Pause); // JBF: I hate the pause key
if(g_netClient)
{
@ -6695,8 +6695,8 @@ MAIN_LOOP_RESTART:
{
if (gameHandleEvents() && quitevent)
{
KB_KeyDown[sc_Escape] = 1;
quitevent = 0;
inputState.SetKeyStatus(sc_Escape, 1);
quitevent = 0;
}
// only allow binds to function if the player is actually in a game (not in a menu, typing, et cetera) or demo

View file

@ -4684,9 +4684,6 @@ void Net_WaitForServer(void)
do
{
if (quitevent || keystatus[1])
G_GameExit("");
if (G_FPSLimit())
{
display_betascreen();

View file

@ -113,10 +113,6 @@ void GAME_onshowosd(int shown)
mouseLockToWindow((!shown) + 2);
osdshown = shown;
// XXX: it's weird to fake a keypress like this.
// if (numplayers == 1 && ((shown && !ud.pause_on) || (!shown && ud.pause_on)))
// KB_KeyDown[sc_Pause] = 1;
}

View file

@ -60,7 +60,6 @@ static struct
#define MAXKEYBOARDSCAN 256
#define KB_KeyDown keystatus
extern kb_scancode KB_LastScan;
#define KB_GetLastScanCode() (KB_LastScan)
@ -72,31 +71,19 @@ extern kb_scancode KB_LastScan;
{ \
KB_SetLastScanCode(sc_None); \
}
#define KB_KeyPressed(scan) (keystatus[(scan)] != 0)
#define KB_ClearKeyDown(scan) \
{ \
keystatus[(scan)] = FALSE; \
}
#define KB_UnBoundKeyPressed(scan) (keystatus[(scan)] != 0 && !CONTROL_KeyBinds[scan].cmdstr)
#define KB_GetCh keyGetChar
#define KB_KeyWaiting keyBufferWaiting
#define KB_FlushKeyboardQueue keyFlushChars
#define KB_FlushKeyboardQueueScans keyFlushScans
static inline void KB_ClearKeysDown(void)
{
KB_LastScan = 0;
Bmemset(keystatus, 0, sizeof(keystatus));
}
static inline void KB_KeyEvent(int32_t scancode, int32_t keypressed)
{
if (keypressed)
KB_LastScan = scancode;
}
static inline void KB_Startup(void) { keySetCallback(KB_KeyEvent); }
static inline void KB_Shutdown(void) { keySetCallback((void (*)(int32_t, int32_t))NULL); }
void KB_Startup(void);
void KB_Shutdown(void);
const char * KB_ScanCodeToString( kb_scancode scancode ); // convert scancode into a string
kb_scancode KB_StringToScanCode( const char * string ); // convert a string into a scancode

View file

@ -139,37 +139,6 @@ static void CONTROL_SetFlag(int which, int active)
}
}
#if 0
int32_t CONTROL_KeyboardFunctionPressed(int32_t which)
{
int32_t key1 = 0, key2 = 0;
if (CONTROL_CheckRange(which)) return FALSE;
if (!CONTROL_Flags[which].used) return FALSE;
if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key1].cmdstr)
key1 = KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] ? TRUE : FALSE;
if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key2].cmdstr)
key2 = KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] ? TRUE : FALSE;
return key1 | key2;
}
void CONTROL_ClearKeyboardFunction(int32_t which)
{
if (CONTROL_CheckRange(which)) return;
if (!CONTROL_Flags[which].used) return;
if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED)
KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] = 0;
if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED)
KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] = 0;
}
#endif
void CONTROL_DefineFlag(int which, int toggle)
{

View file

@ -57,3 +57,6 @@ kb_scancode KB_StringToScanCode(const char * string)
return 0;
}
void KB_Startup(void) { keySetCallback(KB_KeyEvent); }
void KB_Shutdown(void) { keySetCallback((void (*)(int32_t, int32_t))NULL); }

View file

@ -8051,14 +8051,14 @@ MAIN_LOOP_RESTART:
}
ud.warp_on = 0;
KB_KeyDown[sc_Pause] = 0; // JBF: I hate the pause key
inputState.ClearKeyStatus(sc_Pause); // JBF: I hate the pause key
do //main loop
{
if (handleevents() && quitevent)
{
KB_KeyDown[sc_Escape] = 1;
quitevent = 0;
inputState.SetKeyStatus(sc_Escape, 1);
quitevent = 0;
}
Net_GetPackets();

View file

@ -168,8 +168,6 @@ void Net_WaitForEverybody(void)
do
{
//if (quitevent || keystatus[sc_Escape]) G_GameExit("");
if (G_FPSLimit())
{
display_betascreen();

View file

@ -126,10 +126,6 @@ void GAME_onshowosd(int32_t shown)
mouseLockToWindow((!shown) + 2);
osdshown = shown;
// XXX: it's weird to fake a keypress like this.
// if (numplayers == 1 && ((shown && !ud.pause_on) || (!shown && ud.pause_on)))
// KB_KeyDown[sc_Pause] = 1;
}

View file

@ -1044,12 +1044,12 @@ ResizeView(PLAYERp pp)
if (dimensionmode == 2 || dimensionmode == 5 || dimensionmode == 6)
{
if (PKEY_PRESSED(KEYSC_DASH)||PKEY_PRESSED(KEYSC_GMINUS))
if (KEY_PRESSED(KEYSC_DASH)||KEY_PRESSED(KEYSC_GMINUS))
{
if ((zoom -= (zoom >> 4)) < 48) zoom = 48;
}
if (PKEY_PRESSED(KEYSC_EQUAL)||PKEY_PRESSED(KEYSC_GPLUS))
if (KEY_PRESSED(KEYSC_EQUAL)||KEY_PRESSED(KEYSC_GPLUS))
{
if ((zoom += (zoom >> 4)) > 4096) zoom = 4096;
}

View file

@ -231,12 +231,6 @@ extern char MessageOutputString[256];
#define KEYSC_EPGUP sc_PgUp
#define KEYSC_EPGDN sc_PgDn
#undef KB_KeyPressed
#define KB_KeyPressed( scan ) \
( KB_KeyDown[( scan )])
#define KEY_PRESSED(sc) KB_KeyPressed((sc))
#define PKEY_PRESSED(sc) KB_KeyPressed((sc))
//
// NETWORK - REDEFINABLE SHARED (SYNC) KEYS BIT POSITIONS
//