|
@@ -1,396 +0,0 @@
|
|
-From 04c10bd91f64e3cbbcd827fc439ef8018473bcc9 Mon Sep 17 00:00:00 2001
|
|
|
|
-From: Jelle Raaijmakers <jelle@gmta.nl>
|
|
|
|
-Date: Tue, 28 Dec 2021 00:15:59 +0100
|
|
|
|
-Subject: [PATCH 2/2] Big bag of random changes to the source
|
|
|
|
-
|
|
|
|
-FIXME: Split this up sensibly
|
|
|
|
----
|
|
|
|
- src/game_config.c | 26 +++++++++----------
|
|
|
|
- src/keyboard.c | 66 ++++++++++++++++++++++++++---------------------
|
|
|
|
- src/winsys.c | 45 +++++++++++++++-----------------
|
|
|
|
- src/winsys.h | 28 ++++++++++----------
|
|
|
|
- 4 files changed, 85 insertions(+), 80 deletions(-)
|
|
|
|
-
|
|
|
|
-diff --git a/src/game_config.c b/src/game_config.c
|
|
|
|
-index f12bb2d..35b6036 100644
|
|
|
|
---- a/src/game_config.c
|
|
|
|
-+++ b/src/game_config.c
|
|
|
|
-@@ -114,26 +114,26 @@ struct param {
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- #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 @@ void set_param_bool( struct param *p, bool_t new_val )
|
|
|
|
- */
|
|
|
|
- #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 @@ void init_game_configuration()
|
|
|
|
- "# 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 --git a/src/keyboard.c b/src/keyboard.c
|
|
|
|
-index d2b01ed..b0d38f5 100644
|
|
|
|
---- a/src/keyboard.c
|
|
|
|
-+++ b/src/keyboard.c
|
|
|
|
-@@ -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 @@ int add_keymap_entry( game_mode_t mode, keymap_class_t keymap_class,
|
|
|
|
- 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 @@ static int insert_keytable_entries( char *keys, key_cb_t callback )
|
|
|
|
- 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 @@ static void init_keytable( game_mode_t mode )
|
|
|
|
- {
|
|
|
|
- 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 @@ static void keyboard_handler( unsigned int key, bool_t special,
|
|
|
|
- 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 @@ static void keyboard_handler( unsigned int key, bool_t special,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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 --git a/src/winsys.c b/src/winsys.c
|
|
|
|
-index d932a1d..636d8f2 100644
|
|
|
|
---- a/src/winsys.c
|
|
|
|
-+++ b/src/winsys.c
|
|
|
|
-@@ -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_set_passive_motion_func( winsys_motion_func_t func )
|
|
|
|
- */
|
|
|
|
- void winsys_swap_buffers()
|
|
|
|
- {
|
|
|
|
-- SDL_GL_SwapBuffers();
|
|
|
|
-+ SDL_GL_SwapWindow(screen);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@@ -177,7 +178,7 @@ void winsys_swap_buffers()
|
|
|
|
- */
|
|
|
|
- void winsys_warp_pointer( int x, int y )
|
|
|
|
- {
|
|
|
|
-- SDL_WarpMouse( x, y );
|
|
|
|
-+ SDL_WarpMouseInWindow( screen, x, y );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@@ -190,14 +191,14 @@ void winsys_warp_pointer( int x, int y )
|
|
|
|
- */
|
|
|
|
- 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 @@ static void setup_sdl_video_mode()
|
|
|
|
- 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 @@ void winsys_init( int *argc, char **argv, char *window_title,
|
|
|
|
-
|
|
|
|
- setup_sdl_video_mode();
|
|
|
|
-
|
|
|
|
-- SDL_WM_SetCaption( window_title, icon_title );
|
|
|
|
--
|
|
|
|
-+ SDL_SetWindowTitle(screen, window_title);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@@ -280,6 +284,7 @@ void winsys_init( int *argc, char **argv, char *window_title,
|
|
|
|
- */
|
|
|
|
- void winsys_shutdown()
|
|
|
|
- {
|
|
|
|
-+ SDL_GL_DeleteContext(context);
|
|
|
|
- SDL_Quit();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-@@ -293,12 +298,6 @@ void winsys_shutdown()
|
|
|
|
- */
|
|
|
|
- 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 @@ void winsys_process_events()
|
|
|
|
-
|
|
|
|
- while (True) {
|
|
|
|
-
|
|
|
|
-- SDL_LockAudio();
|
|
|
|
-- SDL_UnlockAudio();
|
|
|
|
--
|
|
|
|
- while ( SDL_PollEvent( &event ) ) {
|
|
|
|
-
|
|
|
|
- switch ( event.type ) {
|
|
|
|
-@@ -384,18 +380,19 @@ void winsys_process_events()
|
|
|
|
- }
|
|
|
|
- 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 --git a/src/winsys.h b/src/winsys.h
|
|
|
|
-index 4a51f8d..1cf7ca9 100644
|
|
|
|
---- a/src/winsys.h
|
|
|
|
-+++ b/src/winsys.h
|
|
|
|
-@@ -48,16 +48,16 @@ typedef enum {
|
|
|
|
- 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 @@ typedef enum {
|
|
|
|
- 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
|
|
|
|
-
|
|
|
|
---
|
|
|
|
-2.36.1
|
|
|
|
-
|
|
|