wip
This commit is contained in:
parent
51c839f07f
commit
db63ac6dfb
|
@ -284,6 +284,7 @@ int PDNetInitialise(void) {
|
||||||
gPlayer_id = PDGetTotalTime();
|
gPlayer_id = PDGetTotalTime();
|
||||||
sa_len = sizeof(struct sockaddr_in);
|
sa_len = sizeof(struct sockaddr_in);
|
||||||
dr_dprintf("PDNetInitialise()");
|
dr_dprintf("PDNetInitialise()");
|
||||||
|
gNumber_of_networks = 1;
|
||||||
|
|
||||||
memset(&gAny_addr, 0, sizeof(gAny_addr));
|
memset(&gAny_addr, 0, sizeof(gAny_addr));
|
||||||
memset(&gLocal_addr, 0, sizeof(gLocal_addr));
|
memset(&gLocal_addr, 0, sizeof(gLocal_addr));
|
||||||
|
|
|
@ -327,7 +327,7 @@ void PDShutdownSystem(void) {
|
||||||
|
|
||||||
if (gShow_fatal_error) {
|
if (gShow_fatal_error) {
|
||||||
dr_dprintf("Displaying 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...");
|
dr_dprintf("Destroying window...");
|
||||||
|
|
|
@ -279,7 +279,7 @@ void PDFatalError(char* pThe_str) {
|
||||||
printf("FATAL ERROR: %s\n", pThe_str);
|
printf("FATAL ERROR: %s\n", pThe_str);
|
||||||
dr_dprintf("FATAL ERROR: %s\n", pThe_str);
|
dr_dprintf("FATAL ERROR: %s\n", pThe_str);
|
||||||
#ifdef PLAY_NICE_WITH_GUI
|
#ifdef PLAY_NICE_WITH_GUI
|
||||||
gHarness_platform.ShowErrorMessage(NULL, "Carmageddon Fatal Error", pThe_str);
|
gHarness_platform.ShowErrorMessage("Carmageddon Fatal Error", pThe_str);
|
||||||
#endif
|
#endif
|
||||||
if (gBrZb_initialized) {
|
if (gBrZb_initialized) {
|
||||||
gBrZb_initialized = 0;
|
gBrZb_initialized = 0;
|
||||||
|
|
|
@ -35,7 +35,7 @@ typedef struct tHarness_platform {
|
||||||
// Get ticks
|
// Get ticks
|
||||||
uint32_t (*GetTicks)(void);
|
uint32_t (*GetTicks)(void);
|
||||||
// Show error message
|
// 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
|
// 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);
|
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;
|
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;
|
null_time += 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
fprintf(stderr, "%s", text);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
MessageBoxA(NULL, text, caption, MB_ICONERROR);
|
MessageBoxA(NULL, text, caption, MB_ICONERROR);
|
||||||
|
@ -312,4 +312,3 @@ const tPlatform_bootstrap SDL1_bootstrap = {
|
||||||
ePlatform_cap_software,
|
ePlatform_cap_software,
|
||||||
SDL1_Harness_Platform_Init,
|
SDL1_Harness_Platform_Init,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "harness/trace.h"
|
#include "harness/trace.h"
|
||||||
#include "sdl2_scancode_to_dinput.h"
|
#include "sdl2_scancode_to_dinput.h"
|
||||||
#include "sdl2_syms.h"
|
#include "sdl2_syms.h"
|
||||||
|
#include "sdl_scancode_to_set1.h"
|
||||||
|
|
||||||
SDL_COMPILE_TIME_ASSERT(sdl2_platform_requires_SDL2, SDL_MAJOR_VERSION == 2);
|
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 Uint32 last_frame_time;
|
||||||
|
|
||||||
static uint8_t directinput_key_state[SDL_NUM_SCANCODES];
|
static uint8_t shadow_key_state[SDL_NUM_SCANCODES];
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
int x, y;
|
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) {
|
static void SDL2_Harness_ProcessWindowMessages(MSG_* msg) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int dinput_key;
|
int set1_scancode;
|
||||||
|
|
||||||
while (SDL2_PollEvent(&event)) {
|
while (SDL2_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
|
@ -141,20 +142,21 @@ static void SDL2_Harness_ProcessWindowMessages(MSG_* msg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map incoming SDL scancode to DirectInput DIK_* key code.
|
// Map incoming SDL scancode to PC set 1 scan code as used by game code
|
||||||
// https://github.com/DanielGibson/Snippets/blob/master/sdl2_scancode_to_dinput.h
|
// set1_scancode = sdl_to_set1_scancode[event.key.keysym.scancode];
|
||||||
dinput_key = sdlScanCodeToDirectInputKeyNum[event.key.keysym.scancode];
|
int x = event.key.keysym.scancode;
|
||||||
if (dinput_key == 0) {
|
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);
|
LOG_WARN("unexpected scan code %s (%d)", SDL2_GetScancodeName(event.key.keysym.scancode), event.key.keysym.scancode);
|
||||||
return;
|
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) {
|
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 {
|
} 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;
|
break;
|
||||||
|
|
||||||
|
@ -171,7 +173,7 @@ static void SDL2_Harness_ProcessWindowMessages(MSG_* msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SDL2_Harness_GetKeyboardState(unsigned int count, uint8_t* buffer) {
|
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) {
|
static int SDL2_Harness_GetMouseButtons(int* pButton1, int* pButton2) {
|
||||||
|
@ -225,9 +227,9 @@ static void limit_fps(void) {
|
||||||
last_frame_time = SDL2_GetTicks();
|
last_frame_time = SDL2_GetTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int SDL2_Harness_ShowErrorMessage(void* window, char* text, char* caption) {
|
static int SDL2_Harness_ShowErrorMessage(char* title, char* message) {
|
||||||
fprintf(stderr, "%s", text);
|
fprintf(stderr, "%s", message);
|
||||||
SDL2_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, caption, text, window);
|
SDL2_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,22 +22,20 @@
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#if 0 // Usage Example:
|
#if 0
|
||||||
#include "sdl2_scancode_to_dinput.h"
|
// Usage Example:
|
||||||
static int SDLScanCodeToKeyNum(SDL_Scancode sc)
|
// #include "sdl2_scancode_to_dinput.h"
|
||||||
{
|
static int SDLScanCodeToKeyNum(SDL_Scancode sc) {
|
||||||
int idx = (int)sc;
|
int idx = (int)sc;
|
||||||
assert(idx >= 0 && idx < SDL_NUM_SCANCODES);
|
assert(idx >= 0 && idx < SDL_NUM_SCANCODES);
|
||||||
return scanCodeToKeyNum[idx];
|
return scanCodeToKeyNum[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_Scancode KeyNumToSDLScanCode( int keyNum )
|
static SDL_Scancode KeyNumToSDLScanCode(int keyNum) {
|
||||||
{
|
if (keyNum >= 0 && keyNum < 0xEF) {
|
||||||
if( keyNum >= 0 && keyNum < 0xEF )
|
for (int i = 0; i < SDL_NUM_SCANCODES; ++i) {
|
||||||
{
|
if (scanCodeToKeyNum[i] == keyNum)
|
||||||
for(int i = 0; i < SDL_NUM_SCANCODES; ++i)
|
return (SDL_Scancode)i;
|
||||||
{
|
|
||||||
if(scanCodeToKeyNum[i] == keyNum) return (SDL_Scancode)i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SDL_SCANCODE_UNKNOWN;
|
return SDL_SCANCODE_UNKNOWN;
|
||||||
|
|
Loading…
Reference in New Issue