Added key/bind names to controls menu

This commit is contained in:
MysterD 2022-01-20 21:46:22 -08:00
parent 511e7c5028
commit 05999a9ae8
14 changed files with 201 additions and 169 deletions

View file

@ -89,7 +89,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;WINSOCK;DEBUG;CAPI_SDL2;WAPI_SDL2;RAPI_GL;F3DEX_GBI_2;_LANGUAGE_C;BETTERCAMERA;VERSION_US;EXT_OPTIONS_MENU;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;WINSOCK;DEBUG;CAPI_SDL2;WAPI_SDL2;RAPI_GL;F3DEX_GBI_2;_LANGUAGE_C;BETTERCAMERA;VERSION_US;EXT_OPTIONS_MENU;HAVE_SDL2;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
@ -3936,6 +3936,7 @@
<ClCompile Include="..\src\pc\cheats.c" />
<ClCompile Include="..\src\pc\cliopts.c" />
<ClCompile Include="..\src\pc\configfile.c" />
<ClCompile Include="..\src\pc\controller\controller_bind_mapping.c" />
<ClCompile Include="..\src\pc\controller\controller_emscripten_keyboard.c" />
<ClCompile Include="..\src\pc\controller\controller_entry_point.c" />
<ClCompile Include="..\src\pc\controller\controller_keyboard.c" />
@ -4394,6 +4395,7 @@
<ClInclude Include="..\include\luigi_audio_defines.h" />
<ClInclude Include="..\src\game\characters.h" />
<ClInclude Include="..\src\game\rng_position.h" />
<ClInclude Include="..\src\pc\controller\controller_bind_mapping.h" />
<ClInclude Include="..\src\pc\controller\controller_keyboard_debug.h" />
<ClInclude Include="..\src\pc\debuglog.h" />
<ClInclude Include="..\src\pc\djui\djui.h" />

View file

@ -15288,6 +15288,9 @@
<ClCompile Include="..\src\pc\network\packets\packet_debug_sync.c">
<Filter>Source Files\src\pc\network\packets</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\controller\controller_bind_mapping.c">
<Filter>Source Files\src\pc\controller</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\actors\common0.h">
@ -16387,5 +16390,8 @@
<ClInclude Include="..\actors\custom0.h">
<Filter>Header Files\actors</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\controller\controller_bind_mapping.h">
<Filter>Source Files\src\pc\controller</Filter>
</ClInclude>
</ItemGroup>
</Project>

1
developer/sdl1.sh Normal file
View file

@ -0,0 +1 @@
make RENDER_API=GL WINDOW_API=SDL1 AUDIO_API=SDL1 CONTROLLER_API=SDL1 BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 DEVELOPMENT=1 && ./build/us_pc/sm64.us.f3dex2e.exe

View file

