Add SDL3 platform driver
This commit is contained in:
parent
bcbecb372b
commit
6f0321d8f6
|
@ -51,7 +51,8 @@ jobs:
|
|||
cmake-generator: Ninja
|
||||
cmake-toolchain-file: ${{ matrix.platform.cmake-toolchain-file }}
|
||||
discriminator: ${{ matrix.platform.arch }}
|
||||
version: 2-latest
|
||||
version: 3-latest
|
||||
version-sdl2-compat: 2-head
|
||||
version-sdl12-compat: 1-head
|
||||
- name: 'Prepare sources for release'
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
|
@ -71,6 +72,7 @@ jobs:
|
|||
-DCMAKE_TOOLCHAIN_FILE=${{ matrix.platform.cmake-toolchain-file }} \
|
||||
-DDETHRACE_PLATFORM_SDL1=ON \
|
||||
-DDETHRACE_PLATFORM_SDL2=ON \
|
||||
-DDETHRACE_PLATFORM_SDL3=ON \
|
||||
-DDETHRACE_PLATFORM_SDL_DYNAMIC=ON \
|
||||
${{ matrix.platform.cmake-args }}
|
||||
- name: 'Build (CMake)'
|
||||
|
|
|
@ -64,6 +64,7 @@ test_big_endian(IS_BIGENDIAN)
|
|||
|
||||
option(DETHRACE_PLATFORM_SDL1 "Support SDL 1.2 platform driver" OFF)
|
||||
option(DETHRACE_PLATFORM_SDL2 "Support SDL 2 platform driver" ON)
|
||||
option(DETHRACE_PLATFORM_SDL3 "Support SDL 3 platform driver" ON)
|
||||
set(count_sdl_platforms 0)
|
||||
|
||||
set(DETHRACE_PLATFORMS )
|
||||
|
@ -80,6 +81,11 @@ if(DETHRACE_PLATFORM_SDL2)
|
|||
list(APPEND DETHRACE_PLATFORMS SDL2)
|
||||
math(EXPR count_sdl_platforms "${count_sdl_platforms} + 1")
|
||||
endif()
|
||||
if(DETHRACE_PLATFORM_SDL3)
|
||||
find_package(SDL3 CONFIG REQUIRED)
|
||||
list(APPEND DETHRACE_PLATFORMS SDL3)
|
||||
math(EXPR count_sdl_platforms "${count_sdl_platforms} + 1")
|
||||
endif()
|
||||
|
||||
if(count_sdl_platforms GREATER 1)
|
||||
# Force dynamic SDL when enabling 2 (or more) SDL platform backends
|
||||
|
|
|
@ -86,6 +86,21 @@ if(DETHRACE_PLATFORM_SDL2)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if(DETHRACE_PLATFORM_SDL3)
|
||||
target_sources(harness PRIVATE
|
||||
platforms/sdl3.c
|
||||
platforms/sdl3_scancode_to_dinput.h
|
||||
platforms/sdl3_syms.h
|
||||
)
|
||||
target_compile_definitions(harness PRIVATE DETHRACE_PLATFORM_SDL3)
|
||||
if(DETHRACE_PLATFORM_SDL_DYNAMIC)
|
||||
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/platforms/sdl3.c" APPEND PROPERTY INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:SDL3::SDL3,INTERFACE_INCLUDE_DIRECTORIES>")
|
||||
set_property(GLOBAL APPEND PROPERTY DETHRACE_BUILD_RPATHS "$<TARGET_FILE_DIR:SDL3::SDL3>")
|
||||
else()
|
||||
target_link_libraries(harness PRIVATE SDL3::SDL3)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DETHRACE_PLATFORM_SDL_DYNAMIC)
|
||||
target_compile_definitions(harness PRIVATE DETHRACE_SDL_DYNAMIC)
|
||||
target_link_libraries(harness PRIVATE ${CMAKE_DL_LIBS})
|
||||
|
|
|
@ -18,11 +18,15 @@ extern void Harness_Platform_Init(tHarness_platform* platform);
|
|||
|
||||
extern const tPlatform_bootstrap SDL1_bootstrap;
|
||||
extern const tPlatform_bootstrap SDL2_bootstrap;
|
||||
extern const tPlatform_bootstrap SDL3_bootstrap;
|
||||
|
||||
static const tPlatform_bootstrap *platform_bootstraps[] = {
|
||||
#ifdef DETHRACE_PLATFORM_SDL2
|
||||
&SDL2_bootstrap,
|
||||
#endif
|
||||
#ifdef DETHRACE_PLATFORM_SDL3
|
||||
&SDL3_bootstrap,
|
||||
#endif
|
||||
#ifdef DETHRACE_PLATFORM_SDL1
|
||||
&SDL1_bootstrap,
|
||||
#endif
|
||||
|
|
|
@ -53,6 +53,7 @@ static const char * const possible_locations[] = {
|
|||
static void *sdl1_so;
|
||||
#endif
|
||||
|
||||
#define SDL_NAME "SDL1"
|
||||
#define OBJECT_NAME sdl1_so
|
||||
#define SYMBOL_PREFIX SDL1_
|
||||
#define FOREACH_SDLX_SYM FOREACH_SDL1_SYM
|
||||
|
|
|
@ -63,6 +63,7 @@ static const char * const possible_locations[] = {
|
|||
static void *sdl2_so;
|
||||
#endif
|
||||
|
||||
#define SDL_NAME "SDL2"
|
||||
#define OBJECT_NAME sdl2_so
|
||||
#define SYMBOL_PREFIX SDL2_
|
||||
#define FOREACH_SDLX_SYM FOREACH_SDL2_SYM
|
||||
|
|
|
@ -40,6 +40,4 @@
|
|||
X(GL_SetSwapInterval, int, (int)) \
|
||||
X(GL_SwapWindow, void, (SDL_Window*))
|
||||
|
||||
#undef SDL2_SYM
|
||||
|
||||
#endif /* sdl2_syms_h */
|
||||
|
|
|
@ -0,0 +1,412 @@
|
|||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "harness.h"
|
||||
#include "harness/config.h"
|
||||
#include "harness/hooks.h"
|
||||
#include "harness/trace.h"
|
||||
#include "sdl3_scancode_to_dinput.h"
|
||||
#include "sdl3_syms.h"
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(sdl3_platform_requires_SDL3, SDL_MAJOR_VERSION == 3);
|
||||
|
||||
static SDL_Window* window;
|
||||
static SDL_Renderer* renderer;
|
||||
static SDL_Texture* screen_texture;
|
||||
static uint32_t converted_palette[256];
|
||||
static br_pixelmap* last_screen_src;
|
||||
|
||||
static SDL_GLContext gl_context;
|
||||
|
||||
static int render_width, render_height;
|
||||
|
||||
static Uint32 last_frame_time;
|
||||
|
||||
static uint8_t directinput_key_state[SDL_SCANCODE_COUNT];
|
||||
|
||||
static struct {
|
||||
int x, y;
|
||||
float scale_x, scale_y;
|
||||
} viewport;
|
||||
|
||||
// Callbacks back into original game code
|
||||
extern void QuitGame(void);
|
||||
extern uint32_t gKeyboard_bits[8];
|
||||
extern br_pixelmap* gBack_screen;
|
||||
|
||||
#ifdef DETHRACE_SDL_DYNAMIC
|
||||
#ifdef _WIN32
|
||||
static const char * const possible_locations[] = {
|
||||
"SDL3.dll",
|
||||
};
|
||||
#elif defined(__APPLE__)
|
||||
#define SHARED_OBJECT_NAME "libSDL3"
|
||||
#define SDL3_LIBNAME "libSDL3.dylib"
|
||||
#define SDL3_FRAMEWORK "SDL3.framework/Versions/A/SDL3"
|
||||
static const char * const possible_locations[] = {
|
||||
"@loader_path/" SDL3_LIBNAME, /* MyApp.app/Contents/MacOS/libSDL3_dylib */
|
||||
"@loader_path/../Frameworks/" SDL3_FRAMEWORK, /* MyApp.app/Contents/Frameworks/SDL3_framework */
|
||||
"@executable_path/" SDL3_LIBNAME, /* MyApp.app/Contents/MacOS/libSDL3_dylib */
|
||||
"@executable_path/../Frameworks/" SDL3_FRAMEWORK, /* MyApp.app/Contents/Frameworks/SDL3_framework */
|
||||
NULL, /* /Users/username/Library/Frameworks/SDL3_framework */
|
||||
"/Library/Frameworks" SDL3_FRAMEWORK, /* /Library/Frameworks/SDL3_framework */
|
||||
SDL3_LIBNAME /* oh well, anywhere the system can see the .dylib (/usr/local/lib or whatever) */
|
||||
};
|
||||
#else
|
||||
static const char * const possible_locations[] = {
|
||||
"libSDL3.so.0",
|
||||
"libSDL3.so",
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DETHRACE_SDL_DYNAMIC
|
||||
static void *sdl3_so;
|
||||
#endif
|
||||
|
||||
#define SDL_NAME "SDL3"
|
||||
#define OBJECT_NAME sdl3_so
|
||||
#define SYMBOL_PREFIX SDL3_
|
||||
#define FOREACH_SDLX_SYM FOREACH_SDL3_SYM
|
||||
|
||||
#include "sdl_dyn_common.h"
|
||||
|
||||
static void calculate_viewport(int window_width, int window_height) {
|
||||
int vp_width, vp_height;
|
||||
float target_aspect_ratio;
|
||||
float aspect_ratio;
|
||||
|
||||
aspect_ratio = (float)window_width / window_height;
|
||||
target_aspect_ratio = (float)gBack_screen->width / gBack_screen->height;
|
||||
|
||||
vp_width = window_width;
|
||||
vp_height = window_height;
|
||||
if (aspect_ratio != target_aspect_ratio) {
|
||||
if (aspect_ratio > target_aspect_ratio) {
|
||||
vp_width = window_height * target_aspect_ratio + .5f;
|
||||
} else {
|
||||
vp_height = window_width / target_aspect_ratio + .5f;
|
||||
}
|
||||
}
|
||||
viewport.x = (window_width - vp_width) / 2;
|
||||
viewport.y = (window_height - vp_height) / 2;
|
||||
viewport.scale_x = (float)vp_width / gBack_screen->width;
|
||||
viewport.scale_y = (float)vp_height / gBack_screen->height;
|
||||
}
|
||||
|
||||
static int SDL3_Harness_SetWindowPos(void* hWnd, int x, int y, int nWidth, int nHeight) {
|
||||
// SDL_SetWindowPosition(hWnd, x, y);
|
||||
if (nWidth == 320 && nHeight == 200) {
|
||||
nWidth = 640;
|
||||
nHeight = 400;
|
||||
}
|
||||
SDL3_SetWindowSize(hWnd, nWidth, nHeight);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void SDL3_Harness_DestroyWindow(void* hWnd) {
|
||||
// SDL3_GL_DeleteContext(context);
|
||||
SDL3_DestroyWindow(window);
|
||||
SDL3_Quit();
|
||||
window = NULL;
|
||||
}
|
||||
|
||||
// Checks whether the `flag_check` is the only modifier applied.
|
||||
// e.g. is_only_modifier(event.key.keysym.mod, KMOD_ALT) returns true when only the ALT key was pressed
|
||||
static int is_only_key_modifier(SDL_Keymod modifier_flags, SDL_Keymod flag_check) {
|
||||
return (modifier_flags & flag_check) && (modifier_flags & (SDL_KMOD_CTRL | SDL_KMOD_SHIFT | SDL_KMOD_ALT | SDL_KMOD_GUI)) == (modifier_flags & flag_check);
|
||||
}
|
||||
|
||||
static void SDL3_Harness_ProcessWindowMessages(MSG_* msg) {
|
||||
SDL_Event event;
|
||||
int dinput_key;
|
||||
|
||||
while (SDL3_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
case SDL_EVENT_KEY_UP:
|
||||
if (event.key.windowID != SDL3_GetWindowID(window)) {
|
||||
continue;
|
||||
}
|
||||
if (event.key.key == SDLK_RETURN) {
|
||||
if (event.key.type == SDL_EVENT_KEY_DOWN) {
|
||||
if ((event.key.mod & (SDL_KMOD_CTRL | SDL_KMOD_SHIFT | SDL_KMOD_ALT | SDL_KMOD_GUI))) {
|
||||
// Ignore keydown of RETURN when used together with some modifier
|
||||
return;
|
||||
}
|
||||
} else if (event.key.type == SDL_EVENT_KEY_UP) {
|
||||
if (is_only_key_modifier(event.key.mod, SDL_KMOD_ALT)) {
|
||||
SDL3_SetWindowFullscreen(window, (SDL3_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) ? 0 : SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Map incoming SDL scancode to DirectInput DIK_* key code.
|
||||
// based on https://github.com/DanielGibson/Snippets/blob/master/sdl2_scancode_to_dinput.h
|
||||
dinput_key = sdlScanCodeToDirectInputKeyNum[event.key.scancode];
|
||||
if (dinput_key == 0) {
|
||||
LOG_WARN("unexpected scan code %s (%d)", SDL3_GetScancodeName(event.key.scancode), event.key.scancode);
|
||||
return;
|
||||
}
|
||||
// DInput expects high bit to be set if key is down
|
||||
// https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee418261(v=vs.85)
|
||||
directinput_key_state[dinput_key] = (event.type == SDL_EVENT_KEY_DOWN ? 0x80 : 0);
|
||||
if (event.type == SDL_EVENT_KEY_DOWN) {
|
||||
gKeyboard_bits[dinput_key >> 5] |= (1 << (dinput_key & 0x1F));
|
||||
} else {
|
||||
gKeyboard_bits[dinput_key >> 5] &= ~(1 << (dinput_key & 0x1F));
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
calculate_viewport(event.window.data1, event.window.data2);
|
||||
break;
|
||||
|
||||
case SDL_EVENT_QUIT:
|
||||
QuitGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SDL3_Harness_GetKeyboardState(unsigned int count, uint8_t* buffer) {
|
||||
memcpy(buffer, directinput_key_state, count);
|
||||
}
|
||||
|
||||
static int SDL3_Harness_GetMouseButtons(int* pButton1, int* pButton2) {
|
||||
if (SDL3_GetMouseFocus() != window) {
|
||||
*pButton1 = 0;
|
||||
*pButton2 = 0;
|
||||
return 0;
|
||||
}
|
||||
int state = SDL3_GetMouseState(NULL, NULL);
|
||||
*pButton1 = state & SDL_BUTTON_LMASK;
|
||||
*pButton2 = state & SDL_BUTTON_RMASK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SDL3_Harness_GetMousePosition(int* pX, int* pY) {
|
||||
int window_width, window_height;
|
||||
float fWX, fWY;
|
||||
float fX, fY;
|
||||
|
||||
if (SDL3_GetMouseFocus() != window) {
|
||||
return 0;
|
||||
}
|
||||
SDL3_GetWindowSize(window, &window_width, &window_height);
|
||||
|
||||
SDL3_GetMouseState(&fWX, &fWY);
|
||||
if (renderer != NULL) {
|
||||
// software renderer
|
||||
SDL3_RenderCoordinatesFromWindow(renderer, fWX, fWY, &fX, &fY);
|
||||
} else {
|
||||
// hardware renderer
|
||||
// handle case where window is stretched larger than the pixel size
|
||||
fX = fWX * (640.0f / window_width);
|
||||
fY = fWY * (480.0f / window_height);
|
||||
}
|
||||
*pX = (int)fX;
|
||||
*pY = (int)fY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void limit_fps(void) {
|
||||
Uint32 now = SDL3_GetTicks();
|
||||
if (last_frame_time != 0) {
|
||||
unsigned int frame_time = now - last_frame_time;
|
||||
last_frame_time = now;
|
||||
if (frame_time < 100) {
|
||||
int sleep_time = (1000 / harness_game_config.fps) - frame_time;
|
||||
if (sleep_time > 5) {
|
||||
gHarness_platform.Sleep(sleep_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
last_frame_time = SDL3_GetTicks();
|
||||
}
|
||||
|
||||
static int SDL3_Harness_ShowErrorMessage(void* window, char* text, char* caption) {
|
||||
fprintf(stderr, "%s", text);
|
||||
SDL3_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, caption, text, window);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void SDL3_Harness_CreateWindow(const char* title, int width, int height, tHarness_window_type window_type) {
|
||||
int window_width, window_height;
|
||||
|
||||
render_width = width;
|
||||
render_height = height;
|
||||
|
||||
window_width = width;
|
||||
window_height = height;
|
||||
|
||||
// special case lores and make a bigger window
|
||||
if (width == 320 && height == 200) {
|
||||
window_width = 640;
|
||||
window_height = 480;
|
||||
}
|
||||
|
||||
if (!SDL3_Init(SDL_INIT_VIDEO)) {
|
||||
LOG_PANIC("SDL_INIT_VIDEO error: %s", SDL3_GetError());
|
||||
}
|
||||
|
||||
if (window_type == eWindow_type_opengl) {
|
||||
|
||||
window = SDL3_CreateWindow(title,
|
||||
window_width, window_height,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
|
||||
if (window == NULL) {
|
||||
LOG_PANIC("Failed to create window: %s", SDL3_GetError());
|
||||
}
|
||||
|
||||
SDL3_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL3_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL3_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||
gl_context = SDL3_GL_CreateContext(window);
|
||||
|
||||
if (gl_context == NULL) {
|
||||
LOG_WARN("Failed to create OpenGL core profile: %s. Trying OpenGLES...", SDL3_GetError());
|
||||
SDL3_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||
SDL3_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL3_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||
gl_context = SDL3_GL_CreateContext(window);
|
||||
}
|
||||
if (gl_context == NULL) {
|
||||
LOG_PANIC("Failed to create OpenGL context: %s", SDL3_GetError());
|
||||
}
|
||||
SDL3_GL_SetSwapInterval(1);
|
||||
|
||||
} else {
|
||||
window = SDL3_CreateWindow(title,
|
||||
window_width, window_height,
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
if (window == NULL) {
|
||||
LOG_PANIC("Failed to create window: %s", SDL3_GetError());
|
||||
}
|
||||
|
||||
renderer = SDL3_CreateRenderer(window, NULL);
|
||||
if (renderer == NULL) {
|
||||
LOG_PANIC("Failed to create renderer: %s", SDL3_GetError());
|
||||
}
|
||||
SDL3_SetRenderVSync(renderer, 1);
|
||||
SDL3_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
|
||||
SDL3_SetRenderLogicalPresentation(renderer, render_width, render_height, SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
|
||||
screen_texture = SDL3_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||
if (screen_texture == NULL) {
|
||||
const SDL_PixelFormat *renderer_formats = NULL;
|
||||
SDL_PropertiesID renderer_props = SDL3_GetRendererProperties(renderer);
|
||||
if (renderer_props) {
|
||||
renderer_formats = SDL3_GetPointerProperty(renderer_props, SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL);
|
||||
if (renderer_formats) {
|
||||
for (Uint32 i = 0; renderer_formats[i] != SDL_PIXELFORMAT_UNKNOWN; i++) {
|
||||
LOG_INFO("%s\n", SDL3_GetPixelFormatName(renderer_formats[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_PANIC("Failed to create renderer texture (%s)", SDL3_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
SDL3_ShowCursor();
|
||||
|
||||
viewport.x = 0;
|
||||
viewport.y = 0;
|
||||
viewport.scale_x = 1;
|
||||
viewport.scale_y = 1;
|
||||
|
||||
if (harness_game_config.start_full_screen) {
|
||||
SDL3_SetWindowFullscreen(window, true);
|
||||
}
|
||||
}
|
||||
|
||||
static void SDL3_Harness_Swap(br_pixelmap* back_buffer) {
|
||||
|
||||
SDL3_Harness_ProcessWindowMessages(NULL);
|
||||
|
||||
if (gl_context != NULL) {
|
||||
SDL3_GL_SwapWindow(window);
|
||||
} else {
|
||||
uint8_t* src_pixels = back_buffer->pixels;
|
||||
uint32_t* dest_pixels;
|
||||
int dest_pitch;
|
||||
|
||||
SDL3_LockTexture(screen_texture, NULL, (void**)&dest_pixels, &dest_pitch);
|
||||
for (int i = 0; i < back_buffer->height * back_buffer->width; i++) {
|
||||
*dest_pixels = converted_palette[*src_pixels];
|
||||
dest_pixels++;
|
||||
src_pixels++;
|
||||
}
|
||||
SDL3_UnlockTexture(screen_texture);
|
||||
SDL3_RenderClear(renderer);
|
||||
SDL3_RenderTexture(renderer, screen_texture, NULL, NULL);
|
||||
SDL3_RenderPresent(renderer);
|
||||
last_screen_src = back_buffer;
|
||||
}
|
||||
|
||||
if (harness_game_config.fps != 0) {
|
||||
limit_fps();
|
||||
}
|
||||
}
|
||||
|
||||
static void SDL3_Harness_PaletteChanged(br_colour entries[256]) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
converted_palette[i] = (0xff << 24 | BR_RED(entries[i]) << 16 | BR_GRN(entries[i]) << 8 | BR_BLU(entries[i]));
|
||||
}
|
||||
if (last_screen_src != NULL) {
|
||||
SDL3_Harness_Swap(last_screen_src);
|
||||
}
|
||||
}
|
||||
|
||||
static void SDL3_Harness_GetViewport(int* x, int* y, float* width_multipler, float* height_multiplier) {
|
||||
*x = viewport.x;
|
||||
*y = viewport.y;
|
||||
*width_multipler = viewport.scale_x;
|
||||
*height_multiplier = viewport.scale_y;
|
||||
}
|
||||
|
||||
static uint32_t SDL3_Harness_GetTicks(void) {
|
||||
return SDL3_GetTicks();
|
||||
}
|
||||
|
||||
static int SDL3_Harness_ShowCursor(int show) {
|
||||
if (show) {
|
||||
SDL3_ShowCursor();
|
||||
} else {
|
||||
SDL3_HideCursor();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void* SDL3_Harness_GL_GetProcAddress(const char* name) {
|
||||
return SDL3_GL_GetProcAddress(name);
|
||||
}
|
||||
|
||||
static int SDL3_Harness_Platform_Init(tHarness_platform* platform) {
|
||||
if (SDL3_LoadSymbols() != 0) {
|
||||
return 1;
|
||||
}
|
||||
platform->ProcessWindowMessages = SDL3_Harness_ProcessWindowMessages;
|
||||
platform->Sleep = SDL3_Delay;
|
||||
platform->GetTicks = SDL3_Harness_GetTicks;
|
||||
platform->ShowCursor = SDL3_Harness_ShowCursor;
|
||||
platform->SetWindowPos = SDL3_Harness_SetWindowPos;
|
||||
platform->DestroyWindow = SDL3_Harness_DestroyWindow;
|
||||
platform->GetKeyboardState = SDL3_Harness_GetKeyboardState;
|
||||
platform->GetMousePosition = SDL3_Harness_GetMousePosition;
|
||||
platform->GetMouseButtons = SDL3_Harness_GetMouseButtons;
|
||||
platform->ShowErrorMessage = SDL3_Harness_ShowErrorMessage;
|
||||
|
||||
platform->CreateWindow_ = SDL3_Harness_CreateWindow;
|
||||
platform->Swap = SDL3_Harness_Swap;
|
||||
platform->PaletteChanged = SDL3_Harness_PaletteChanged;
|
||||
platform->GL_GetProcAddress = SDL3_Harness_GL_GetProcAddress;
|
||||
platform->GetViewport = SDL3_Harness_GetViewport;
|
||||
return 0;
|
||||
};
|
||||
|
||||
const tPlatform_bootstrap SDL3_bootstrap = {
|
||||
"sdl3",
|
||||
"SDL3 video backend (libsdl.org)",
|
||||
ePlatform_cap_software | ePlatform_cap_opengl,
|
||||
SDL3_Harness_Platform_Init,
|
||||
};
|
|
@ -0,0 +1,390 @@
|
|||
/*
|
||||
* Maps SDL2 scancodes to directinput keynums/scancodes.
|
||||
* Useful if you're porting a game that uses dinput scancodes internally
|
||||
* (for key bindings etc) or any other lib (like CEGUI) that uses them.
|
||||
*
|
||||
* (C) 2015 Daniel Gibson
|
||||
*
|
||||
* Homepage: https://github.com/DanielGibson/Snippets/
|
||||
*
|
||||
* License:
|
||||
* This software is dual-licensed to the public domain and under the following
|
||||
* license: you are granted a perpetual, irrevocable license to copy, modify,
|
||||
* publish, and distribute this file as you see fit.
|
||||
* No warranty implied; use at your own risk.
|
||||
*
|
||||
* So you can do whatever you want with this code, including copying it
|
||||
* (or parts of it) into your own source.
|
||||
* No need to mention me or this "license" in your code or docs, even though
|
||||
* it would be appreciated, of course.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#if 0 // Usage Example:
|
||||
#include "sdl2_scancode_to_dinput.h"
|
||||
static int SDLScanCodeToKeyNum(SDL_Scancode sc)
|
||||
{
|
||||
int idx = (int)sc;
|
||||
assert(idx >= 0 && idx < SDL_NUM_SCANCODES);
|
||||
return scanCodeToKeyNum[idx];
|
||||
}
|
||||
|
||||
static SDL_Scancode KeyNumToSDLScanCode( int keyNum )
|
||||
{
|
||||
if( keyNum >= 0 && keyNum < 0xEF )
|
||||
{
|
||||
for(int i = 0; i < SDL_NUM_SCANCODES; ++i)
|
||||
{
|
||||
if(scanCodeToKeyNum[i] == keyNum) return (SDL_Scancode)i;
|
||||
}
|
||||
}
|
||||
return SDL_SCANCODE_UNKNOWN;
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
#ifndef _SDL3_SCANCODE_TO_DINPUT_H_
|
||||
#define _SDL3_SCANCODE_TO_DINPUT_H_
|
||||
|
||||
// TODO: map the following keys, if possible:
|
||||
// #define DIK_UNDERLINE 0x93 /* (NEC PC98) */
|
||||
// #define DIK_KANJI 0x94 /* (Japanese keyboard) */
|
||||
// #define DIK_AX 0x96 /* (Japan AX) */
|
||||
// #define DIK_UNLABELED 0x97 /* (J3100) */
|
||||
//
|
||||
// #define DIK_WAKE 0xE3 /* System Wake */
|
||||
//
|
||||
// (#define DIK_ABNT_C2 0x7E /* Numpad . on Brazilian keyboard */ - system should map this to KP_COMMA or something,
|
||||
// according to USB doc, so probably it doesn't need mapping here)
|
||||
|
||||
// maps SDL3 scancodes to directinput keynums/scancodes - dinput_key = sdlScanCodeToDirectInputKeyNum[(int)your_sdl2_scancode];
|
||||
static int sdlScanCodeToDirectInputKeyNum[SDL_SCANCODE_COUNT] = {
|
||||
0x0, // SDL_SCANCODE_UNKNOWN = 0, => 0 should also work for dinput codes as "not assigned/unknown"
|
||||
0x0, // // 1 (unused)
|
||||
0x0, // // 2 (unused)
|
||||
0x0, // // 3 (unused)
|
||||
0x1E, // SDL_SCANCODE_A = 4, - DIK_A
|
||||
0x30, // SDL_SCANCODE_B = 5, - DIK_B
|
||||
0x2E, // SDL_SCANCODE_C = 6, - DIK_C
|
||||
0x20, // SDL_SCANCODE_D = 7, - DIK_D
|
||||
0x12, // SDL_SCANCODE_E = 8, - DIK_E
|
||||
0x21, // SDL_SCANCODE_F = 9, - DIK_F
|
||||
0x22, // SDL_SCANCODE_G = 10, - DIK_G
|
||||
0x23, // SDL_SCANCODE_H = 11, - DIK_H
|
||||
0x17, // SDL_SCANCODE_I = 12, - DIK_I
|
||||
0x24, // SDL_SCANCODE_J = 13, - DIK_J
|
||||
0x25, // SDL_SCANCODE_K = 14, - DIK_K
|
||||
0x26, // SDL_SCANCODE_L = 15, - DIK_L
|
||||
0x32, // SDL_SCANCODE_M = 16, - DIK_M
|
||||
0x31, // SDL_SCANCODE_N = 17, - DIK_N
|
||||
0x18, // SDL_SCANCODE_O = 18, - DIK_O
|
||||
0x19, // SDL_SCANCODE_P = 19, - DIK_P
|
||||
0x10, // SDL_SCANCODE_Q = 20, - DIK_Q
|
||||
0x13, // SDL_SCANCODE_R = 21, - DIK_R
|
||||
0x1F, // SDL_SCANCODE_S = 22, - DIK_S
|
||||
0x14, // SDL_SCANCODE_T = 23, - DIK_T
|
||||
0x16, // SDL_SCANCODE_U = 24, - DIK_U
|
||||
0x2F, // SDL_SCANCODE_V = 25, - DIK_V
|
||||
0x11, // SDL_SCANCODE_W = 26, - DIK_W
|
||||
0x2D, // SDL_SCANCODE_X = 27, - DIK_X
|
||||
0x15, // SDL_SCANCODE_Y = 28, - DIK_Y
|
||||
0x2C, // SDL_SCANCODE_Z = 29, - DIK_Z
|
||||
|
||||
0x02, // SDL_SCANCODE_1 = 30, - DIK_1
|
||||
0x03, // SDL_SCANCODE_2 = 31, - DIK_2
|
||||
0x04, // SDL_SCANCODE_3 = 32, - DIK_3
|
||||
0x05, // SDL_SCANCODE_4 = 33, - DIK_4
|
||||
0x06, // SDL_SCANCODE_5 = 34, - DIK_5
|
||||
0x07, // SDL_SCANCODE_6 = 35, - DIK_6
|
||||
0x08, // SDL_SCANCODE_7 = 36, - DIK_7
|
||||
0x09, // SDL_SCANCODE_8 = 37, - DIK_8
|
||||
0x0A, // SDL_SCANCODE_9 = 38, - DIK_9
|
||||
0x0B, // SDL_SCANCODE_0 = 39, - DIK_0
|
||||
|
||||
0x1C, // SDL_SCANCODE_RETURN = 40, - DIK_RETURN
|
||||
0x01, // SDL_SCANCODE_ESCAPE = 41, - DIK_ESCAPE
|
||||
0x0E, // SDL_SCANCODE_BACKSPACE = 42, - DIK_BACK
|
||||
0x0F, // SDL_SCANCODE_TAB = 43, - DIK_TAB
|
||||
0x39, // SDL_SCANCODE_SPACE = 44, - DIK_SPACE
|
||||
|
||||
0x0C, // SDL_SCANCODE_MINUS = 45, - DIK_MINUS
|
||||
0x0D, // SDL_SCANCODE_EQUALS = 46, - DIK_EQUALS
|
||||
0x1A, // SDL_SCANCODE_LEFTBRACKET = 47, - DIK_LBRACKET
|
||||
0x1B, // SDL_SCANCODE_RIGHTBRACKET = 48, - DIK_RBRACKET
|
||||
0x2B, // SDL_SCANCODE_BACKSLASH = 49, // next to enter, US: [\|] DE: [#'] UK: [#~] - DIK_BACKSLASH
|
||||
0x2B, // SDL_SCANCODE_NONUSHASH = 50, // same key as before actually on some layouts, systems should map this to SDL_SCANCODE_BACKSLASH - DIK_BACKSLASH
|
||||
0x27, // SDL_SCANCODE_SEMICOLON = 51, - DIK_SEMICOLON
|
||||
0x28, // SDL_SCANCODE_APOSTROPHE = 52, - DIK_APOSTROPHE
|
||||
0x29, // SDL_SCANCODE_GRAVE = 53, // "quake/doom3 console key" - DIK_GRAVE
|
||||
0x33, // SDL_SCANCODE_COMMA = 54, - DIK_COMMA
|
||||
0x34, // SDL_SCANCODE_PERIOD = 55, - DIK_PERIOD
|
||||
0x35, // SDL_SCANCODE_SLASH = 56, - DIK_SLASH
|
||||
|
||||
0x3A, // SDL_SCANCODE_CAPSLOCK = 57, - DIK_CAPITAL
|
||||
|
||||
0x3B, // SDL_SCANCODE_F1 = 58, - DIK_F1
|
||||
0x3C, // SDL_SCANCODE_F2 = 59, - DIK_F2
|
||||
0x3D, // SDL_SCANCODE_F3 = 60, - DIK_F3
|
||||
0x3E, // SDL_SCANCODE_F4 = 61, - DIK_F4
|
||||
0x3F, // SDL_SCANCODE_F5 = 62, - DIK_F5
|
||||
0x40, // SDL_SCANCODE_F6 = 63, - DIK_F6
|
||||
0x41, // SDL_SCANCODE_F7 = 64, - DIK_F7
|
||||
0x42, // SDL_SCANCODE_F8 = 65, - DIK_F8
|
||||
0x43, // SDL_SCANCODE_F9 = 66, - DIK_F9
|
||||
0x44, // SDL_SCANCODE_F10 = 67, - DIK_F10
|
||||
0x57, // SDL_SCANCODE_F11 = 68, - DIK_F11
|
||||
0x58, // SDL_SCANCODE_F12 = 69, - DIK_F12
|
||||
|
||||
0xB7, // SDL_SCANCODE_PRINTSCREEN = 70, // - DIK_SYSRQ; SDL_SCANCODE_SYSREQ also maps to this!
|
||||
|
||||
0x46, // SDL_SCANCODE_SCROLLLOCK = 71, - DIK_SCROLL
|
||||
0xC5, // SDL_SCANCODE_PAUSE = 72, - DIK_PAUSE
|
||||
0xD2, // SDL_SCANCODE_INSERT = 73, // insert on PC, help on some Mac keyboards (but does send code 73, not 117) - DIK_INSERT
|
||||
0xC7, // SDL_SCANCODE_HOME = 74, - DIK_HOME
|
||||
0xC9, // SDL_SCANCODE_PAGEUP = 75, - DIK_PRIOR
|
||||
0xD3, // SDL_SCANCODE_DELETE = 76, - DIK_DELETE
|
||||
0xCF, // SDL_SCANCODE_END = 77, - DIK_END
|
||||
0xD1, // SDL_SCANCODE_PAGEDOWN = 78, - DIK_NEXT
|
||||
0xCD, // SDL_SCANCODE_RIGHT = 79, - DIK_RIGHT
|
||||
0xCB, // SDL_SCANCODE_LEFT = 80, - DIK_LEFT
|
||||
0xD0, // SDL_SCANCODE_DOWN = 81, - DIK_DOWN
|
||||
0xC8, // SDL_SCANCODE_UP = 82, - DIK_UP
|
||||
|
||||
0x45, // SDL_SCANCODE_NUMLOCKCLEAR = 83, // num lock on PC, clear on Mac keyboards - DIK_NUMLOCK
|
||||
|
||||
0xB5, // SDL_SCANCODE_KP_DIVIDE = 84, - DIK_DIVIDE
|
||||
0x37, // SDL_SCANCODE_KP_MULTIPLY = 85, - DIK_MULTIPLY
|
||||
0x4A, // SDL_SCANCODE_KP_MINUS = 86, - DIK_SUBTRACT
|
||||
0x4E, // SDL_SCANCODE_KP_PLUS = 87, - DIK_ADD
|
||||
0x9C, // SDL_SCANCODE_KP_ENTER = 88, - DIK_NUMPADENTER
|
||||
0x4F, // SDL_SCANCODE_KP_1 = 89, - DIK_NUMPAD1
|
||||
0x50, // SDL_SCANCODE_KP_2 = 90, - DIK_NUMPAD2
|
||||
0x51, // SDL_SCANCODE_KP_3 = 91, - DIK_NUMPAD3
|
||||
0x4B, // SDL_SCANCODE_KP_4 = 92, - DIK_NUMPAD4
|
||||
0x4C, // SDL_SCANCODE_KP_5 = 93, - DIK_NUMPAD5
|
||||
0x4D, // SDL_SCANCODE_KP_6 = 94, - DIK_NUMPAD6
|
||||
0x47, // SDL_SCANCODE_KP_7 = 95, - DIK_NUMPAD7
|
||||
0x48, // SDL_SCANCODE_KP_8 = 96, - DIK_NUMPAD8
|
||||
0x49, // SDL_SCANCODE_KP_9 = 97, - DIK_NUMPAD9
|
||||
0x52, // SDL_SCANCODE_KP_0 = 98, - DIK_NUMPAD0
|
||||
0x53, // SDL_SCANCODE_KP_PERIOD = 99, - DIK_DECIMAL
|
||||
|
||||
0x56, // SDL_SCANCODE_NONUSBACKSLASH = 100, // [<>|] on german keyboard, next to left shift - DIK_OEM_102
|
||||
0xDD, // SDL_SCANCODE_APPLICATION = 101, // windows contextual menu, compose - DIK_APPS
|
||||
0xDE, // SDL_SCANCODE_POWER = 102, // should be a status flag, but some mac keyboards have a power key - DIK_POWER
|
||||
|
||||
0x8D, // SDL_SCANCODE_KP_EQUALS = 103, - DIK_NUMPADEQUALS
|
||||
0x64, // SDL_SCANCODE_F13 = 104, - DIK_F13
|
||||
0x65, // SDL_SCANCODE_F14 = 105, - DIK_F14
|
||||
0x66, // SDL_SCANCODE_F15 = 106, - DIK_F15
|
||||
0x67, // SDL_SCANCODE_F16 = 107, // TODO: F16 and up don't have DIK_ constants! is this right?
|
||||
0x68, // SDL_SCANCODE_F17 = 108, // (at least 0x67-0x6F have no DIK_constants at all)
|
||||
0x69, // SDL_SCANCODE_F18 = 109,
|
||||
0x6A, // SDL_SCANCODE_F19 = 110,
|
||||
0x6B, // SDL_SCANCODE_F20 = 111,
|
||||
0x6C, // SDL_SCANCODE_F21 = 112,
|
||||
0x6D, // SDL_SCANCODE_F22 = 113,
|
||||
0x6E, // SDL_SCANCODE_F23 = 114,
|
||||
0x6F, // SDL_SCANCODE_F24 = 115,
|
||||
|
||||
0x0, // SDL_SCANCODE_EXECUTE = 116,
|
||||
0x0, // SDL_SCANCODE_HELP = 117,
|
||||
0x0, // SDL_SCANCODE_MENU = 118,
|
||||
0x0, // SDL_SCANCODE_SELECT = 119,
|
||||
|
||||
0x95, // SDL_SCANCODE_STOP = 120, - DIK_STOP
|
||||
|
||||
0x0, // SDL_SCANCODE_AGAIN = 121, // redo
|
||||
0x0, // SDL_SCANCODE_UNDO = 122,
|
||||
0x0, // SDL_SCANCODE_CUT = 123,
|
||||
0x0, // SDL_SCANCODE_COPY = 124,
|
||||
0x0, // SDL_SCANCODE_PASTE = 125,
|
||||
0x0, // SDL_SCANCODE_FIND = 126,
|
||||
0x0, // SDL_SCANCODE_MUTE = 127,
|
||||
|
||||
0xB0, // SDL_SCANCODE_VOLUMEUP = 128, - DIK_VOLUMEUP
|
||||
0xAE, // SDL_SCANCODE_VOLUMEDOWN = 129, - DIK_VOLUMEDOWN
|
||||
|
||||
// /* not sure whether there's a reason to enable these */
|
||||
0x0, // /* SDL_SCANCODE_LOCKINGCAPSLOCK = 130, */
|
||||
0x0, // /* SDL_SCANCODE_LOCKINGNUMLOCK = 131, */
|
||||
0x0, // /* SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */
|
||||
|
||||
0xB3, // SDL_SCANCODE_KP_COMMA = 133, - DIK_NUMPADCOMMA
|
||||
|
||||
0x0, // SDL_SCANCODE_KP_EQUALSAS400 = 134,
|
||||
|
||||
0x73, // SDL_SCANCODE_INTERNATIONAL1 = 135, // this is really brazilian / and ? - DIK_ABNT_C1
|
||||
0x0, // SDL_SCANCODE_INTERNATIONAL2 = 136, // TODO: Hut1_12v2.pdf page 60, footnote 16
|
||||
0x7D, // SDL_SCANCODE_INTERNATIONAL3 = 137, - DIK_YEN
|
||||
0x79, // SDL_SCANCODE_INTERNATIONAL4 = 138, // Japan: XFER/"convert kana -> kanji", right of space - DIK_CONVERT
|
||||
0x7B, // SDL_SCANCODE_INTERNATIONAL5 = 139, // Japan: NFER/"don't convert kana -> kanji", left of space - DIK_NOCONVERT
|
||||
0x0, // SDL_SCANCODE_INTERNATIONAL6 = 140, // TODO: Hut1_12v2.pdf page 60, footnote 20
|
||||
0x0, // SDL_SCANCODE_INTERNATIONAL7 = 141, // Toggle Double-Byte/Single-Byte mode.
|
||||
0x0, // SDL_SCANCODE_INTERNATIONAL8 = 142, // Undefined, available for other Front End Language Processors
|
||||
0x0, // SDL_SCANCODE_INTERNATIONAL9 = 143, // Undefined, available for other Front End Language Processors
|
||||
0x0, // SDL_SCANCODE_LANG1 = 144, // Hangul/English toggle (Korea)
|
||||
0x0, // SDL_SCANCODE_LANG2 = 145, // Hanja conversion (Korea)
|
||||
0x70, // SDL_SCANCODE_LANG3 = 146, // Katakana (Japan) - DIK_KANA
|
||||
0x0, // SDL_SCANCODE_LANG4 = 147, // Hiragana (Japan)
|
||||
0x0, // SDL_SCANCODE_LANG5 = 148, // Zenkaku/Hankaku (Japan)
|
||||
0x0, // SDL_SCANCODE_LANG6 = 149, // reserved
|
||||
0x0, // SDL_SCANCODE_LANG7 = 150, // reserved
|
||||
0x0, // SDL_SCANCODE_LANG8 = 151, // reserved
|
||||
0x0, // SDL_SCANCODE_LANG9 = 152, // reserved
|
||||
|
||||
0x0, // SDL_SCANCODE_ALTERASE = 153, // Erase-Eaze
|
||||
|
||||
0xB7, // SDL_SCANCODE_SYSREQ = 154, - DIK_SYSRQ; SDL_SCANCODE_PRINTSCREEN also maps to this!
|
||||
|
||||
0x0, // SDL_SCANCODE_CANCEL = 155,
|
||||
0x0, // SDL_SCANCODE_CLEAR = 156,
|
||||
0x0, // SDL_SCANCODE_PRIOR = 157,
|
||||
0x0, // SDL_SCANCODE_RETURN2 = 158,
|
||||
0x0, // SDL_SCANCODE_SEPARATOR = 159,
|
||||
0x0, // SDL_SCANCODE_OUT = 160,
|
||||
0x0, // SDL_SCANCODE_OPER = 161,
|
||||
0x0, // SDL_SCANCODE_CLEARAGAIN = 162,
|
||||
0x0, // SDL_SCANCODE_CRSEL = 163,
|
||||
0x0, // SDL_SCANCODE_EXSEL = 164,
|
||||
|
||||
0x0, // 165 (unused)
|
||||
0x0, // 166 (unused)
|
||||
0x0, // 167 (unused)
|
||||
0x0, // 168 (unused)
|
||||
0x0, // 169 (unused)
|
||||
0x0, // 170 (unused)
|
||||
0x0, // 171 (unused)
|
||||
0x0, // 172 (unused)
|
||||
0x0, // 173 (unused)
|
||||
0x0, // 174 (unused)
|
||||
0x0, // 175 (unused)
|
||||
|
||||
0x0, // SDL_SCANCODE_KP_00 = 176,
|
||||
0x0, // SDL_SCANCODE_KP_000 = 177,
|
||||
0x0, // SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
|
||||
0x0, // SDL_SCANCODE_DECIMALSEPARATOR = 179,
|
||||
0x0, // SDL_SCANCODE_CURRENCYUNIT = 180,
|
||||
0x0, // SDL_SCANCODE_CURRENCYSUBUNIT = 181,
|
||||
0x0, // SDL_SCANCODE_KP_LEFTPAREN = 182,
|
||||
0x0, // SDL_SCANCODE_KP_RIGHTPAREN = 183,
|
||||
0x0, // SDL_SCANCODE_KP_LEFTBRACE = 184,
|
||||
0x0, // SDL_SCANCODE_KP_RIGHTBRACE = 185,
|
||||
0x0, // SDL_SCANCODE_KP_TAB = 186,
|
||||
0x0, // SDL_SCANCODE_KP_BACKSPACE = 187,
|
||||
0x0, // SDL_SCANCODE_KP_A = 188,
|
||||
0x0, // SDL_SCANCODE_KP_B = 189,
|
||||
0x0, // SDL_SCANCODE_KP_C = 190,
|
||||
0x0, // SDL_SCANCODE_KP_D = 191,
|
||||
0x0, // SDL_SCANCODE_KP_E = 192,
|
||||
0x0, // SDL_SCANCODE_KP_F = 193,
|
||||
0x0, // SDL_SCANCODE_KP_XOR = 194,
|
||||
0x0, // SDL_SCANCODE_KP_POWER = 195,
|
||||
0x0, // SDL_SCANCODE_KP_PERCENT = 196,
|
||||
0x0, // SDL_SCANCODE_KP_LESS = 197,
|
||||
0x0, // SDL_SCANCODE_KP_GREATER = 198,
|
||||
0x0, // SDL_SCANCODE_KP_AMPERSAND = 199,
|
||||
0x0, // SDL_SCANCODE_KP_DBLAMPERSAND = 200,
|
||||
0x0, // SDL_SCANCODE_KP_VERTICALBAR = 201,
|
||||
0x0, // SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
|
||||
|
||||
0x92, // SDL_SCANCODE_KP_COLON = 203, - DIK_COLON
|
||||
|
||||
0x0, // SDL_SCANCODE_KP_HASH = 204,
|
||||
0x0, // SDL_SCANCODE_KP_SPACE = 205,
|
||||
|
||||
0x91, // SDL_SCANCODE_KP_AT = 206, - DIK_AT
|
||||
|
||||
0x0, // SDL_SCANCODE_KP_EXCLAM = 207,
|
||||
0x0, // SDL_SCANCODE_KP_MEMSTORE = 208,
|
||||
0x0, // SDL_SCANCODE_KP_MEMRECALL = 209,
|
||||
0x0, // SDL_SCANCODE_KP_MEMCLEAR = 210,
|
||||
0x0, // SDL_SCANCODE_KP_MEMADD = 211,
|
||||
0x0, // SDL_SCANCODE_KP_MEMSUBTRACT = 212,
|
||||
0x0, // SDL_SCANCODE_KP_MEMMULTIPLY = 213,
|
||||
0x0, // SDL_SCANCODE_KP_MEMDIVIDE = 214,
|
||||
0x0, // SDL_SCANCODE_KP_PLUSMINUS = 215,
|
||||
0x0, // SDL_SCANCODE_KP_CLEAR = 216,
|
||||
0x0, // SDL_SCANCODE_KP_CLEARENTRY = 217,
|
||||
0x0, // SDL_SCANCODE_KP_BINARY = 218,
|
||||
0x0, // SDL_SCANCODE_KP_OCTAL = 219,
|
||||
0x0, // SDL_SCANCODE_KP_DECIMAL = 220,
|
||||
0x0, // SDL_SCANCODE_KP_HEXADECIMAL = 221,
|
||||
|
||||
0x0, // 222 (unused)
|
||||
0x0, // 223 (unused)
|
||||
|
||||
0x1D, // SDL_SCANCODE_LCTRL = 224, - DIK_LCONTROL
|
||||
0x2A, // SDL_SCANCODE_LSHIFT = 225, - DIK_LSHIFT
|
||||
0x38, // SDL_SCANCODE_LALT = 226, // left Alt, option - DIK_LMENU
|
||||
0xDB, // SDL_SCANCODE_LGUI = 227, // left windows, command (apple), meta - DIK_LWIN
|
||||
0x9D, // SDL_SCANCODE_RCTRL = 228, - DIK_RCONTROL
|
||||
0x36, // SDL_SCANCODE_RSHIFT = 229, - DIK_RSHIFT
|
||||
0xB8, // SDL_SCANCODE_RALT = 230, // right Alt/AltGr, option - DIK_RMENU, also used for SDL_SCANCODE_MODE!
|
||||
0xDC, // SDL_SCANCODE_RGUI = 231, // left windows, command (apple), meta - DIK_RWIN
|
||||
|
||||
// 232 - 256 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, // 232 - 240 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 241-250 unused
|
||||
0, 0, 0, 0, 0, 0, // 251-256 unused
|
||||
|
||||
0xB8, // SDL_SCANCODE_MODE = 257, // this seems to be the AltGr Key? - DIK_RMENU (right alt)
|
||||
|
||||
// These values are mapped from usage page 0x0C (USB consumer page).
|
||||
0x99, // SDL_SCANCODE_AUDIONEXT = 258, - DIK_NEXTTRACK
|
||||
0x90, // SDL_SCANCODE_AUDIOPREV = 259, - DIK_PREVTRACK, which is DIK_CIRCUMFLEX on japanese keyboards
|
||||
0xA4, // SDL_SCANCODE_AUDIOSTOP = 260, - DIK_MEDIASTOP
|
||||
0xA2, // SDL_SCANCODE_AUDIOPLAY = 261, - DIK_PLAYPAUSE
|
||||
0xA0, // SDL_SCANCODE_AUDIOMUTE = 262, - DIK_MUTE
|
||||
0xED, // SDL_SCANCODE_MEDIASELECT = 263, - DIK_MEDIASELECT
|
||||
|
||||
0x0, // SDL_SCANCODE_WWW = 264,
|
||||
|
||||
0xEC, // SDL_SCANCODE_MAIL = 265, - DIK_MAIL
|
||||
0xA1, // SDL_SCANCODE_CALCULATOR = 266, - DIK_CALCULATOR
|
||||
0xEB, // SDL_SCANCODE_COMPUTER = 267, - DIK_MYCOMPUTER
|
||||
0xE5, // SDL_SCANCODE_AC_SEARCH = 268, - DIK_WEBSEARCH
|
||||
0xB2, // SDL_SCANCODE_AC_HOME = 269, - DIK_WEBHOME
|
||||
0xEA, // SDL_SCANCODE_AC_BACK = 270, - DIK_WEBBACK
|
||||
0xE9, // SDL_SCANCODE_AC_FORWARD = 271, - DIK_WEBFORWARD
|
||||
0xE8, // SDL_SCANCODE_AC_STOP = 272, - DIK_WEBSTOP
|
||||
0xE7, // SDL_SCANCODE_AC_REFRESH = 273, - DIK_WEBREFRESH
|
||||
0xE6, // SDL_SCANCODE_AC_BOOKMARKS = 274, - DIK_WEBFAVORITES
|
||||
|
||||
// These are values that Christian Walther added (for mac keyboard?).
|
||||
0x0, // SDL_SCANCODE_BRIGHTNESSDOWN = 275,
|
||||
0x0, // SDL_SCANCODE_BRIGHTNESSUP = 276,
|
||||
0x0, // SDL_SCANCODE_DISPLAYSWITCH = 277, // display mirroring/dual display switch, video mode switch
|
||||
0x0, // SDL_SCANCODE_KBDILLUMTOGGLE = 278,
|
||||
0x0, // SDL_SCANCODE_KBDILLUMDOWN = 279,
|
||||
0x0, // SDL_SCANCODE_KBDILLUMUP = 280,
|
||||
0x0, // SDL_SCANCODE_EJECT = 281,
|
||||
|
||||
0xDF, // SDL_SCANCODE_SLEEP = 282, - DIK_SLEEP
|
||||
|
||||
0x0, // SDL_SCANCODE_APP1 = 283,
|
||||
0x0, // SDL_SCANCODE_APP2 = 284,
|
||||
// end of Walther-keys
|
||||
|
||||
// the rest up to 511 are currently not named in SDL
|
||||
|
||||
0, 0, 0, 0, 0, 0, // 285-290 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 291-300 unused
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 301-320 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 321-340 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 341-360 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 361-380 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 381-400 unused
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 401-420 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 421-440 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 441-460 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 461-480 unused
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 481-500 unused
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 501-511 unused
|
||||
};
|
||||
|
||||
#endif /* _SDL3_SCANCODE_TO_DINPUT_H_ */
|
|
@ -0,0 +1,47 @@
|
|||
#ifndef sdl3_syms_h
|
||||
#define sdl3_syms_h
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#define FOREACH_SDL3_SYM(X) \
|
||||
X(Init, bool, (Uint32)) \
|
||||
X(Quit, void, (void)) \
|
||||
X(Delay, void, (Uint32)) \
|
||||
X(GetTicks, Uint64, (void)) \
|
||||
X(GetError, const char*, (void)) \
|
||||
X(GetPointerProperty, void*, (SDL_PropertiesID, const char*, void*)) \
|
||||
X(PollEvent, bool, (SDL_Event*)) \
|
||||
X(ShowSimpleMessageBox, bool, (SDL_MessageBoxFlags flags, const char*, const char *, SDL_Window*)) \
|
||||
X(CreateWindow, SDL_Window*, (const char*, int, int, SDL_WindowFlags)) \
|
||||
X(DestroyWindow, void, (SDL_Window*)) \
|
||||
X(GetWindowFlags, SDL_WindowFlags, (SDL_Window*)) \
|
||||
X(GetWindowID, SDL_WindowID, (SDL_Window*)) \
|
||||
X(GetWindowSize, bool, (SDL_Window*, int*, int*)) \
|
||||
X(HideCursor, bool, (void)) \
|
||||
X(SetWindowFullscreen, bool, (SDL_Window*, bool)) \
|
||||
X(SetWindowSize, bool, (SDL_Window*, int, int)) \
|
||||
X(CreateRenderer, SDL_Renderer*, (SDL_Window*, const char*)) \
|
||||
X(RenderClear, bool, (SDL_Renderer*)) \
|
||||
X(RenderTexture, bool, (SDL_Renderer*, SDL_Texture*, const SDL_FRect*, const SDL_FRect*)) \
|
||||
X(RenderPresent, bool, (SDL_Renderer*)) \
|
||||
X(RenderCoordinatesFromWindow, bool, (SDL_Renderer*, float, float, float*, float*)) \
|
||||
X(GetRendererName, const char*, (SDL_Renderer*)) \
|
||||
X(GetRendererProperties, SDL_PropertiesID, (SDL_Renderer*)) \
|
||||
X(SetRenderLogicalPresentation, bool, (SDL_Renderer*, int, int, SDL_RendererLogicalPresentation)) \
|
||||
X(SetRenderDrawBlendMode, bool, (SDL_Renderer*, SDL_BlendMode)) \
|
||||
X(SetRenderVSync, bool, (SDL_Renderer*, int)) \
|
||||
X(CreateTexture, SDL_Texture*, (SDL_Renderer*, SDL_PixelFormat, SDL_TextureAccess, int, int)) \
|
||||
X(LockTexture, bool, (SDL_Texture*, const SDL_Rect*, void**, int*)) \
|
||||
X(UnlockTexture, void, (SDL_Texture*)) \
|
||||
X(GetMouseFocus, SDL_Window*, (void)) \
|
||||
X(GetMouseState, SDL_MouseButtonFlags, (float*, float*)) \
|
||||
X(ShowCursor, bool, (void)) \
|
||||
X(GetPixelFormatName, const char*, (SDL_PixelFormat)) \
|
||||
X(GetScancodeName, const char *, (SDL_Scancode)) \
|
||||
X(GL_CreateContext, SDL_GLContext, (SDL_Window*)) \
|
||||
X(GL_GetProcAddress, SDL_FunctionPointer, (const char*)) \
|
||||
X(GL_SetAttribute, bool, (SDL_GLAttr, int)) \
|
||||
X(GL_SetSwapInterval, bool, (int)) \
|
||||
X(GL_SwapWindow, bool, (SDL_Window*))
|
||||
|
||||
#endif /* sdl3_syms_h */
|
|
@ -38,7 +38,8 @@ static void *Harness_LoadFunction(void *obj, const char *name) {
|
|||
#ifdef DETHRACE_SDL_DYNAMIC
|
||||
#define X_LOAD_FUNCTION(name, ret, args) \
|
||||
STR_JOIN(SYMBOL_PREFIX, name) = Harness_LoadFunction(OBJECT_NAME, "SDL_" #name); \
|
||||
if (STR_JOIN(SYMBOL_PREFIX, name) == NULL) { \
|
||||
if (STR_JOIN(SYMBOL_PREFIX, name) == NULL) { \
|
||||
fprintf(stderr, "Failed to load %s function: %s (%s)\n", SDL_NAME, "SDL_" #name, dlerror()); \
|
||||
goto failure; \
|
||||
}
|
||||
#else
|
||||
|
@ -57,6 +58,7 @@ static int STR_JOIN(SYMBOL_PREFIX,LoadSymbols)(void) {
|
|||
}
|
||||
}
|
||||
if (OBJECT_NAME == NULL) {
|
||||
fputs("Could not find " SDL_NAME " library\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue