From 0bf96ac6fb2034fac628a08a07810ad0064d00b5 Mon Sep 17 00:00:00 2001 From: Hourier Date: Sun, 5 Jul 2020 11:41:34 +0900 Subject: [PATCH] [Refactor] #40467 Separated option-loader.c/h from load.c --- Hengband/Hengband/Hengband.vcxproj | 2 + Hengband/Hengband/Hengband.vcxproj.filters | 6 ++ src/Makefile.am | 1 + src/savedata/load.c | 102 +------------------------- src/savedata/option-loader.c | 111 +++++++++++++++++++++++++++++ src/savedata/option-loader.h | 3 + 6 files changed, 124 insertions(+), 101 deletions(-) create mode 100644 src/savedata/option-loader.c create mode 100644 src/savedata/option-loader.h diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index 448706fbf..6c275237f 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -243,6 +243,7 @@ + @@ -710,6 +711,7 @@ + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index a6bb08c2c..c88a658ff 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -1625,6 +1625,9 @@ savedata + + savedata + @@ -3553,6 +3556,9 @@ savedata + + savedata + diff --git a/src/Makefile.am b/src/Makefile.am index 8e9c42b2d..18a087bee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -528,6 +528,7 @@ hengband_SOURCES = \ savedata/load-zangband.c savedata/load-zangband.h \ savedata/load.c savedata/load.h \ savedata/lore-loader.c savedata/lore-loader.h \ + savedata/option-loader.c savedata/option-loader.h \ savedata/savedata-flag-types.h \ savedata/save.c savedata/save.h \ savedata/store-loader.c savedata/store-loader.h \ diff --git a/src/savedata/load.c b/src/savedata/load.c index a5dee36b4..7ae9c6877 100644 --- a/src/savedata/load.c +++ b/src/savedata/load.c @@ -81,6 +81,7 @@ #include "savedata/lore-loader.h" #include "savedata/monster-loader.h" #include "savedata/old-feature-types.h" +#include "savedata/option-loader.h" #include "savedata/save.h" #include "savedata/savedata-flag-types.h" #include "savedata/store-loader.h" @@ -108,107 +109,6 @@ static const int QUEST_OLD_CASTLE = 27; // 古い城. static const int QUEST_ROYAL_CRYPT = 28; // 王家の墓. /*! - * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options) - * @return なし - * @details - * Note that the normal options are now stored as a set of 256 bit flags, - * plus a set of 256 bit masks to indicate which bit flags were defined - * at the time the savefile was created. This will allow new options - * to be added, and old options to be removed, at any time, without - * hurting old savefiles. - * - * The window options are stored in the same way, but note that each - * window gets 32 options, and their order is fixed by certain defines. - */ -static void rd_options(void) -{ - strip_bytes(16); - - byte b; - rd_byte(&b); - delay_factor = b; - - rd_byte(&b); - hitpoint_warn = b; - - if (h_older_than(1, 7, 0, 0)) { - mana_warn = 2; - } else { - rd_byte(&b); - mana_warn = b; - } - - u16b c; - rd_u16b(&c); - - if (c & 0x0002) - current_world_ptr->wizard = TRUE; - - cheat_peek = (c & 0x0100) ? TRUE : FALSE; - cheat_hear = (c & 0x0200) ? TRUE : FALSE; - cheat_room = (c & 0x0400) ? TRUE : FALSE; - cheat_xtra = (c & 0x0800) ? TRUE : FALSE; - cheat_know = (c & 0x1000) ? TRUE : FALSE; - cheat_live = (c & 0x2000) ? TRUE : FALSE; - cheat_save = (c & 0x4000) ? TRUE : FALSE; - cheat_diary_output = (c & 0x8000) ? TRUE : FALSE; - cheat_turn = (c & 0x0080) ? TRUE : FALSE; - cheat_sight = (c & 0x0040) ? TRUE : FALSE; - - rd_byte((byte *)&autosave_l); - rd_byte((byte *)&autosave_t); - rd_s16b(&autosave_freq); - - BIT_FLAGS flag[8]; - for (int n = 0; n < 8; n++) - rd_u32b(&flag[n]); - - BIT_FLAGS mask[8]; - for (int n = 0; n < 8; n++) - rd_u32b(&mask[n]); - - for (int n = 0; n < 8; n++) { - for (int i = 0; i < 32; i++) { - if (!(mask[n] & (1L << i))) - continue; - if (!(option_mask[n] & (1L << i))) - continue; - - if (flag[n] & (1L << i)) { - option_flag[n] |= (1L << i); - } else { - option_flag[n] &= ~(1L << i); - } - } - } - - if (z_older_than(10, 4, 5)) - load_zangband_options(); - - extract_option_vars(); - for (int n = 0; n < 8; n++) - rd_u32b(&flag[n]); - - for (int n = 0; n < 8; n++) - rd_u32b(&mask[n]); - - for (int n = 0; n < 8; n++) { - for (int i = 0; i < 32; i++) { - if (!(mask[n] & (1L << i))) - continue; - if (!(window_mask[n] & (1L << i))) - continue; - - if (flag[n] & (1L << i)) { - window_flag[n] |= (1L << i); - } else { - window_flag[n] &= ~(1L << i); - } - } - } -} - -/*! * @brief ダミー情報スキップ / Hack -- strip the "ghost" info * @return なし * @details diff --git a/src/savedata/option-loader.c b/src/savedata/option-loader.c new file mode 100644 index 000000000..dbb96d5a2 --- /dev/null +++ b/src/savedata/option-loader.c @@ -0,0 +1,111 @@ +#include "savedata/option-loader.h" +#include "cmd-io/cmd-gameoption.h" +#include "game-option/cheat-options.h" +#include "game-option/option-flags.h" +#include "game-option/special-options.h" +#include "savedata/angband-version-comparer.h" +#include "savedata/load-util.h" +#include "savedata/load-zangband.h" +#include "system/angband.h" +#include "world/world.h" + +/*! + * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options) + * @return なし + * @details + * Note that the normal options are now stored as a set of 256 bit flags, + * plus a set of 256 bit masks to indicate which bit flags were defined + * at the time the savefile was created. This will allow new options + * to be added, and old options to be removed, at any time, without + * hurting old savefiles. + * + * The window options are stored in the same way, but note that each + * window gets 32 options, and their order is fixed by certain defines. + */ +void rd_options(void) +{ + strip_bytes(16); + + byte b; + rd_byte(&b); + delay_factor = b; + + rd_byte(&b); + hitpoint_warn = b; + + if (h_older_than(1, 7, 0, 0)) { + mana_warn = 2; + } else { + rd_byte(&b); + mana_warn = b; + } + + u16b c; + rd_u16b(&c); + + if (c & 0x0002) + current_world_ptr->wizard = TRUE; + + cheat_peek = (c & 0x0100) ? TRUE : FALSE; + cheat_hear = (c & 0x0200) ? TRUE : FALSE; + cheat_room = (c & 0x0400) ? TRUE : FALSE; + cheat_xtra = (c & 0x0800) ? TRUE : FALSE; + cheat_know = (c & 0x1000) ? TRUE : FALSE; + cheat_live = (c & 0x2000) ? TRUE : FALSE; + cheat_save = (c & 0x4000) ? TRUE : FALSE; + cheat_diary_output = (c & 0x8000) ? TRUE : FALSE; + cheat_turn = (c & 0x0080) ? TRUE : FALSE; + cheat_sight = (c & 0x0040) ? TRUE : FALSE; + + rd_byte((byte *)&autosave_l); + rd_byte((byte *)&autosave_t); + rd_s16b(&autosave_freq); + + BIT_FLAGS flag[8]; + for (int n = 0; n < 8; n++) + rd_u32b(&flag[n]); + + BIT_FLAGS mask[8]; + for (int n = 0; n < 8; n++) + rd_u32b(&mask[n]); + + for (int n = 0; n < 8; n++) { + for (int i = 0; i < 32; i++) { + if (!(mask[n] & (1L << i))) + continue; + if (!(option_mask[n] & (1L << i))) + continue; + + if (flag[n] & (1L << i)) { + option_flag[n] |= (1L << i); + } else { + option_flag[n] &= ~(1L << i); + } + } + } + + if (z_older_than(10, 4, 5)) + load_zangband_options(); + + extract_option_vars(); + for (int n = 0; n < 8; n++) + rd_u32b(&flag[n]); + + for (int n = 0; n < 8; n++) + rd_u32b(&mask[n]); + + for (int n = 0; n < 8; n++) { + for (int i = 0; i < 32; i++) { + if (!(mask[n] & (1L << i))) + continue; + if (!(window_mask[n] & (1L << i))) + continue; + + if (flag[n] & (1L << i)) { + window_flag[n] |= (1L << i); + } else { + window_flag[n] &= ~(1L << i); + } + } + } +} diff --git a/src/savedata/option-loader.h b/src/savedata/option-loader.h new file mode 100644 index 000000000..6a446800a --- /dev/null +++ b/src/savedata/option-loader.h @@ -0,0 +1,3 @@ +#pragma once + +void rd_options(void); -- 2.11.0