@ -0,0 +1,151 @@
#ifdef HAVE_SDL2
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h>
#endif
#include "controller_bind_mapping.h"
#include "controller_api.h"
#include "controller_sdl.h"
static int inverted_scancode_table[512];
static SDL_Scancode bind_to_sdl_scancode[512] = { 0 };
const SDL_Scancode windows_scancode_table[] = {
/* 0 1 2 3 4 5 6 7 */
/* 8 9 A B C D E F */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, /* 0 */
SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, /* 0 */
SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, /* 1 */
SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, /* 1 */
SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, /* 2 */
SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, /* 2 */
SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,/* 3 */
SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, /* 3 */
SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, /* 4 */
SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, /* 4 */
SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH, SDL_SCANCODE_F11, /* 5 */
SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 5 */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_F16, /* 6 */
SDL_SCANCODE_F17, SDL_SCANCODE_F18, SDL_SCANCODE_F19, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 6 */
SDL_SCANCODE_INTERNATIONAL2, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL1, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 7 */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL4, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL5, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL3, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN /* 7 */
};
const SDL_Scancode scancode_rmapping_extended[][2] = {
{SDL_SCANCODE_KP_ENTER, SDL_SCANCODE_RETURN},
{SDL_SCANCODE_RALT, SDL_SCANCODE_LALT},
{SDL_SCANCODE_RCTRL, SDL_SCANCODE_LCTRL},
{SDL_SCANCODE_KP_DIVIDE, SDL_SCANCODE_SLASH},
//{SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_CAPSLOCK}
};
const SDL_Scancode scancode_rmapping_nonextended[][2] = {
{SDL_SCANCODE_KP_7, SDL_SCANCODE_HOME},
{SDL_SCANCODE_KP_8, SDL_SCANCODE_UP},
{SDL_SCANCODE_KP_9, SDL_SCANCODE_PAGEUP},
{SDL_SCANCODE_KP_4, SDL_SCANCODE_LEFT},
{SDL_SCANCODE_KP_6, SDL_SCANCODE_RIGHT},
{SDL_SCANCODE_KP_1, SDL_SCANCODE_END},
{SDL_SCANCODE_KP_2, SDL_SCANCODE_DOWN},
{SDL_SCANCODE_KP_3, SDL_SCANCODE_PAGEDOWN},
{SDL_SCANCODE_KP_0, SDL_SCANCODE_INSERT},
{SDL_SCANCODE_KP_PERIOD, SDL_SCANCODE_DELETE},
{SDL_SCANCODE_KP_MULTIPLY, SDL_SCANCODE_PRINTSCREEN}
};
void controller_bind_init(void) {
for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) {
inverted_scancode_table[windows_scancode_table[i]] = i;
}
for (size_t i = 0; i < sizeof(scancode_rmapping_extended) / sizeof(scancode_rmapping_extended[0]); i++) {
inverted_scancode_table[scancode_rmapping_extended[i][0]] = inverted_scancode_table[scancode_rmapping_extended[i][1]] + 0x100;
}
for (size_t i = 0; i < sizeof(scancode_rmapping_nonextended) / sizeof(scancode_rmapping_nonextended[0]); i++) {
inverted_scancode_table[scancode_rmapping_nonextended[i][0]] = inverted_scancode_table[scancode_rmapping_nonextended[i][1]];
inverted_scancode_table[scancode_rmapping_nonextended[i][1]] += 0x100;
}
for (size_t i = 0; i < 512; i++) {
if (inverted_scancode_table[i] >= 512) { continue; }
bind_to_sdl_scancode[inverted_scancode_table[i]] = i;
}
}
int translate_sdl_scancode(int scancode) {
if (scancode < 512) {
return inverted_scancode_table[scancode];
}
else {
return 0;
}
}
const char* translate_bind_to_name(int bind) {
static char name[11] = { 0 };
sprintf(name, "%04X", bind);
if (bind == VK_INVALID) { return ""; }
// mouse
if (bind >= VK_BASE_SDL_MOUSE) {
int mouse_button = (bind - VK_BASE_SDL_MOUSE);
if (mouse_button == 1) { return "L Mouse"; }
if (mouse_button == 2) { return "M Mouse"; }
if (mouse_button == 3) { return "R Mouse"; }
snprintf(name, 8, "Mouse %d", bind - VK_BASE_SDL_MOUSE);
return name;
}
// gamepad
if (bind >= VK_BASE_SDL_GAMEPAD) {
int gamepad_button = (bind - VK_BASE_SDL_GAMEPAD);
switch (gamepad_button) {
case 0: return "[A]";
case 1: return "[B]";
case 2: return "[X]";
case 3: return "[Y]";
case 4: return "[Back]";
case 5: return "[Guide]";
case 6: return "[Start]";
case 7: return "[L Stick]";
case 8: return "[R Stick]";
case 9: return "[L Bump]";
case 10: return "[R Bump]";
case 11: return "[DPAD Up]";
case 12: return "[DPAD Down]";
case 13: return "[DPAD Left]";
case 14: return "[DPAD Right]";
case 0x1A: return "[L Trig]";
case 0x1B: return "[R Trig]";
default: return name;
}
}
// keyboard
if (bind >= 512) { return name; }
SDL_Scancode sc = bind_to_sdl_scancode[bind];
if (sc == 0) { return name; }
#ifdef HAVE_SDL2
const char* sname = SDL_GetScancodeName(sc);
if (strlen(sname) <= 9) { return sname; }
char* space = strchr(sname, ' ');
if (space == NULL) { return sname; }
sprintf_s(name, 10, "%c%s", sname[0], (space + 1));
#endif
return name;
}

View file

@ -0,0 +1,8 @@
#ifndef CONTROLLER_BIND_MAPPING_H
#define CONTROLLER_BIND_MAPPING_H
void controller_bind_init(void);
int translate_sdl_scancode(int scancode);
const char* translate_bind_to_name(int bind);
#endif

