wip
This commit is contained in:
parent
51c839f07f
commit
db63ac6dfb
|
@ -284,6 +284,7 @@ int PDNetInitialise(void) {
|
|||
gPlayer_id = PDGetTotalTime();
|
||||
sa_len = sizeof(struct sockaddr_in);
|
||||
dr_dprintf("PDNetInitialise()");
|
||||
gNumber_of_networks = 1;
|
||||
|
||||
memset(&gAny_addr, 0, sizeof(gAny_addr));
|
||||
memset(&gLocal_addr, 0, sizeof(gLocal_addr));
|
||||
|
|
|
@ -327,7 +327,7 @@ void PDShutdownSystem(void) {
|
|||
|
||||
if (gShow_fatal_error) {
|
||||
dr_dprintf("Displaying fatal error...");
|
||||
gHarness_platform.ShowErrorMessage(NULL, "Carmageddon Fatal Error", gFatal_error_string);
|
||||
gHarness_platform.ShowErrorMessage("Carmageddon Fatal Error", gFatal_error_string);
|
||||
}
|
||||
|
||||
dr_dprintf("Destroying window...");
|
||||
|
|
|
@ -279,7 +279,7 @@ void PDFatalError(char* pThe_str) {
|
|||
printf("FATAL ERROR: %s\n", pThe_str);
|
||||
dr_dprintf("FATAL ERROR: %s\n", pThe_str);
|
||||
#ifdef PLAY_NICE_WITH_GUI
|
||||
gHarness_platform.ShowErrorMessage(NULL, "Carmageddon Fatal Error", pThe_str);
|
||||
gHarness_platform.ShowErrorMessage("Carmageddon Fatal Error", pThe_str);
|
||||
#endif
|
||||
if (gBrZb_initialized) {
|
||||
gBrZb_initialized = 0;
|
||||
|
|
|
@ -35,7 +35,7 @@ typedef struct tHarness_platform {
|
|||
// Get ticks
|
||||
uint32_t (*GetTicks)(void);
|
||||
// Show error message
|
||||
int (*ShowErrorMessage)(void* window, char* text, char* caption);
|
||||
int (*ShowErrorMessage)(char* title, char* message);
|
||||
|
||||
// Create a window. Uses an underscore to avoid name collisions with windows.h `CreateWindow` macro
|
||||
void (*CreateWindow_)(const char* title, int nWidth, int nHeight, tHarness_window_type window_type);
|
||||
|
|
|
@ -11,7 +11,7 @@ static void null_destroy_window(void* hWnd) {
|
|||
null_time += 1;
|
||||
}
|
||||
|
||||
static int null_show_error_message(void* window, char* text, char* caption) {
|
||||
static int null_show_error_message(char* title, char* text) {
|
||||
null_time += 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -30,19 +30,19 @@ static int window_width, window_height;
|
|||
|
||||
#ifdef DETHRACE_SDL_DYNAMIC
|
||||
#ifdef _WIN32
|
||||
static const char * const possible_locations[] = {
|
||||
static const char* const possible_locations[] = {
|
||||
"SDL.dll",
|
||||
};
|
||||
#elif defined(__APPLE__)
|
||||
#define SHARED_OBJECT_NAME "libSDL"
|
||||
#define SDL1_LIBNAME "libSDL.dylib"
|
||||
static const char * const possible_locations[] = {
|
||||
"@loader_path/" SDL1_LIBNAME, /* MyApp.app/Contents/MacOS/libSDL2_dylib */
|
||||
static const char* const possible_locations[] = {
|
||||
"@loader_path/" SDL1_LIBNAME, /* MyApp.app/Contents/MacOS/libSDL2_dylib */
|
||||
"@executable_path/" SDL1_LIBNAME, /* MyApp.app/Contents/MacOS/libSDL2_dylib */
|
||||
SDL1_LIBNAME /* oh well, anywhere the system can see the .dylib (/usr/local/lib or whatever) */
|
||||
SDL1_LIBNAME /* oh well, anywhere the system can see the .dylib (/usr/local/lib or whatever) */
|
||||
};
|
||||
#else
|
||||
static const char * const possible_locations[] = {
|
||||
static const char* const possible_locations[] = {
|
||||
"libSDL-1.2.so.0",
|
||||
"libSDL-1.2.so",
|
||||
};
|
||||
|
@ -50,7 +50,7 @@ static const char * const possible_locations[] = {
|
|||
#endif
|
||||
|
||||
#ifdef DETHRACE_SDL_DYNAMIC
|
||||
static void *sdl1_so;
|
||||
static void* sdl1_so;
|
||||
#endif
|
||||
|
||||
#define OBJECT_NAME sdl1_so
|
||||
|
@ -268,7 +268,7 @@ static void SDL1_Harness_PaletteChanged(br_colour entries[256]) {
|
|||
}
|
||||
}
|
||||
|
||||
static int SDL1_Harness_ShowErrorMessage(void* window, char* text, char* caption) {
|
||||
static int SDL1_Harness_ShowErrorMessage(char* text, char* caption) {
|
||||
fprintf(stderr, "%s", text);
|
||||
#ifdef _WIN32
|
||||
MessageBoxA(NULL, text, caption, MB_ICONERROR);
|
||||
|
@ -312,4 +312,3 @@ const tPlatform_bootstrap SDL1_bootstrap = {
|
|||
ePlatform_cap_software,
|
||||
SDL1_Harness_Platform_Init,
|
||||
};
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "harness/trace.h"
|
||||
#include "sdl2_scancode_to_dinput.h"
|
||||
#include "sdl2_syms.h"
|
||||
#include "sdl_scancode_to_set1.h"
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(sdl2_platform_requires_SDL2, SDL_MAJOR_VERSION == 2);
|
||||
|
||||
|
@ -21,7 +22,7 @@ static int render_width, render_height;
|
|||
|
||||
static Uint32 last_frame_time;
|
||||
|
||||
static uint8_t directinput_key_state[SDL_NUM_SCANCODES];
|
||||
static uint8_t shadow_key_state[SDL_NUM_SCANCODES];
|
||||
|
||||
static struct {
|
||||
int x, y;
|
||||
|
@ -119,7 +120,7 @@ static int is_only_key_modifier(int modifier_flags, int flag_check) {
|
|||
|
||||
static void SDL2_Harness_ProcessWindowMessages(MSG_* msg) {
|
||||
SDL_Event event;
|
||||
int dinput_key;
|
||||
int set1_scancode;
|
||||
|
||||
while (SDL2_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
|
@ -141,20 +142,21 @@ static void SDL2_Harness_ProcessWindowMessages(MSG_* msg) {
|
|||
}
|
||||
}
|
||||
|
||||
// Map incoming SDL scancode to DirectInput DIK_* key code.
|
||||
// https://github.com/DanielGibson/Snippets/blob/master/sdl2_scancode_to_dinput.h
|
||||
dinput_key = sdlScanCodeToDirectInputKeyNum[event.key.keysym.scancode];
|
||||
if (dinput_key == 0) {
|
||||
// Map incoming SDL scancode to PC set 1 scan code as used by game code
|
||||
// set1_scancode = sdl_to_set1_scancode[event.key.keysym.scancode];
|
||||
int x = event.key.keysym.scancode;
|
||||
set1_scancode = sdlScanCodeToDirectInputKeyNum[event.key.keysym.scancode];
|
||||
if (set1_scancode == 0) {
|
||||
LOG_WARN("unexpected scan code %s (%d)", SDL2_GetScancodeName(event.key.keysym.scancode), event.key.keysym.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_KEYDOWN ? 0x80 : 0);
|
||||
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
gKeyboard_bits[dinput_key >> 5] |= (1 << (dinput_key & 0x1F));
|
||||
gKeyboard_bits[set1_scancode >> 5] |= (1 << (set1_scancode & 0x1F));
|
||||
shadow_key_state[set1_scancode] = 0xff;
|
||||
} else {
|
||||
gKeyboard_bits[dinput_key >> 5] &= ~(1 << (dinput_key & 0x1F));
|
||||
gKeyboard_bits[set1_scancode >> 5] &= ~(1 << (set1_scancode & 0x1F));
|
||||
shadow_key_state[set1_scancode] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -171,7 +173,7 @@ static void SDL2_Harness_ProcessWindowMessages(MSG_* msg) {
|
|||
}
|
||||
|
||||
static void SDL2_Harness_GetKeyboardState(unsigned int count, uint8_t* buffer) {
|
||||
memcpy(buffer, directinput_key_state, count);
|
||||
memcpy(buffer, shadow_key_state, count);
|
||||
}
|
||||
|
||||
static int SDL2_Harness_GetMouseButtons(int* pButton1, int* pButton2) {
|
||||
|
@ -225,9 +227,9 @@ static void limit_fps(void) {
|
|||
last_frame_time = SDL2_GetTicks();
|
||||
}
|
||||
|
||||
static int SDL2_Harness_ShowErrorMessage(void* window, char* text, char* caption) {
|
||||
fprintf(stderr, "%s", text);
|
||||
SDL2_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, caption, text, window);
|
||||
static int SDL2_Harness_ShowErrorMessage(char* title, char* message) {
|
||||
fprintf(stderr, "%s", message);
|
||||
SDL2_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,26 +22,24 @@
|
|||
|
||||
#include <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];
|
||||
}
|
||||
#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;
|
||||
}
|
||||
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 _SDL2_SCANCODE_TO_DINPUT_H_
|
||||
|
|
Loading…
Reference in New Issue