From cea15eedbbebfd5fdb3458feff9d56136cf00cf7 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 16 Jul 2023 08:40:35 +0300 Subject: [PATCH 18/18] 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 9b9b566bd5..0474ed3d80 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 __pMap_Scroll_User_Event; + static SDL_Event *pNet_User_Event = NULL; static SDL_Event *pAnim_User_Event = NULL; static SDL_Event *pInfo_User_Event = NULL; +static SDL_Event *flush_user_event = NULL; static SDL_Event *pMap_Scroll_User_Event = NULL; static void print_usage(void); @@ -602,7 +608,7 @@ Uint16 gui_event_loop(void *pData, 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); @@ -627,7 +633,7 @@ Uint16 gui_event_loop(void *pData, } } } - } else { /* if connection is not establish */ + } else { /* If connection is not establish */ SDL_Delay(10); } /* ========================================= */ @@ -977,11 +983,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 __pMap_Scroll_User_Event; Uint32 flags = 0; parse_options(argc, argv); @@ -1030,7 +1031,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(__pMap_Scroll_User_Event); __pMap_Scroll_User_Event.type = user_event_type; @@ -1276,3 +1277,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 7b9416f9ab..c2355e1b0a 100644 --- a/client/gui-sdl2/gui_main.h +++ b/client/gui-sdl2/gui_main.h @@ -128,6 +128,8 @@ Uint16 gui_event_loop(void *pData, void (*loop_action)(void *pData), 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 SMALL_SCREEN #define adj_size(size) ((size) / 2) diff --git a/client/gui-sdl2/mapview.c b/client/gui-sdl2/mapview.c index fee9899d94..506d1a3650 100644 --- a/client/gui-sdl2/mapview.c +++ b/client/gui-sdl2/mapview.c @@ -67,7 +67,6 @@ #include "mapview.h" -extern SDL_Event *flush_event; extern SDL_Rect *pInfo_Area; int overview_start_x = 0; @@ -146,17 +145,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. */ log_error(_("Failed to add events to SDL2 event buffer: %s"), SDL_GetError()); -- 2.40.1