View file

@ -5,6 +5,10 @@
#define VK_BASE_SDL_GAMEPAD 0x1000
// mouse buttons are also in the controller namespace (why), just offset 0x100
#define VK_OFS_SDL_MOUSE 0x0100
#define VK_BASE_SDL_MOUSE (VK_BASE_SDL_GAMEPAD + VK_OFS_SDL_MOUSE)
extern struct ControllerAPI controller_sdl;
void controller_sdl_read_mouse_window(void);

View file

@ -26,9 +26,6 @@
#include "pc/djui/djui.h"
// mouse buttons are also in the controller namespace (why), just offset 0x100
#define VK_OFS_SDL_MOUSE 0x0100
#define VK_BASE_SDL_MOUSE (VK_BASE_SDL_GAMEPAD + VK_OFS_SDL_MOUSE)
#define MAX_JOYBINDS 32
#define MAX_MOUSEBUTTONS 8 // arbitrary
#define MAX_JOYBUTTONS 32 // arbitrary; includes virtual keys for triggers

View file

@ -26,9 +26,6 @@
#include "pc/djui/djui.h"
// mouse buttons are also in the controller namespace (why), just offset 0x100
#define VK_OFS_SDL_MOUSE 0x0100
#define VK_BASE_SDL_MOUSE (VK_BASE_SDL_GAMEPAD + VK_OFS_SDL_MOUSE)
#define MAX_JOYBINDS 32
#define MAX_MOUSEBUTTONS 8 // arbitrary
#define MAX_JOYBUTTONS 32 // arbitrary; includes virtual keys for triggers

View file

