From 6405094c415b57044ac39a5505ff301fafc7ab74 Mon Sep 17 00:00:00 2001 From: Eric Branlund Date: Mon, 9 Mar 2020 09:19:59 -0700 Subject: [PATCH] Put the do_cmd_redraw() and wakeup_event_loop() combination in a separate function. Also, character_generated always implies game_in_progress, so don't need to test the latter when testing the former. --- src/main-cocoa.m | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/main-cocoa.m b/src/main-cocoa.m index 00adb95b2..151896658 100644 --- a/src/main-cocoa.m +++ b/src/main-cocoa.m @@ -1243,6 +1243,7 @@ static Boolean game_in_progress = FALSE; #pragma mark Prototypes +static BOOL redraw_for_tiles_or_term0_font(void); static void wakeup_event_loop(void); static void hook_plog(const char *str); static void hook_quit(const char * str); @@ -3595,6 +3596,27 @@ static errr Term_text_cocoa( } /** + * Handle redrawing for a change to the tile set, tile scaling, or main window + * font. Returns YES if the redrawing was initiated. Otherwise returns NO. + */ +static BOOL redraw_for_tiles_or_term0_font(void) +{ + /* + * In Angband 4.2, do_cmd_redraw() will always clear, but only provides + * something to replace the erased content if a character has been + * generated. In Hengband, do_cmd_redraw() isn't safe to call unless a + * character has been generated. Therefore, only call it if a character + * has been generated. + */ + if (character_generated) { + do_cmd_redraw(); + wakeup_event_loop(); + return YES; + } + return NO; +} + +/** * Post a nonsense event so that our event loop wakes up */ static void wakeup_event_loop(void) @@ -4140,11 +4162,7 @@ static void play_sound(int event) NSEnableScreenUpdates(); - if (mainTerm == 0 && game_in_progress && character_generated) { - /* Mimics the logic in setGraphicsMode(). */ - do_cmd_redraw(); - wakeup_event_loop(); - } else { + if (mainTerm != 0 || ! redraw_for_tiles_or_term0_font()) { [(id)angbandContext requestRedraw]; } } @@ -4576,19 +4594,11 @@ static void play_sound(int event) arg_bigtile = TRUE; } - if (game_in_progress && character_generated) - { - if (arg_bigtile != use_bigtile) { - Term_activate(angband_term[0]); - Term_resize(angband_term[0]->wid, angband_term[0]->hgt); - } - - /* Hack -- Force redraw */ - do_cmd_redraw(); - - /* Wake up the event loop so it notices the change */ - wakeup_event_loop(); + if (arg_bigtile != use_bigtile) { + Term_activate(angband_term[0]); + Term_resize(angband_term[0]->wid, angband_term[0]->hgt); } + redraw_for_tiles_or_term0_font(); } - (void)selectWindow: (id)sender @@ -4629,13 +4639,10 @@ static void play_sound(int event) forKey:AngbandBigTileDefaultsKey]; if (graphics_are_enabled()) { arg_bigtile = (is_on) ? FALSE : TRUE; - /* Mimics the logic in setGraphicsMode(). */ - if (game_in_progress && character_generated && - arg_bigtile != use_bigtile) { + if (arg_bigtile != use_bigtile) { Term_activate(angband_term[0]); Term_resize(angband_term[0]->wid, angband_term[0]->hgt); - do_cmd_redraw(); - wakeup_event_loop(); + redraw_for_tiles_or_term0_font(); } } } -- 2.11.0