From 1243a123ccb408782aa96d49e56b3640ced8a557 Mon Sep 17 00:00:00 2001 From: Hourier Date: Sun, 14 Jun 2020 13:05:52 +0900 Subject: [PATCH] [Refactor] #40413 Separated quarks.c/h from util.c/h --- Hengband/Hengband/Hengband.vcxproj | 2 + Hengband/Hengband/Hengband.vcxproj.filters | 6 +++ src/Makefile.am | 1 + src/autopick/autopick-entry.c | 1 + src/autopick/autopick-util.c | 1 + src/cmd-action/cmd-pet.c | 1 + src/cmd-item/cmd-activate.c | 1 + src/cmd-item/cmd-item.c | 1 + src/inventory/inventory-curse.c | 1 + src/inventory/player-inventory.c | 1 + src/inventory/recharge-processor.c | 1 + src/io/interpret-pref-file.c | 1 + src/io/load.c | 31 +------------- src/io/save.c | 1 + src/main/init.c | 1 + src/monster/monster-describer.c | 1 + src/object-enchant/artifact.c | 2 +- src/object/object-flavor.c | 2 +- src/player/player-status.c | 1 + src/store/store.c | 1 + src/term/gameterm.c | 2 +- src/util/quarks.c | 58 ++++++++++++++++++++++++++ src/util/quarks.h | 18 +++++++++ src/util/util.c | 65 ++---------------------------- src/util/util.h | 13 ------ src/wizard/wizard-spoiler.c | 1 + 26 files changed, 108 insertions(+), 107 deletions(-) create mode 100644 src/util/quarks.c create mode 100644 src/util/quarks.h diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index 807dd1d55..1970ba971 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -202,6 +202,7 @@ + @@ -577,6 +578,7 @@ + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index 9dc093a84..8c0e9d2f0 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -1370,6 +1370,9 @@ io + + util + @@ -3001,6 +3004,9 @@ io + + util + diff --git a/src/Makefile.am b/src/Makefile.am index 699d23993..eadc70ccf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -547,6 +547,7 @@ hengband_SOURCES = \ \ util/angband-files.c util/angband-files.h \ util/object-sort.c util/object-sort.h \ + util/quarks.c util/quarks.h \ util/string-processor.c util/string-processor.h \ util/util.c util/util.h \ \ diff --git a/src/autopick/autopick-entry.c b/src/autopick/autopick-entry.c index 79160f85a..cdf25c049 100644 --- a/src/autopick/autopick-entry.c +++ b/src/autopick/autopick-entry.c @@ -14,6 +14,7 @@ #include "object/object-kind.h" #include "object/object-info.h" #include "perception/object-perception.h" +#include "util/quarks.h" #ifdef JP static char kanji_colon[] = ":"; diff --git a/src/autopick/autopick-util.c b/src/autopick/autopick-util.c index 505b9620c..e2e9e8b7a 100644 --- a/src/autopick/autopick-util.c +++ b/src/autopick/autopick-util.c @@ -4,6 +4,7 @@ #include "main/sound-of-music.h" #include "monster-race/race-indice-types.h" #include "object-enchant/item-feeling.h" +#include "util/quarks.h" /* * 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries diff --git a/src/cmd-action/cmd-pet.c b/src/cmd-action/cmd-pet.c index 8a13638b1..e2b4758b2 100644 --- a/src/cmd-action/cmd-pet.c +++ b/src/cmd-action/cmd-pet.c @@ -32,6 +32,7 @@ #include "player/player-skill.h" #include "player/player-status.h" #include "view/display-main-window.h" +#include "util/quarks.h" #include "world/world.h" int total_friends = 0; diff --git a/src/cmd-item/cmd-activate.c b/src/cmd-item/cmd-activate.c index c317aa1f9..a741802a5 100644 --- a/src/cmd-item/cmd-activate.c +++ b/src/cmd-item/cmd-activate.c @@ -67,6 +67,7 @@ #include "spell/spells3.h" #include "sv-definition/sv-lite-types.h" #include "sv-definition/sv-ring-types.h" +#include "util/quarks.h" #include "world/world.h" /*! diff --git a/src/cmd-item/cmd-item.c b/src/cmd-item/cmd-item.c index d26fbd5d5..fb3fadca4 100644 --- a/src/cmd-item/cmd-item.c +++ b/src/cmd-item/cmd-item.c @@ -58,6 +58,7 @@ #include "realm/realm-hex-numbers.h" #include "spell/spells3.h" #include "sv-definition/sv-lite-types.h" +#include "util/quarks.h" #include "view/display-main-window.h" /*! diff --git a/src/inventory/inventory-curse.c b/src/inventory/inventory-curse.c index aa5b2081c..59e450cb6 100644 --- a/src/inventory/inventory-curse.c +++ b/src/inventory/inventory-curse.c @@ -18,6 +18,7 @@ #include "spell-kind/spells-random.h" #include "spell-kind/spells-teleport.h" #include "spell/spells-summon.h" +#include "util/quarks.h" #define TRC_P_FLAG_MASK \ (TRC_TELEPORT_SELF | TRC_CHAINSWORD | TRC_TY_CURSE | TRC_DRAIN_EXP | TRC_ADD_L_CURSE | TRC_ADD_H_CURSE | TRC_CALL_ANIMAL | TRC_CALL_DEMON \ diff --git a/src/inventory/player-inventory.c b/src/inventory/player-inventory.c index f2b08acd3..09ad61130 100644 --- a/src/inventory/player-inventory.c +++ b/src/inventory/player-inventory.c @@ -20,6 +20,7 @@ #include "player/player-move.h" #include "term/gameterm.h" #include "term/term-color-types.h" +#include "util/quarks.h" #include "view/display-main-window.h" bool select_ring_slot; diff --git a/src/inventory/recharge-processor.c b/src/inventory/recharge-processor.c index 3e478a30c..28d347c16 100644 --- a/src/inventory/recharge-processor.c +++ b/src/inventory/recharge-processor.c @@ -4,6 +4,7 @@ #include "object/object-hook.h" #include "object/object-kind.h" #include "player/player-move.h" +#include "util/quarks.h" /*! * @brief diff --git a/src/io/interpret-pref-file.c b/src/io/interpret-pref-file.c index b1d33d74f..62c8c7205 100644 --- a/src/io/interpret-pref-file.c +++ b/src/io/interpret-pref-file.c @@ -14,6 +14,7 @@ #include "object/object-kind.h" #include "system/game-option-types.h" #include "term/gameterm.h" +#include "util/quarks.h" #include "util/string-processor.h" #include "view/display-main-window.h" // 暫定。apply_default_feat_lighting()。後で消す. #include "world/world.h" diff --git a/src/io/load.c b/src/io/load.c index 867047d51..1380dd4dd 100644 --- a/src/io/load.c +++ b/src/io/load.c @@ -8,36 +8,6 @@ * This software may be copied and distributed for educational, research, * and not for profit purposes provided that this copyright and statement * are included in all such copies. Other copyrights may also apply. - * @details - * This file loads savefiles from Angband 2.7.X and 2.8.X - * - * Ancient savefiles (pre-2.7.0) are loaded by another file. - * - * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete, - * and savefiles from those versions may not be successfully converted. - * - * We attempt to prevent corrupt savefiles from inducing memory errors. - * - * Note that this file should not use the random number generator, the - * object flavors, the visual attr/char mappings, or anything else which - * is initialized *after* or *during* the "load character" function. - * - * This file assumes that the monster/object records are initialized - * to zero, and the race/kind tables have been loaded correctly. The - * order of object stacks is currently not saved in the savefiles, but - * the "next" pointers are saved, so all necessary knowledge is present. - * - * We should implement simple "savefile extenders" using some form of - * "sized" chunks of bytes, with a {size,type,data} format, so everyone - * can know the size, interested people can know the type, and the actual - * data is available to the parsing routines that acknowledge the type. - * - * Consider changing the "globe of invulnerability" code so that it - * takes some form of "maximum damage to protect from" in addition to - * the existing "number of turns to protect for", and where each hit - * by a monster will reduce the shield by that amount. - * - * */ #include "io/load.h" @@ -110,6 +80,7 @@ #include "system/system-variables.h" // 暫定、init_flags の扱いを決めた上で消す. #include "util/angband-files.h" #include "util/object-sort.h" +#include "util/quarks.h" #include "world/world-object.h" #include "world/world.h" diff --git a/src/io/save.c b/src/io/save.c index 964cab609..612fe83c8 100644 --- a/src/io/save.c +++ b/src/io/save.c @@ -42,6 +42,7 @@ #include "store/store.h" #include "system/angband-version.h" #include "util/angband-files.h" +#include "util/quarks.h" #include "view/display-main-window.h" #include "world/world.h" diff --git a/src/main/init.c b/src/main/init.c index 1327bdd96..23bb561e7 100644 --- a/src/main/init.c +++ b/src/main/init.c @@ -73,6 +73,7 @@ #include "term/gameterm.h" #include "term/term-color-types.h" #include "util/angband-files.h" +#include "util/quarks.h" #include "world/world.h" #include diff --git a/src/monster/monster-describer.c b/src/monster/monster-describer.c index 94a88fea3..2e56de776 100644 --- a/src/monster/monster-describer.c +++ b/src/monster/monster-describer.c @@ -5,6 +5,7 @@ #include "monster/monster-description-types.h" #include "monster/monster-flag-types.h" #include "monster/monster-info.h" +#include "util/quarks.h" /*! * @brief モンスターの呼称を作成する / Build a string describing a monster in some way. diff --git a/src/object-enchant/artifact.c b/src/object-enchant/artifact.c index 62f1a7685..63ac7a3fe 100644 --- a/src/object-enchant/artifact.c +++ b/src/object-enchant/artifact.c @@ -45,7 +45,7 @@ #include "player/player-class.h" #include "player/player-personalities-types.h" #include "spell/spells-object.h" -#include "util/util.h" +#include "util/quarks.h" #include "view/display-main-window.h" #include "world/world.h" diff --git a/src/object/object-flavor.c b/src/object/object-flavor.c index 0edb63ecd..f8888fa38 100644 --- a/src/object/object-flavor.c +++ b/src/object/object-flavor.c @@ -33,7 +33,7 @@ #include "shoot.h" #include "sv-definition/sv-food-types.h" #include "sv-definition/sv-lite-types.h" -#include "util/util.h" +#include "util/quarks.h" #include "world/world.h" /*! diff --git a/src/player/player-status.c b/src/player/player-status.c index 86e050034..932e04632 100644 --- a/src/player/player-status.c +++ b/src/player/player-status.c @@ -71,6 +71,7 @@ #include "spell/technic-info-table.h" #include "sv-definition/sv-lite-types.h" #include "sv-definition/sv-weapon-types.h" +#include "util/quarks.h" #include "view/display-main-window.h" #include "world/world.h" diff --git a/src/store/store.c b/src/store/store.c index 55fb2c8c4..0a248baee 100644 --- a/src/store/store.c +++ b/src/store/store.c @@ -77,6 +77,7 @@ #include "system/angband.h" #include "term/gameterm.h" #include "util/object-sort.h" +#include "util/quarks.h" #include "view/display-main-window.h" #include "view/object-describer.h" #include "world/world.h" diff --git a/src/term/gameterm.c b/src/term/gameterm.c index 2ef274638..1d34ce63e 100644 --- a/src/term/gameterm.c +++ b/src/term/gameterm.c @@ -1,7 +1,7 @@ #include "term/gameterm.h" #include "system/system-variables.h" #include "term/term-color-types.h" -#include "util/util.h" +#include "util/quarks.h" /* * Convert an "attr"/"char" pair into a "pict" (P) diff --git a/src/util/quarks.c b/src/util/quarks.c new file mode 100644 index 000000000..e2634aae7 --- /dev/null +++ b/src/util/quarks.c @@ -0,0 +1,58 @@ +#include "util/quarks.h" + +/* + * The number of quarks + */ +STR_OFFSET quark__num; + +/* + * The pointers to the quarks [QUARK_MAX] + */ +concptr *quark__str; + +/* + * Initialize the quark array + */ +void quark_init(void) +{ + C_MAKE(quark__str, QUARK_MAX, concptr); + quark__str[1] = string_make(""); + quark__num = 2; +} + +/* + * Add a new "quark" to the set of quarks. + */ +u16b quark_add(concptr str) +{ + u16b i; + for (i = 1; i < quark__num; i++) { + if (streq(quark__str[i], str)) + return (i); + } + + if (quark__num == QUARK_MAX) + return 1; + + quark__num = i + 1; + quark__str[i] = string_make(str); + return (i); +} + +/* + * This function looks up a quark + */ +concptr quark_str(STR_OFFSET i) +{ + concptr q; + + /* Return NULL for an invalid index */ + if ((i < 1) || (i >= quark__num)) + return NULL; + + /* Access the quark */ + q = quark__str[i]; + + /* Return the quark */ + return (q); +} diff --git a/src/util/quarks.h b/src/util/quarks.h new file mode 100644 index 000000000..d91a1db28 --- /dev/null +++ b/src/util/quarks.h @@ -0,0 +1,18 @@ +#pragma once + +#include "system/angband.h" + +/*! + * @brief 銘情報の最大数 / Maximum number of "quarks" (see "io.c") + * @note + * Default: assume at most 512 different inscriptions are used
+ * Was 512... 256 quarks added for random artifacts
+ */ +#define QUARK_MAX 768 + +extern STR_OFFSET quark__num; +extern concptr *quark__str; + +concptr quark_str(STR_OFFSET num); +void quark_init(void); +u16b quark_add(concptr str); diff --git a/src/util/util.c b/src/util/util.c index 712ebafc7..09d007b79 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -38,6 +38,7 @@ #include "system/system-variables.h" #include "term/gameterm.h" #include "term/term-color-types.h" +#include "util/quarks.h" #include "util/string-processor.h" #include "view/display-main-window.h" #include "world/world.h" @@ -106,16 +107,6 @@ bool use_menu; pos_list tmp_pos; -/* - * The number of quarks - */ -STR_OFFSET quark__num; - -/* - * The pointers to the quarks [QUARK_MAX] - */ -concptr *quark__str; - int max_macrotrigger = 0; /*!< 現在登録中のマクロ(トリガー)の数 */ concptr macro_template = NULL; /*!< Angband設定ファイルのT: タグ情報から読み込んだ長いTコードを処理するために利用する文字列ポインタ */ concptr macro_modifier_chr; /*!< &x# で指定されるマクロトリガーに関する情報を記録する文字列ポインタ */ @@ -153,58 +144,10 @@ void flush(void) } -/* - * Initialize the quark array - */ -void quark_init(void) -{ - C_MAKE(quark__str, QUARK_MAX, concptr); - quark__str[1] = string_make(""); - quark__num = 2; -} - - -/* - * Add a new "quark" to the set of quarks. - */ -u16b quark_add(concptr str) -{ - u16b i; - for (i = 1; i < quark__num; i++) - { - if (streq(quark__str[i], str)) return (i); - } - - if (quark__num == QUARK_MAX) return 1; - - quark__num = i + 1; - quark__str[i] = string_make(str); - return (i); -} - - -/* - * This function looks up a quark +/*! + * @brief 保存中の過去ゲームメッセージの数を返す。 / How many messages are "available"? + * @return 残っているメッセージの数 */ -concptr quark_str(STR_OFFSET i) -{ - concptr q; - - /* Return NULL for an invalid index */ - if ((i < 1) || (i >= quark__num)) return NULL; - - /* Access the quark */ - q = quark__str[i]; - - /* Return the quark */ - return (q); -} - - - /*! - * @brief 保存中の過去ゲームメッセージの数を返す。 / How many messages are "available"? - * @return 残っているメッセージの数 - */ s32b message_num(void) { int n; diff --git a/src/util/util.h b/src/util/util.h index 7858ac008..45366c521 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -125,8 +125,6 @@ extern bool use_menu; extern pos_list tmp_pos; -extern STR_OFFSET quark__num; -extern concptr *quark__str; /* * Automatically generated "variable" declarations */ @@ -148,14 +146,6 @@ extern s16b command_new; extern concptr keymap_act[KEYMAP_MODES][256]; -/*! - * @brief 銘情報の最大数 / Maximum number of "quarks" (see "io.c") - * @note - * Default: assume at most 512 different inscriptions are used
- * Was 512... 256 quarks added for random artifacts
- */ -#define QUARK_MAX 768 - /* * OPTION: Maximum number of messages to remember (see "io.c") * Default: assume maximal memorization of 2048 total messages @@ -217,9 +207,6 @@ extern const char hexsym[16]; // todo ファイル処理関数・メッセージ処理関数・画面描画関数で最低限分割する. extern void flush(void); extern void move_cursor(int row, int col); -extern concptr quark_str(STR_OFFSET num); -extern void quark_init(void); -extern u16b quark_add(concptr str); extern s32b message_num(void); extern concptr message_str(int age); extern void message_add(concptr msg); diff --git a/src/wizard/wizard-spoiler.c b/src/wizard/wizard-spoiler.c index cc9df2c41..7447e81f7 100644 --- a/src/wizard/wizard-spoiler.c +++ b/src/wizard/wizard-spoiler.c @@ -37,6 +37,7 @@ #include "system/angband-version.h" #include "term/term-color-types.h" #include "util/angband-files.h" +#include "util/quarks.h" #include "view/display-lore.h" /* -- 2.11.0