@ -2,6 +2,7 @@
#include <string.h>
#include "djui.h"
#include "src/pc/controller/controller_api.h"
#include "src/pc/controller/controller_bind_mapping.h"
#include "audio_defines.h"
#include "audio/external.h"
@ -32,11 +33,7 @@ static void djui_bind_button_on_bind(struct DjuiBase* caller) {
// set key
bind->configKey[button->base.tag] = key;
char keyStr[5] = { 0 };
if (key != VK_INVALID) {
sprintf(keyStr, "%04x", key);
}
djui_text_set_text(button->text, keyStr);
djui_text_set_text(button->text, translate_bind_to_name(key));
djui_interactable_set_binding(NULL);
play_sound(SOUND_MENU_CHANGE_SELECT, gDefaultSoundArgs);
controller_reconfigure();
@ -55,7 +52,7 @@ struct DjuiBind* djui_bind_create(struct DjuiBase* parent, const char* message,
djui_base_init(parent, base, NULL, djui_bind_destroy);
djui_base_set_size_type(&bind->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&bind->base, 1.0f, 32);
djui_base_set_size(&bind->base, 1.0f, 28);
djui_base_set_color(&bind->base, 0, 0, 0, 0);
struct DjuiText* text = djui_text_create(&bind->base, message);
@ -70,17 +67,13 @@ struct DjuiBind* djui_bind_create(struct DjuiBase* parent, const char* message,
struct DjuiRect* rect = djui_rect_create(&bind->base);
djui_base_set_alignment(&rect->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_CENTER);
djui_base_set_size_type(&rect->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
djui_base_set_size(&rect->base, 0.7f, 1.0f);
djui_base_set_size(&rect->base, 0.8f, 1.0f);
djui_base_set_color(&rect->base, 0, 0, 0, 0);
bind->rect = rect;
for (int i = 0; i < MAX_BINDS; i++) {
unsigned int key = configKey[i];
char keyStr[5] = { 0 };
if (key != VK_INVALID) {
sprintf(keyStr, "%04x", key);
}
struct DjuiButton* button = djui_button_create(&rect->base, keyStr);
struct DjuiButton* button = djui_button_create(&rect->base, translate_bind_to_name(key));
djui_base_set_size_type(&button->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
djui_base_set_size(&button->base, 0.33f, 1.0f);
button->base.tag = i;

View file

@ -8,7 +8,7 @@ void djui_panel_controls_value_change(UNUSED struct DjuiBase* caller) {
}
void djui_panel_controls_create(struct DjuiBase* caller) {
f32 bindBodyHeight = 32 * 12 + 1 * 11;
f32 bindBodyHeight = 32 * 11 + 1 * 10;
f32 bodyHeight = bindBodyHeight + 16 * 3 + 32 * 2 + 64;
struct DjuiBase* defaultBase = NULL;
@ -32,7 +32,7 @@ void djui_panel_controls_create(struct DjuiBase* caller) {
djui_bind_create(&bindBody->base, "C Left", configKeyCLeft);
djui_bind_create(&bindBody->base, "C Right", configKeyCRight);
djui_bind_create(&bindBody->base, "Chat", configKeyChat);
djui_bind_create(&bindBody->base, "Player List", configKeyPlayerList);
djui_bind_create(&bindBody->base, "Players", configKeyPlayerList);
defaultBase = &bind1->buttons[0]->base;
}

View file

@ -22,6 +22,10 @@
#include "gfx_rendering_api.h"
#include "gfx_direct3d_common.h"
extern "C" {
#include "src/pc/controller/controller_bind_mapping.h"
}
#define DECLARE_GFX_DXGI_FUNCTIONS
#include "gfx_dxgi.h"
@ -303,6 +307,8 @@ static void gfx_d3d11_init(void) {
gfx_dxgi_get_h_wnd(), "Failed to create per-draw constant buffer.");
d3d.context->PSSetConstantBuffers(1, 1, d3d.per_draw_cb.GetAddressOf());
controller_bind_init();
}

View file

@ -37,6 +37,10 @@
#include "gfx_rendering_api.h"
#include "gfx_direct3d_common.h"
extern "C" {
#include "src/pc/controller/controller_bind_mapping.h"
}
#include "gfx_screen_config.h"
#define DEBUG_D3D 0
@ -866,6 +870,8 @@ static void gfx_direct3d12_init(void ) {
CD3DX12_RANGE read_range(0, 0); // Read not possible from CPU
ThrowIfFailed(d3d.vertex_buffer->Map(0, &read_range, &d3d.mapped_vbuf_address));
}
controller_bind_init();
}
static void gfx_direct3d12_end_frame(void) {

View file

@ -19,6 +19,7 @@
#include "../platform.h"
#include "src/pc/controller/controller_keyboard.h"
#include "src/pc/controller/controller_bind_mapping.h"
// TODO: figure out if this shit even works
#ifdef VERSION_EU
@ -27,8 +28,6 @@
# define FRAMERATE 30
#endif
static int inverted_scancode_table[512];
static kb_callback_t kb_key_down = NULL;
static kb_callback_t kb_key_up = NULL;
static void (*kb_all_keys_up)(void) = NULL;
@ -43,56 +42,6 @@ static int desktop_bpp = 24;
static int window_w = 0;
static int window_h = 0;
const SDLKey windows_scancode_table[] = {
/* 0 1 2 3 4 5 6 7 */
/* 8 9 A B C D E F */
SDLK_UNKNOWN, SDLK_ESCAPE, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, /* 0 */
SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS, SDLK_BACKSPACE, SDLK_TAB, /* 0 */
SDLK_q, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_y, SDLK_u, SDLK_i, /* 1 */
SDLK_o, SDLK_p, SDLK_LEFTBRACKET, SDLK_RIGHTBRACKET, SDLK_RETURN, SDLK_LCTRL, SDLK_a, SDLK_s, /* 1 */
SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, SDLK_SEMICOLON, /* 2 */
SDLK_UNKNOWN, SDLK_BACKQUOTE, SDLK_LSHIFT, SDLK_BACKSLASH, SDLK_z, SDLK_x, SDLK_c, SDLK_v, /* 2 */
SDLK_b, SDLK_n, SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_RSHIFT, SDLK_PRINT, /* 3 */
SDLK_LALT, SDLK_SPACE, SDLK_CAPSLOCK, SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, /* 3 */
SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_NUMLOCK, SDLK_SCROLLOCK, SDLK_HOME, /* 4 */
SDLK_UP, SDLK_PAGEUP, SDLK_KP_MINUS, SDLK_LEFT, SDLK_KP5, SDLK_RIGHT, SDLK_KP_PLUS, SDLK_END, /* 4 */
SDLK_DOWN, SDLK_PAGEDOWN, SDLK_INSERT, SDLK_DELETE, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_F11, /* 5 */
SDLK_F12, SDLK_PAUSE, SDLK_UNKNOWN, SDLK_LSUPER, SDLK_RSUPER, SDLK_MODE, SDLK_UNKNOWN, SDLK_UNKNOWN, /* 5 */
SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_F13, SDLK_F14, SDLK_F15, SDLK_UNKNOWN, /* 6 */
SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, /* 6 */
SDLK_WORLD_2, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_WORLD_1, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, SDLK_UNKNOWN, /* 7 */
SDLK_UNKNOWN, SDLK_WORLD_4, SDLK_UNKNOWN, SDLK_WORLD_5, SDLK_UNKNOWN, SDLK_WORLD_3, SDLK_UNKNOWN, SDLK_UNKNOWN /* 7 */
};
const SDLKey scancode_rmapping_extended[][2] = {
{ SDLK_KP_ENTER, SDLK_RETURN },
{ SDLK_RALT, SDLK_LALT },
{ SDLK_RCTRL, SDLK_LCTRL },
{ SDLK_KP_DIVIDE, SDLK_SLASH },
//{ SDLK_KPPLUS, SDLK_CAPSLOCK }
};
const SDLKey scancode_rmapping_nonextended[][2] = {
{ SDLK_KP7, SDLK_HOME },
{ SDLK_KP8, SDLK_UP },
{ SDLK_KP9, SDLK_PAGEUP },
{ SDLK_KP4, SDLK_LEFT },
{ SDLK_KP6, SDLK_RIGHT },
{ SDLK_KP1, SDLK_END },
{ SDLK_KP2, SDLK_DOWN },
{ SDLK_KP3, SDLK_PAGEDOWN },
{ SDLK_KP0, SDLK_INSERT },
{ SDLK_KP_PERIOD, SDLK_DELETE },
{ SDLK_KP_MULTIPLY, SDLK_PRINT }
};
static void gfx_sdl_set_mode(void) {
if (configWindow.exiting_fullscreen)
configWindow.exiting_fullscreen = false;
@ -160,18 +109,7 @@ static void gfx_sdl_init(const char *window_title) {
SDL_ShowCursor(0);
}
for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDLKey); i++) {
inverted_scancode_table[windows_scancode_table[i]] = i;
}
for (size_t i = 0; i < sizeof(scancode_rmapping_extended) / sizeof(scancode_rmapping_extended[0]); i++) {
inverted_scancode_table[scancode_rmapping_extended[i][0]] = inverted_scancode_table[scancode_rmapping_extended[i][1]] + 0x100;
}
for (size_t i = 0; i < sizeof(scancode_rmapping_nonextended) / sizeof(scancode_rmapping_nonextended[0]); i++) {
inverted_scancode_table[scancode_rmapping_nonextended[i][0]] = inverted_scancode_table[scancode_rmapping_nonextended[i][1]];
inverted_scancode_table[scancode_rmapping_nonextended[i][1]] += 0x100;
}
controller_bind_init();
}
static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) {
@ -183,22 +121,14 @@ static void gfx_sdl_get_dimensions(uint32_t *width, uint32_t *height) {
if (height) *height = window_h;
}
static int translate_scancode(int scancode) {
if (scancode < 512) {
return inverted_scancode_table[scancode];
} else {
return 0;
}
}
static void gfx_sdl_onkeydown(int scancode) {
if (kb_key_down)
kb_key_down(translate_scancode(scancode));
kb_key_down(translate_bind_to_name(scancode));
}
static void gfx_sdl_onkeyup(int scancode) {
if (kb_key_up)
kb_key_up(translate_scancode(scancode));
kb_key_up(translate_bind_to_name(scancode));
}
static void gfx_sdl_handle_events(void) {

View file

@ -34,7 +34,8 @@
#include "../cliopts.h"
#include "src/pc/controller/controller_keyboard.h"
#include "src/pc/controller/controller_sdl.h"
#include "src/pc/controller/controller_bind_mapping.h"
#include "pc/utils/misc.h"
// TODO: figure out if this shit even works
@ -49,63 +50,12 @@ static f64 sFrameTargetTime = 0;
static SDL_Window *wnd;
static SDL_GLContext ctx = NULL;
static int inverted_scancode_table[512];
static kb_callback_t kb_key_down = NULL;
static kb_callback_t kb_key_up = NULL;
static void (*kb_all_keys_up)(void) = NULL;
static void (*kb_text_input)(char*) = NULL;
const SDL_Scancode windows_scancode_table[] = {
/* 0 1 2 3 4 5 6 7 */
/* 8 9 A B C D E F */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, /* 0 */
SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, /* 0 */
SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, /* 1 */
SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, /* 1 */
SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, /* 2 */
SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, /* 2 */
SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,/* 3 */
SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, /* 3 */
SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, /* 4 */
SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, /* 4 */
SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH, SDL_SCANCODE_F11, /* 5 */
SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 5 */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_F16, /* 6 */
SDL_SCANCODE_F17, SDL_SCANCODE_F18, SDL_SCANCODE_F19, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 6 */
SDL_SCANCODE_INTERNATIONAL2, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL1, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 7 */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL4, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL5, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL3, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN /* 7 */
};
const SDL_Scancode scancode_rmapping_extended[][2] = {
{SDL_SCANCODE_KP_ENTER, SDL_SCANCODE_RETURN},
{SDL_SCANCODE_RALT, SDL_SCANCODE_LALT},
{SDL_SCANCODE_RCTRL, SDL_SCANCODE_LCTRL},
{SDL_SCANCODE_KP_DIVIDE, SDL_SCANCODE_SLASH},
//{SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_CAPSLOCK}
};
const SDL_Scancode scancode_rmapping_nonextended[][2] = {
{SDL_SCANCODE_KP_7, SDL_SCANCODE_HOME},
{SDL_SCANCODE_KP_8, SDL_SCANCODE_UP},
{SDL_SCANCODE_KP_9, SDL_SCANCODE_PAGEUP},
{SDL_SCANCODE_KP_4, SDL_SCANCODE_LEFT},
{SDL_SCANCODE_KP_6, SDL_SCANCODE_RIGHT},
{SDL_SCANCODE_KP_1, SDL_SCANCODE_END},
{SDL_SCANCODE_KP_2, SDL_SCANCODE_DOWN},
{SDL_SCANCODE_KP_3, SDL_SCANCODE_PAGEDOWN},
{SDL_SCANCODE_KP_0, SDL_SCANCODE_INSERT},
{SDL_SCANCODE_KP_PERIOD, SDL_SCANCODE_DELETE},
{SDL_SCANCODE_KP_MULTIPLY, SDL_SCANCODE_PRINTSCREEN}
};
#define IS_FULLSCREEN() ((SDL_GetWindowFlags(wnd) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0)
int test_vsync(void) {
@ -211,18 +161,7 @@ static void gfx_sdl_init(const char *window_title) {
SDL_ShowCursor(SDL_DISABLE);
}
for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) {
inverted_scancode_table[windows_scancode_table[i]] = i;
}
for (size_t i = 0; i < sizeof(scancode_rmapping_extended) / sizeof(scancode_rmapping_extended[0]); i++) {
inverted_scancode_table[scancode_rmapping_extended[i][0]] = inverted_scancode_table[scancode_rmapping_extended[i][1]] + 0x100;
}
for (size_t i = 0; i < sizeof(scancode_rmapping_nonextended) / sizeof(scancode_rmapping_nonextended[0]); i++) {
inverted_scancode_table[scancode_rmapping_nonextended[i][0]] = inverted_scancode_table[scancode_rmapping_nonextended[i][1]];
inverted_scancode_table[scancode_rmapping_nonextended[i][1]] += 0x100;
}
controller_bind_init();
}
static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) {
@ -236,17 +175,9 @@ static void gfx_sdl_get_dimensions(uint32_t *width, uint32_t *height) {
if (height) *height = h;
}
static int translate_scancode(int scancode) {
if (scancode < 512) {
return inverted_scancode_table[scancode];
} else {
return 0;
}
}
static void gfx_sdl_onkeydown(int scancode) {
if (kb_key_down)
kb_key_down(translate_scancode(scancode));
kb_key_down(translate_sdl_scancode(scancode));
const Uint8 *state = SDL_GetKeyboardState(NULL);
@ -258,7 +189,7 @@ static void gfx_sdl_onkeydown(int scancode) {
static void gfx_sdl_onkeyup(int scancode) {
if (kb_key_up)
kb_key_up(translate_scancode(scancode));
kb_key_up(translate_sdl_scancode(scancode));
}
static void gfx_sdl_handle_events(void) {