Change how backend keyboard status stuff works

This commit is contained in:
Clownacy 2020-04-05 13:26:08 +01:00
parent aef0f81f28
commit eaef25d5da
4 changed files with 23 additions and 10 deletions

View file

@ -20,12 +20,12 @@
#define DO_KEY(GLFW_KEY, BACKEND_KEY) \ #define DO_KEY(GLFW_KEY, BACKEND_KEY) \
case GLFW_KEY: \ case GLFW_KEY: \
backend_keyboard_state[BACKEND_KEY] = action == GLFW_PRESS; \ keyboard_state[BACKEND_KEY] = action == GLFW_PRESS; \
break; break;
BOOL bActive = TRUE; BOOL bActive = TRUE;
BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL];
BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; static BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
static GLFWcursor* cursor; static GLFWcursor* cursor;
@ -272,6 +272,11 @@ BOOL Backend_SystemTask(void)
return TRUE; return TRUE;
} }
void Backend_GetKeyboardState(BOOL *out_keyboard_state)
{
memcpy(out_keyboard_state, keyboard_state, sizeof(keyboard_state));
}
void Backend_ShowMessageBox(const char *title, const char *message) void Backend_ShowMessageBox(const char *title, const char *message)
{ {
// GLFW3 doesn't have a message box // GLFW3 doesn't have a message box

View file

@ -84,7 +84,6 @@ enum
}; };
extern BOOL bActive; extern BOOL bActive;
extern BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL];
void Backend_Init(void); void Backend_Init(void);
void Backend_Deinit(void); void Backend_Deinit(void);
@ -95,6 +94,7 @@ void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width,
void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
void PlaybackBackend_EnableDragAndDrop(void); void PlaybackBackend_EnableDragAndDrop(void);
BOOL Backend_SystemTask(void); BOOL Backend_SystemTask(void);
void Backend_GetKeyboardState(BOOL *keyboard_state);
void Backend_ShowMessageBox(const char *title, const char *message); void Backend_ShowMessageBox(const char *title, const char *message);
unsigned long Backend_GetTicks(void); unsigned long Backend_GetTicks(void);
void Backend_Delay(unsigned int ticks); void Backend_Delay(unsigned int ticks);

View file

@ -18,12 +18,12 @@
#define DO_KEY(SDL_KEY, BACKEND_KEY) \ #define DO_KEY(SDL_KEY, BACKEND_KEY) \
case SDL_KEY: \ case SDL_KEY: \
backend_keyboard_state[BACKEND_KEY] = event.key.type == SDL_KEYDOWN; \ keyboard_state[BACKEND_KEY] = event.key.type == SDL_KEYDOWN; \
break; break;
BOOL bActive = TRUE; BOOL bActive = TRUE;
BOOL backend_keyboard_state[BACKEND_KEYBOARD_TOTAL];
BOOL backend_previous_keyboard_state[BACKEND_KEYBOARD_TOTAL]; static BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
static SDL_Surface *cursor_surface; static SDL_Surface *cursor_surface;
static SDL_Cursor *cursor; static SDL_Cursor *cursor;
@ -238,6 +238,11 @@ BOOL Backend_SystemTask(void)
return TRUE; return TRUE;
} }
void Backend_GetKeyboardState(BOOL *out_keyboard_state)
{
memcpy(out_keyboard_state, keyboard_state, sizeof(keyboard_state));
}
void Backend_ShowMessageBox(const char *title, const char *message) void Backend_ShowMessageBox(const char *title, const char *message)
{ {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window);

View file

@ -390,9 +390,12 @@ BOOL SystemTask(void)
if (!Backend_SystemTask()) if (!Backend_SystemTask())
return FALSE; return FALSE;
BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
Backend_GetKeyboardState(keyboard_state);
for (unsigned int i = 0; i < BACKEND_KEYBOARD_TOTAL; ++i) for (unsigned int i = 0; i < BACKEND_KEYBOARD_TOTAL; ++i)
{ {
if (backend_keyboard_state[i] && !previous_keyboard_state[i]) if (keyboard_state[i] && !previous_keyboard_state[i])
{ {
switch (i) switch (i)
{ {
@ -478,7 +481,7 @@ BOOL SystemTask(void)
break; break;
} }
} }
else if (!backend_keyboard_state[i] && previous_keyboard_state[i]) else if (!keyboard_state[i] && previous_keyboard_state[i])
{ {
switch (i) switch (i)
{ {
@ -562,7 +565,7 @@ BOOL SystemTask(void)
} }
} }
memcpy(previous_keyboard_state, backend_keyboard_state, sizeof(backend_keyboard_state)); memcpy(previous_keyboard_state, keyboard_state, sizeof(keyboard_state));
// Run joystick code // Run joystick code
if (gbUseJoystick) if (gbUseJoystick)