From 8b7b718c66cdb0ec98547bff9a879c1547fd84cf Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 16 Jul 2023 08:14:47 +0300 Subject: [PATCH 17/17] sdl2: Move reusable SDL_Events from ui_main() to module level To make sure they stay in scope. See osdn #48399 Signed-off-by: Marko Lindqvist --- client/gui-sdl2/gui_main.c | 27 ++++++++++++++++++--------- client/gui-sdl2/gui_main.h | 2 ++ client/gui-sdl2/mapview.c | 7 +++---- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/client/gui-sdl2/gui_main.c b/client/gui-sdl2/gui_main.c index 3eeea1a7db..c0e38a2f24 100644 --- a/client/gui-sdl2/gui_main.c +++ b/client/gui-sdl2/gui_main.c @@ -99,7 +99,6 @@ Uint32 widget_info_counter = 0; int MOVE_STEP_X = DEFAULT_MOVE_STEP; int MOVE_STEP_Y = DEFAULT_MOVE_STEP; extern bool draw_goto_patrol_lines; -SDL_Event *flush_event = NULL; bool is_unit_move_blocked; bool LSHIFT; bool RSHIFT; @@ -125,9 +124,16 @@ static enum direction8 scroll_dir; static struct finger_behavior finger_behavior; static struct mouse_button_behavior button_behavior; +static SDL_Event __net_user_event; +static SDL_Event __anim_user_event; +static SDL_Event __info_user_event; +static SDL_Event __flush_user_event; +static SDL_Event __map_scroll_user_event; + static SDL_Event *net_user_event = NULL; static SDL_Event *anim_user_event = NULL; static SDL_Event *info_user_event = NULL; +static SDL_Event *flush_user_event = NULL; static SDL_Event *map_scroll_user_event = NULL; static void print_usage(void); @@ -609,7 +615,7 @@ Uint16 gui_event_loop(void *data, t_last_map_scrolling = t_last_unit_anim = real_timer_next_call = SDL_GetTicks(); while (ID == ID_ERROR) { /* ========================================= */ - /* net check with 10ms delay event loop */ + /* Net check with 10ms delay event loop */ if (net_socket >= 0) { FD_ZERO(&civfdset); @@ -634,7 +640,7 @@ Uint16 gui_event_loop(void *data, } } } - } else { /* if connection is not establish */ + } else { /* If connection is not establish */ SDL_Delay(10); } /* ========================================= */ @@ -1013,11 +1019,6 @@ static void migrate_options_from_sdl(void) **************************************************************************/ int ui_main(int argc, char *argv[]) { - SDL_Event __net_user_event; - SDL_Event __anim_user_event; - SDL_Event __info_user_event; - SDL_Event __flush_user_event; - SDL_Event __map_scroll_user_event; Uint32 flags = 0; parse_options(argc, argv); @@ -1075,7 +1076,7 @@ int ui_main(int argc, char *argv[]) __flush_user_event.user.code = FLUSH; __flush_user_event.user.data1 = NULL; __flush_user_event.user.data2 = NULL; - flush_event = &__flush_user_event; + flush_user_event = &__flush_user_event; SDL_zero(__map_scroll_user_event); __map_scroll_user_event.type = user_event_type; @@ -1320,3 +1321,11 @@ void insert_client_build_info(char *outbuf, size_t outlen) { /* PORTME */ } + +/**********************************************************************//** + Queue a flush event to be handled later by SDL. +**************************************************************************/ +bool flush_event(void) +{ + return SDL_PushEvent(flush_user_event) >= 0; +} diff --git a/client/gui-sdl2/gui_main.h b/client/gui-sdl2/gui_main.h index 98fc8700cf..0be422163e 100644 --- a/client/gui-sdl2/gui_main.h +++ b/client/gui-sdl2/gui_main.h @@ -132,6 +132,8 @@ Uint16 gui_event_loop(void *data, void (*loop_action)(void *data), unsigned default_font_size(struct theme *act_theme); void update_font_from_theme(int theme_font_size); +bool flush_event(void); + /* Shrink sizes for 320x240 screen */ #ifdef GUI_SDL2_SMALL_SCREEN #define adj_size(size) ((size) / 2) diff --git a/client/gui-sdl2/mapview.c b/client/gui-sdl2/mapview.c index 119bbefd84..f190c89b18 100644 --- a/client/gui-sdl2/mapview.c +++ b/client/gui-sdl2/mapview.c @@ -68,7 +68,6 @@ #include "mapview.h" -extern SDL_Event *flush_event; extern SDL_Rect *info_area; int overview_start_x = 0; @@ -147,17 +146,17 @@ void unqueue_flush(void) /**********************************************************************//** Called when a region is marked dirty, this function queues a flush event - to be handled later by SDL. The flush may end up being done + to be handled later by SDL. The flush may end up being done by freeciv before then, in which case it will be a wasted call. **************************************************************************/ void queue_flush(void) { if (!is_flush_queued) { - if (SDL_PushEvent(flush_event) >= 0) { + if (flush_event()) { is_flush_queued = TRUE; } else { /* We don't want to set is_flush_queued in this case, since then - * the flush code would simply stop working. But this means the + * the flush code would simply stop working. But this means the * below message may be repeated many times. */ bugreport_request(_("Failed to add events to SDL2 event buffer: %s"), SDL_GetError()); -- 2.40.1