1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-08 15:27:35 +00:00
serenity/Ports/tuxracer/patches/source.patch
Jelle Raaijmakers 8d8f74e334 Ports: Implement SDL_QUIT event in Tux Racer
This allows the user to close Tux Racer by closing the window.
2021-12-30 14:24:29 +01:00

376 lines
10 KiB
Diff

diff -ur tuxracer-0.61-original/src/game_config.c tuxracer-0.61/src/game_config.c
--- tuxracer-0.61-original/src/game_config.c 2001-01-30 20:04:43.000000000 +0000
+++ tuxracer-0.61/src/game_config.c 2021-12-26 13:41:33.341076372 +0000
@@ -114,26 +114,26 @@
*/
#define INIT_PARAM( nam, val, typename, commnt ) \
- Params. ## nam ## .loaded = False; \
- Params. ## nam ## .name = #nam; \
- Params. ## nam ## .deflt. ## typename ## _val = val; \
- Params. ## nam ## .comment = commnt;
+ Params.nam.loaded = False; \
+ Params.nam.name = #nam; \
+ Params.nam.deflt.typename ## _val = val; \
+ Params.nam.comment = commnt;
#define INIT_PARAM_STRING( nam, val, commnt ) \
INIT_PARAM( nam, val, string, commnt ); \
- Params. ## nam ## .type = PARAM_STRING;
+ Params.nam.type = PARAM_STRING;
#define INIT_PARAM_CHAR( nam, val, commnt ) \
INIT_PARAM( nam, val, char, commnt ); \
- Params. ## nam ## .type = PARAM_CHAR;
+ Params.nam.type = PARAM_CHAR;
#define INIT_PARAM_INT( nam, val, commnt ) \
INIT_PARAM( nam, val, int, commnt ); \
- Params. ## nam ## .type = PARAM_INT;
+ Params.nam.type = PARAM_INT;
#define INIT_PARAM_BOOL( nam, val, commnt ) \
INIT_PARAM( nam, val, bool, commnt ); \
- Params. ## nam ## .type = PARAM_BOOL;
+ Params.nam.type = PARAM_BOOL;
/*
@@ -310,13 +310,13 @@
*/
#define FN_PARAM( name, typename, type ) \
type getparam_ ## name() { \
- if ( !Params. ## name ## .loaded ) { \
- fetch_param_ ## typename( &( Params. ## name ) ); \
+ if ( !Params.name.loaded ) { \
+ fetch_param_ ## typename( &( Params.name ) ); \
} \
- return Params. ## name ## .val. ## typename ## _val; \
+ return Params.name.val.typename ## _val; \
} \
void setparam_ ## name( type val) { \
- set_param_ ## typename( &( Params. ## name ), val ); }
+ set_param_ ## typename( &( Params.name ), val ); }
#define FN_PARAM_STRING( name ) \
FN_PARAM( name, string, char* )
@@ -505,7 +505,7 @@
"# decreasing this number, at the cost of lower image quality." );
INIT_PARAM_BOOL(
- fullscreen, True,
+ fullscreen, False,
"# If true then the game will run in full-screen mode." );
INIT_PARAM_INT(
diff -ur tuxracer-0.61-original/src/keyboard.c tuxracer-0.61/src/keyboard.c
--- tuxracer-0.61-original/src/keyboard.c 2001-01-13 22:09:51.000000000 +0000
+++ tuxracer-0.61/src/keyboard.c 2021-12-26 13:41:33.341076372 +0000
@@ -23,11 +23,17 @@
#include "loop.h"
#define KEYMAP_SIZE 1000
-#define KEYTABLE_SIZE WSK_LAST
-#define SPECIAL_KEYTABLE_SIZE WSK_LAST
+#define KEYTABLE_SIZE 100
-static key_cb_t keytable[KEYTABLE_SIZE];
-static key_cb_t special_keytable[SPECIAL_KEYTABLE_SIZE];
+static key_cb_t keytable_callback[KEYTABLE_SIZE];
+static int keytable_key[KEYTABLE_SIZE];
+static int num_keytable_entries = 0;
+
+static key_cb_t special_keytable_callback[KEYTABLE_SIZE];
+static int special_keytable_key[KEYTABLE_SIZE];
+static int num_special_keytable_entries = 0;
+
+static key_cb_t default_keytable_callback = NULL;
static keymap_t keymap[KEYMAP_SIZE];
static int num_keymap_entries = 0;
@@ -50,19 +56,6 @@
return 0; /* success */
}
-static void fill_keytable( key_cb_t value )
-{
- int i;
-
- for (i=0; i<KEYTABLE_SIZE; i++) {
- keytable[i] = value;
- }
-
- for (i=0; i<SPECIAL_KEYTABLE_SIZE; i++) {
- special_keytable[i] = value;
- }
-}
-
static int insert_keytable_entries( char *keys, key_cb_t callback )
{
key_desc_t *key_list;
@@ -74,9 +67,13 @@
if ( num_keys > 0 ) {
for ( i=0; i<num_keys; i++ ) {
if ( key_list[i].special ) {
- special_keytable[ key_list[i].key ] = callback;
+ special_keytable_callback[num_special_keytable_entries] = callback;
+ special_keytable_key[num_special_keytable_entries] = key_list[i].key;
+ ++num_special_keytable_entries;
} else {
- keytable[ key_list[i].key ] = callback;
+ keytable_callback[num_keytable_entries] = callback;
+ keytable_key[num_keytable_entries] = key_list[i].key;
+ ++num_keytable_entries;
}
}
@@ -92,15 +89,14 @@
{
int i;
char *keys;
- fill_keytable( NULL );
/* Handle default callbacks first */
for (i=0; i<num_keymap_entries; i++) {
if ( ( keymap[i].mode == mode || keymap[i].mode == ALL_MODES ) &&
keymap[i].keymap_class == DEFAULT_CALLBACK )
{
- fill_keytable( keymap[i].key_cb );
- }
+ default_keytable_callback = keymap[i].key_cb;
+ }
}
/* Handle other classes */
@@ -155,7 +151,9 @@
bool_t release, int x, int y )
{
static game_mode_t last_mode = NO_MODE;
- key_cb_t *table;
+ int* table_key;
+ key_cb_t* table_callback;
+ int num_entries;
if ( is_mode_change_pending() ) {
/* Don't process keyboard events until the mode change happens */
@@ -168,18 +166,28 @@
}
if ( special ) {
- table = special_keytable;
+ table_callback = special_keytable_callback;
+ table_key = special_keytable_key;
+ num_entries = num_special_keytable_entries;
} else {
- table = keytable;
+ table_callback = keytable_callback;
+ table_key = keytable_key;
+ num_entries = num_keytable_entries;
}
if ( isalpha( key ) ) {
- key = tolower( key );
+ key = tolower( key );
}
- if ( table[key] != NULL ) {
- (table[key])( key, special, release, x, y );
- }
+ // Find index
+ int callback_index = 0;
+ for (; callback_index < num_entries; ++callback_index) {
+ if (table_key[callback_index] == key)
+ break;
+ }
+ if (callback_index < num_entries) {
+ (table_callback[callback_index])(key, special, release, x, y);
+ }
}
void init_keyboard()
diff -ur tuxracer-0.61-original/src/winsys.c tuxracer-0.61/src/winsys.c
--- tuxracer-0.61-original/src/winsys.c 2001-01-13 22:09:51.000000000 +0000
+++ tuxracer-0.61/src/winsys.c 2021-12-27 23:10:37.344295969 +0000
@@ -36,7 +36,8 @@
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
-static SDL_Surface *screen = NULL;
+static SDL_Window *screen = NULL;
+static SDL_GLContext context = NULL;
static winsys_display_func_t display_func = NULL;
static winsys_idle_func_t idle_func = NULL;
@@ -164,7 +165,7 @@
*/
void winsys_swap_buffers()
{
- SDL_GL_SwapBuffers();
+ SDL_GL_SwapWindow(screen);
}
@@ -177,7 +178,7 @@
*/
void winsys_warp_pointer( int x, int y )
{
- SDL_WarpMouse( x, y );
+ SDL_WarpMouseInWindow( screen, x, y );
}
@@ -190,14 +191,14 @@
*/
static void setup_sdl_video_mode()
{
- Uint32 video_flags = SDL_OPENGL;
+ Uint32 video_flags = SDL_WINDOW_OPENGL;
int bpp = 0;
int width, height;
if ( getparam_fullscreen() ) {
- video_flags |= SDL_FULLSCREEN;
+ video_flags |= SDL_WINDOW_FULLSCREEN;
} else {
- video_flags |= SDL_RESIZABLE;
+ video_flags |= SDL_WINDOW_RESIZABLE;
}
switch ( getparam_bpp_mode() ) {
@@ -224,12 +225,16 @@
width = getparam_x_resolution();
height = getparam_y_resolution();
- if ( ( screen = SDL_SetVideoMode( width, height, bpp, video_flags ) ) ==
+ if ( ( screen = SDL_CreateWindow("Tuxracer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, video_flags ) ) ==
NULL )
{
handle_system_error( 1, "Couldn't initialize video: %s",
SDL_GetError() );
}
+
+ context = SDL_GL_CreateContext(screen);
+ if (context == NULL)
+ handle_system_error( 1, "Couldn't initialize video: %s", SDL_GetError() );
}
@@ -266,8 +271,7 @@
setup_sdl_video_mode();
- SDL_WM_SetCaption( window_title, icon_title );
-
+ SDL_SetWindowTitle(screen, window_title);
}
@@ -280,6 +284,7 @@
*/
void winsys_shutdown()
{
+ SDL_GL_DeleteContext(context);
SDL_Quit();
}
@@ -293,12 +298,6 @@
*/
void winsys_enable_key_repeat( bool_t enabled )
{
- if ( enabled ) {
- SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY,
- SDL_DEFAULT_REPEAT_INTERVAL );
- } else {
- SDL_EnableKeyRepeat( 0, 0 );
- }
}
@@ -330,9 +329,6 @@
while (True) {
- SDL_LockAudio();
- SDL_UnlockAudio();
-
while ( SDL_PollEvent( &event ) ) {
switch ( event.type ) {
@@ -384,18 +380,19 @@
}
break;
- case SDL_VIDEORESIZE:
+ case SDL_WINDOWEVENT_RESIZED:
setup_sdl_video_mode();
if ( reshape_func ) {
- (*reshape_func)( event.resize.w,
- event.resize.h );
+ (*reshape_func)( event.window.data1,
+ event.window.data2 );
}
break;
- }
- SDL_LockAudio();
- SDL_UnlockAudio();
+ case SDL_QUIT:
+ winsys_exit(0);
+ break;
+ }
}
if ( redisplay && display_func ) {
diff -ur tuxracer-0.61-original/src/winsys.h tuxracer-0.61/src/winsys.h
--- tuxracer-0.61-original/src/winsys.h 2001-01-13 22:09:51.000000000 +0000
+++ tuxracer-0.61/src/winsys.h 2021-12-26 13:41:33.341076372 +0000
@@ -48,16 +48,16 @@
WSK_NOT_AVAIL = SDLK_UNKNOWN,
/* Numeric keypad */
- WSK_KP0 = SDLK_KP0,
- WSK_KP1 = SDLK_KP1,
- WSK_KP2 = SDLK_KP2,
- WSK_KP3 = SDLK_KP3,
- WSK_KP4 = SDLK_KP4,
- WSK_KP5 = SDLK_KP5,
- WSK_KP6 = SDLK_KP6,
- WSK_KP7 = SDLK_KP7,
- WSK_KP8 = SDLK_KP8,
- WSK_KP9 = SDLK_KP9,
+ WSK_KP0 = SDLK_KP_0,
+ WSK_KP1 = SDLK_KP_1,
+ WSK_KP2 = SDLK_KP_2,
+ WSK_KP3 = SDLK_KP_3,
+ WSK_KP4 = SDLK_KP_4,
+ WSK_KP5 = SDLK_KP_5,
+ WSK_KP6 = SDLK_KP_6,
+ WSK_KP7 = SDLK_KP_7,
+ WSK_KP8 = SDLK_KP_8,
+ WSK_KP9 = SDLK_KP_9,
WSK_KP_PERIOD = SDLK_KP_PERIOD,
WSK_KP_DIVIDE = SDLK_KP_DIVIDE,
WSK_KP_MULTIPLY = SDLK_KP_MULTIPLY,
@@ -95,17 +95,17 @@
WSK_F15 = SDLK_F15,
/* Key state modifier keys */
- WSK_NUMLOCK = SDLK_NUMLOCK,
+ WSK_NUMLOCK = SDLK_NUMLOCKCLEAR,
WSK_CAPSLOCK = SDLK_CAPSLOCK,
- WSK_SCROLLOCK = SDLK_SCROLLOCK,
+ WSK_SCROLLOCK = SDLK_SCROLLLOCK,
WSK_RSHIFT = SDLK_RSHIFT,
WSK_LSHIFT = SDLK_LSHIFT,
WSK_RCTRL = SDLK_RCTRL,
WSK_LCTRL = SDLK_LCTRL,
WSK_RALT = SDLK_RALT,
WSK_LALT = SDLK_LALT,
- WSK_RMETA = SDLK_RMETA,
- WSK_LMETA = SDLK_LMETA,
+ WSK_RMETA = SDLK_RALT,
+ WSK_LMETA = SDLK_LALT,
WSK_LAST