diff options
author | Bardur Arantsson <bardur@scientician.net> | 2019-02-15 19:20:25 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2019-02-15 19:20:25 +0100 |
commit | 8700399d87d16e92a6f14207a5e4b99ebf6d4f7a (patch) | |
tree | 46c3dccbdba3fc63845d8880da14a848639c3464 | |
parent | d5083b9fe96de0cc69687ee7b1fe7597edd37d77 (diff) |
Remove duplicate code around Term_{load,save} calls
-rw-r--r-- | src/cave.cc | 10 | ||||
-rw-r--r-- | src/cmd3.cc | 30 | ||||
-rw-r--r-- | src/cmd4.cc | 98 | ||||
-rw-r--r-- | src/cmd5.cc | 23 | ||||
-rw-r--r-- | src/cmd7.cc | 39 | ||||
-rw-r--r-- | src/files.cc | 6 | ||||
-rw-r--r-- | src/gods.cc | 6 | ||||
-rw-r--r-- | src/monster3.cc | 9 | ||||
-rw-r--r-- | src/object1.cc | 3 | ||||
-rw-r--r-- | src/powers.cc | 12 | ||||
-rw-r--r-- | src/skills.cc | 19 | ||||
-rw-r--r-- | src/spells2.cc | 21 | ||||
-rw-r--r-- | src/util.cc | 33 | ||||
-rw-r--r-- | src/util.hpp | 2 | ||||
-rw-r--r-- | src/xtra2.cc | 6 |
15 files changed, 97 insertions, 220 deletions
diff --git a/src/cave.cc b/src/cave.cc index 4c490332..6b6b52f7 100644 --- a/src/cave.cc +++ b/src/cave.cc @@ -1868,11 +1868,8 @@ void do_cmd_view_map() /* Retrive current screen size */ Term_get_size(&wid, &hgt); - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); /* Note */ prt("Please wait...", 0, 0); @@ -1896,10 +1893,7 @@ void do_cmd_view_map() inkey(); /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } diff --git a/src/cmd3.cc b/src/cmd3.cc index 9b7366d9..c694e61f 100644 --- a/src/cmd3.cc +++ b/src/cmd3.cc @@ -60,8 +60,7 @@ void do_cmd_inven() command_wrk = FALSE; /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Show the inventory */ show_inven_full(); @@ -83,9 +82,7 @@ void do_cmd_inven() command_new = inkey(); /* Restore the screen */ - Term_load(); - character_icky = FALSE; - + screen_load_no_flush(); /* Process "Escape" */ if (command_new == ESCAPE) @@ -115,8 +112,7 @@ void do_cmd_equip() command_wrk = TRUE; /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Display the equipment */ show_equip_full(); @@ -139,9 +135,7 @@ void do_cmd_equip() command_new = inkey(); /* Restore the screen */ - Term_load(); - character_icky = FALSE; - + screen_load_no_flush(); /* Process "Escape" */ if (command_new == ESCAPE) @@ -1495,8 +1489,7 @@ void do_cmd_query_symbol() if (recall) { /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Recall on screen */ screen_roff(who[i], 0); @@ -1512,8 +1505,7 @@ void do_cmd_query_symbol() if (recall) { /* Restore */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } /* Normal commands */ @@ -1769,20 +1761,14 @@ void do_cmd_cli_help() } } - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); /* Display the file contents */ show_string(w.c_str(), "Command line help"); /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } diff --git a/src/cmd4.cc b/src/cmd4.cc index 9f1f6f48..b571e36e 100644 --- a/src/cmd4.cc +++ b/src/cmd4.cc @@ -143,11 +143,8 @@ void do_cmd_change_name() char tmp[160]; - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); /* Forever */ while (true) @@ -240,11 +237,7 @@ void do_cmd_change_name() } /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; - + screen_load_no_flush(); /* Redraw everything */ p_ptr->redraw |= (PR_WIPE | PR_FRAME | PR_MAP); @@ -303,11 +296,8 @@ void do_cmd_messages() /* Start at leftmost edge */ u32b q = 0; - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); /* Process requests until done */ while (true) @@ -486,10 +476,7 @@ void do_cmd_messages() } /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } // File-local @@ -1657,13 +1644,8 @@ void do_cmd_macros() /* Keymap mode */ int mode = get_keymap_mode(); - - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save screen */ - Term_save(); - + screen_save_no_flush(); /* Process requests until done */ while (true) @@ -2011,10 +1993,7 @@ void do_cmd_macros() } /* Load screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } @@ -2029,12 +2008,8 @@ void do_cmd_visuals() char buf[1024]; - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); - + screen_save_no_flush(); /* Interact until done */ while (true) @@ -2443,10 +2418,7 @@ void do_cmd_visuals() /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } @@ -2461,13 +2433,8 @@ void do_cmd_colors() char buf[1024]; - - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); - + screen_save_no_flush(); /* Interact until done */ while (true) @@ -2662,10 +2629,7 @@ void do_cmd_colors() /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } @@ -2825,11 +2789,8 @@ void do_cmd_load_screen() /* Retrieve the current screen size */ Term_get_size(&wid, &hgt); - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); /* Clear the screen */ Term_clear(); @@ -2908,10 +2869,7 @@ void do_cmd_load_screen() /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } @@ -2945,12 +2903,8 @@ void do_cmd_save_screen() /* Retrieve the current screen size */ Term_get_size(&wid, &hgt); - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); - + screen_save_no_flush(); /* Dump the screen */ for (y = 0; y < hgt; y++) @@ -3010,10 +2964,7 @@ void do_cmd_save_screen() /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } @@ -3735,12 +3686,8 @@ void do_cmd_knowledge() { int i; - - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); /* Interact until done */ while (true) @@ -3868,10 +3815,7 @@ void do_cmd_knowledge() } /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } @@ -3881,20 +3825,14 @@ void do_cmd_knowledge() */ void do_cmd_checkquest() { - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); /* Quest info */ do_cmd_knowledge_quests(); /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } diff --git a/src/cmd5.cc b/src/cmd5.cc index 71322b65..1ac508a0 100644 --- a/src/cmd5.cc +++ b/src/cmd5.cc @@ -170,8 +170,7 @@ static void browse_school_spell(int book, int spell_idx, object_type *o_ptr) I2A(0), I2A(num - 1)); /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Display a list of spells */ print_book(book, spell_idx, o_ptr); @@ -208,8 +207,7 @@ static void browse_school_spell(int book, int spell_idx, object_type *o_ptr) /* Restore the screen */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); /* Show choices */ window_stuff(); @@ -667,8 +665,7 @@ static std::tuple<int, int> choose_monster_power(monster_race const *r_ptr, bool label, (symbiosis ? "symbiote" : "body")); /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Get a spell from the user */ monster_power const *power = nullptr; @@ -799,8 +796,7 @@ static std::tuple<int, int> choose_monster_power(monster_race const *r_ptr, bool } /* Restore the screen */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); /* Abort if needed */ if (!flag || (power == nullptr)) @@ -1976,8 +1972,7 @@ s32b get_school_spell(const char *do_what, s16b force_book) } /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Go */ if (hack_force_spell == -1) @@ -1996,8 +1991,8 @@ s32b get_school_spell(const char *do_what, s16b force_book) /* Restore and save screen; this prevents subprompt from leaving garbage when going around the loop multiple times. */ - Term_load(); - Term_save(); + screen_load_no_flush(); + screen_save_no_flush(); /* Display a list of spells */ where = print_book(sval, pval, o_ptr); @@ -2069,9 +2064,7 @@ s32b get_school_spell(const char *do_what, s16b force_book) /* Restore the screen */ - Term_load(); - character_icky = FALSE; - + screen_load_no_flush(); /* Show choices */ window_stuff(); diff --git a/src/cmd7.cc b/src/cmd7.cc index 7183c82c..0539f6b4 100644 --- a/src/cmd7.cc +++ b/src/cmd7.cc @@ -275,8 +275,7 @@ static bool get_magic_power(int *sn, magic_power *powers, int max_powers, p, I2A(0), I2A(num - 1), toupper(I2A(0)), toupper(I2A(num - 1)), p); /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Show the list */ display_magic_powers(powers, max_powers, power_info, plev, cast_stat, y, x); @@ -307,11 +306,10 @@ static bool get_magic_power(int *sn, magic_power *powers, int max_powers, if (info) { c_prt(TERM_L_BLUE, spell.desc, 1, 0); + inkey(); /* Restore the screen */ - inkey(); - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); /* Redisplay choices */ display_magic_powers(powers, max_powers, power_info, plev, cast_stat, y, x); @@ -323,8 +321,7 @@ static bool get_magic_power(int *sn, magic_power *powers, int max_powers, } /* Restore the screen */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); /* Abort if needed */ if (!flag) @@ -1296,11 +1293,8 @@ static random_spell* select_spell_from_batch(std::size_t batch) char which; random_spell* ret = nullptr; - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); int const mut_max = (random_spells.size() < (batch + 1) * 10) ? random_spells.size() - batch * 10 @@ -1361,10 +1355,7 @@ static random_spell* select_spell_from_batch(std::size_t batch) } /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); /* Return selection */ return (ret); @@ -1401,11 +1392,8 @@ static random_spell* select_spell() /* How many spells in the last batch? */ int batch_max = (random_spells.size() - 1) / 10; - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); strnfmt(tmp, 160, "(a-%c) Select batch of powers: ", I2A(batch_max)); @@ -1417,10 +1405,7 @@ static random_spell* select_spell() if (which == ESCAPE) { - Term_load(); - ret = NULL; - break; } @@ -1428,10 +1413,7 @@ static random_spell* select_spell() { if (batch_max == 0) { - Term_load(); - ret = select_spell_from_batch(0); - break; } @@ -1441,10 +1423,7 @@ static random_spell* select_spell() which = tolower(which); if (isalpha(which) && (A2I(which) <= batch_max)) { - Term_load(); - ret = select_spell_from_batch(A2I(which)); - break; } else @@ -1453,8 +1432,8 @@ static random_spell* select_spell() } } - /* Leave "icky" mode */ - character_icky = FALSE; + /* Restore screen */ + screen_load_no_flush(); return (ret); } diff --git a/src/files.cc b/src/files.cc index 7a16ea99..a6b28106 100644 --- a/src/files.cc +++ b/src/files.cc @@ -4125,15 +4125,13 @@ static void show_info() if (!out_val[0]) break; /* Save screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Dump a character file */ file_character(out_val); /* Load screen */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } diff --git a/src/gods.cc b/src/gods.cc index a2ee3dd4..0efcee19 100644 --- a/src/gods.cc +++ b/src/gods.cc @@ -134,8 +134,7 @@ bool_ show_god_info() msg_print(NULL); - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); text_out(format("You worship %s. ", d_ptr->name)); for (i = 0; (i < 10) && (!equals(d_ptr->desc[i], "")); i++) @@ -144,8 +143,7 @@ bool_ show_god_info() inkey(); - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } return TRUE; diff --git a/src/monster3.cc b/src/monster3.cc index 9cbd04ec..8bb2ed98 100644 --- a/src/monster3.cc +++ b/src/monster3.cc @@ -519,8 +519,7 @@ bool do_control_magic() redraw = TRUE; /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); prt ("", y++, x); @@ -562,8 +561,7 @@ bool do_control_magic() redraw = FALSE; /* Restore the screen */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } /* Redo asking */ @@ -623,8 +621,7 @@ bool do_control_magic() /* Restore the screen */ if (redraw) { - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } /* Take a turn */ diff --git a/src/object1.cc b/src/object1.cc index 0963611c..b976369d 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2124,8 +2124,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait else { /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Set up stuff for text_out */ text_out_hook = text_out_to_screen; diff --git a/src/powers.cc b/src/powers.cc index de417d11..1e33a487 100644 --- a/src/powers.cc +++ b/src/powers.cc @@ -1137,8 +1137,7 @@ static boost::optional<int> select_power() int start = 0; int const max = power_idxs.size(); // Save - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); // Loop until we get a result. boost::optional<int> result; while (true) @@ -1154,15 +1153,13 @@ static boost::optional<int> select_power() { start += 20; if (start >= max) start -= 20; - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else if (which == '-') { start -= 20; if (start < 0) start += 20; - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else { @@ -1183,8 +1180,7 @@ static boost::optional<int> select_power() } } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); return result; } diff --git a/src/skills.cc b/src/skills.cc index 4181dbcd..21ec162c 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -779,8 +779,8 @@ static void choose_melee() int i, j, z = 0; int force_drop = FALSE, style_unchanged = FALSE; - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); + Term_clear(); j = get_melee_skills(); @@ -843,8 +843,7 @@ static void choose_melee() /* Redraw monster hitpoint */ p_ptr->redraw |= (PR_FRAME); - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); if (style_unchanged) { @@ -964,8 +963,7 @@ static int do_cmd_activate_skill_aux() return -1; } - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); while (true) { @@ -984,8 +982,7 @@ static int do_cmd_activate_skill_aux() { start -= 20; } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else if (which == '-') { @@ -994,8 +991,7 @@ static int do_cmd_activate_skill_aux() { start += 20; } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else if (which == '@') { @@ -1039,8 +1035,7 @@ static int do_cmd_activate_skill_aux() break; } } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); return ret; } diff --git a/src/spells2.cc b/src/spells2.cc index de320c40..18f11758 100644 --- a/src/spells2.cc +++ b/src/spells2.cc @@ -891,8 +891,7 @@ void report_magics() } /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Erase the screen */ for (k = 1; k < 24; k++) prt("", k, 13); @@ -922,8 +921,7 @@ void report_magics() inkey(); /* Restore the screen */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } @@ -4801,8 +4799,7 @@ static int reset_recall_aux() } } - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); while (true) { @@ -4818,8 +4815,7 @@ static int reset_recall_aux() else if (which == '*' || which == '?' || which == ' ') { mode = (mode) ? FALSE : TRUE; - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else if (which == '+') @@ -4830,8 +4826,7 @@ static int reset_recall_aux() { start -= 20; } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else if (which == '-') @@ -4841,8 +4836,7 @@ static int reset_recall_aux() { start += 20; } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else if (which == '@') @@ -4900,8 +4894,7 @@ static int reset_recall_aux() } } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); return ret; } diff --git a/src/util.cc b/src/util.cc index 0012ee11..13acf7f8 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1933,6 +1933,14 @@ void screen_save() character_icky++; } +void screen_save_no_flush() +{ + /* Enter "icky" mode */ + character_icky = TRUE; + + /* Save the screen */ + Term_save(); +} /* * Load the screen, and decrease the "icky" depth. @@ -1951,6 +1959,15 @@ void screen_load() character_icky--; } +void screen_load_no_flush() +{ + /* Restore the screen */ + Term_load(); + + /* Leave "icky" mode */ + character_icky = FALSE; +} + /* * Display a formatted message, using "vstrnfmt()" and "msg_print()". @@ -3487,17 +3504,15 @@ int ask_menu(const char *ask, const std::vector<std::string> &items) char c; int size = static_cast<int>(items.size()); // Convert to int to avoid warnings - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); while (TRUE) { /* Display list */ - Term_load(); - Term_save(); + screen_load_no_flush(); + screen_save_no_flush(); + prt(ask, 0, 0); for (i = start; (i < size) && (i < start + 20); i++) { @@ -3546,11 +3561,7 @@ int ask_menu(const char *ask, const std::vector<std::string> &items) } } - /* Load the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); return ret; } diff --git a/src/util.hpp b/src/util.hpp index 630c2bbd..0ec4beb1 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -41,7 +41,9 @@ void msg_print(std::string const &msg); void cmsg_format(byte color, const char *fmt, ...); void msg_format(const char *fmt, ...); void screen_save(); +void screen_save_no_flush(); void screen_load(); +void screen_load_no_flush(); void c_put_str(byte attr, const char *str, int row, int col); void c_put_str(byte attr, std::string const &str, int row, int col); void put_str(const char *str, int row, int col); diff --git a/src/xtra2.cc b/src/xtra2.cc index d3218abd..9d3968f6 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -4025,8 +4025,7 @@ static int target_set_aux(int y, int x, int mode, const char *info_) if (recall) { /* Save */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Recall on screen */ screen_roff(m_ptr->r_idx, m_ptr->ego); @@ -4038,8 +4037,7 @@ static int target_set_aux(int y, int x, int mode, const char *info_) query = inkey(); /* Restore */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } /* Normal */ |