From 553cacd88eed1c44b6464485697d2960fa2a447d Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Wed, 4 Apr 2018 21:55:08 +1100 Subject: [PATCH] Moved game version stuff from game_config.hpp to version.hpp They're still in the game_config namespace but are now in a more logical header. game_config::version has been replaced with wesnoth_version.str(), save for one case where it was replaced with wesnoth_version directly (it was a comparison against another version_info object; no need to compare against a string...). Also cleaned up a bunch of game_config.hpp includes. (cherry-picked from commit b8d051cb72e51682d0fc41a3a37442ed7ecb553d) --- src/addon/info.cpp | 1 - src/ai/testing.cpp | 1 + src/build_info.cpp | 1 + src/color_range.cpp | 1 - src/deprecation.cpp | 1 - src/display.hpp | 1 + src/game_classification.cpp | 4 ++-- src/game_config.cpp | 20 +------------------- src/game_config.hpp | 7 ------- src/game_end_exceptions.cpp | 1 - src/game_initialization/mp_game_utils.cpp | 4 ++-- src/game_initialization/multiplayer.cpp | 4 ++-- src/gui/dialogs/unit_create.cpp | 1 - src/image.hpp | 1 - src/mouse_events.cpp | 1 - src/savegame.cpp | 4 ++-- src/scripting/lua_kernel_base.cpp | 4 ++-- src/serialization/preprocessor.cpp | 1 - src/server/server.cpp | 4 ++-- src/terrain/filter.hpp | 1 - src/units/animation.hpp | 1 + src/units/frame.hpp | 1 + src/version.cpp | 22 ++++++++++++++++++++++ src/version.hpp | 10 ++++++++++ src/wesnoth.cpp | 2 +- 25 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/addon/info.cpp b/src/addon/info.cpp index 12ed059be82..7b05a07886e 100644 --- a/src/addon/info.cpp +++ b/src/addon/info.cpp @@ -17,7 +17,6 @@ #include "addon/manager.hpp" #include "config.hpp" #include "font/pango/escape.hpp" -#include "game_config.hpp" #include "gettext.hpp" #include "image.hpp" #include "log.hpp" diff --git a/src/ai/testing.cpp b/src/ai/testing.cpp index ffa39647fa0..752b81dbfac 100644 --- a/src/ai/testing.cpp +++ b/src/ai/testing.cpp @@ -25,6 +25,7 @@ #include "team.hpp" #include "units/unit.hpp" #include "tod_manager.hpp" +#include "version.hpp" static lg::log_domain log_ai_testing("ai/testing"); #define DBG_AI_TESTING LOG_STREAM(debug, log_ai_testing) diff --git a/src/build_info.cpp b/src/build_info.cpp index 28014aa91f9..dc69e90712a 100644 --- a/src/build_info.cpp +++ b/src/build_info.cpp @@ -21,6 +21,7 @@ #include "filesystem.hpp" #include "formatter.hpp" #include "gettext.hpp" +#include "version.hpp" #include diff --git a/src/color_range.cpp b/src/color_range.cpp index 78d65b2f601..3e9ecaf4a1e 100644 --- a/src/color_range.cpp +++ b/src/color_range.cpp @@ -20,7 +20,6 @@ #include "color_range.hpp" -#include "game_config.hpp" #include "map/map.hpp" #include diff --git a/src/deprecation.cpp b/src/deprecation.cpp index ca6fe175b84..34ff216bcb3 100644 --- a/src/deprecation.cpp +++ b/src/deprecation.cpp @@ -14,7 +14,6 @@ #include "deprecation.hpp" #include "formula/string_utils.hpp" -#include "game_config.hpp" #include "gettext.hpp" #include "log.hpp" #include "preferences/general.hpp" diff --git a/src/display.hpp b/src/display.hpp index 62da0b01e1d..af39f5cdfe6 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -51,6 +51,7 @@ namespace wb { #include "animated.hpp" #include "display_context.hpp" #include "font/standard_colors.hpp" +#include "game_config.hpp" #include "image.hpp" //only needed for enums (!) #include "key.hpp" #include "time_of_day.hpp" diff --git a/src/game_classification.cpp b/src/game_classification.cpp index f06a81e20e8..54d9fd81265 100644 --- a/src/game_classification.cpp +++ b/src/game_classification.cpp @@ -15,9 +15,9 @@ #include "game_classification.hpp" #include "config.hpp" -#include "game_config.hpp" #include "log.hpp" #include "serialization/string_utils.hpp" +#include "version.hpp" static lg::log_domain log_engine("engine"); #define ERR_NG LOG_STREAM(err, log_engine) @@ -96,7 +96,7 @@ config game_classification::to_config() const { config cfg; cfg["label"] = label; - cfg["version"] = game_config::version; + cfg["version"] = game_config::wesnoth_version.str(); cfg["campaign_type"] = campaign_type.to_string(); cfg["campaign_define"] = campaign_define; cfg["campaign_extra_defines"] = utils::join(campaign_xtra_defines); diff --git a/src/game_config.cpp b/src/game_config.cpp index aac50907ee6..982b808b04c 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -23,9 +23,6 @@ #include "version.hpp" #include "wesconfig.h" #include "serialization/string_utils.hpp" -#ifdef LOAD_REVISION -#include "revision.h" -#endif static lg::log_domain log_engine("engine"); #define LOG_NG LOG_STREAM(info, log_engine) @@ -33,24 +30,9 @@ static lg::log_domain log_engine("engine"); namespace game_config { - // -// Path and revision info +// Path info // -const std::string version = VERSION; - -const version_info wesnoth_version(VERSION); -const version_info min_savegame_version(MIN_SAVEGAME_VERSION); -const version_info test_version("test"); - -#ifdef REVISION -const std::string revision = VERSION " (" REVISION ")"; -#elif defined(VCS_SHORT_HASH) && defined(VCS_WC_MODIFIED) -const std::string revision = std::string(VERSION) + " (" + VCS_SHORT_HASH + (VCS_WC_MODIFIED ? "-Modified" : "-Clean") + ")"; -#else -const std::string revision = VERSION; -#endif - #ifdef WESNOTH_PATH std::string path = WESNOTH_PATH; #else diff --git a/src/game_config.hpp b/src/game_config.hpp index 774829ac14f..4db1d500fc3 100644 --- a/src/game_config.hpp +++ b/src/game_config.hpp @@ -15,7 +15,6 @@ #pragma once class config; -class version_info; class color_range; #include "color.hpp" @@ -38,8 +37,6 @@ namespace game_config extern unsigned int tile_size; extern unsigned lobby_network_timer; extern unsigned lobby_refresh; - extern const std::string version; - extern const std::string revision; extern const std::string default_title_string; extern std::string default_terrain; @@ -189,9 +186,5 @@ namespace game_config color_t red_to_green(int val, bool for_text = true); color_t blue_to_white(int val, bool for_text = true); - extern const version_info wesnoth_version; - extern const version_info min_savegame_version; - extern const version_info test_version; - std::string get_default_title_string(); } diff --git a/src/game_end_exceptions.cpp b/src/game_end_exceptions.cpp index 01f78123dde..1d59f70da42 100644 --- a/src/game_end_exceptions.cpp +++ b/src/game_end_exceptions.cpp @@ -16,7 +16,6 @@ #include "game_end_exceptions.hpp" #include "config.hpp" -#include "game_config.hpp" transient_end_level::transient_end_level() : carryover_report(true) diff --git a/src/game_initialization/mp_game_utils.cpp b/src/game_initialization/mp_game_utils.cpp index 4f93a0eabda..4754cec8c3f 100644 --- a/src/game_initialization/mp_game_utils.cpp +++ b/src/game_initialization/mp_game_utils.cpp @@ -15,11 +15,11 @@ #include "config.hpp" #include "formula/string_utils.hpp" -#include "game_config.hpp" #include "game_config_manager.hpp" #include "gettext.hpp" #include "log.hpp" #include "saved_game.hpp" +#include "version.hpp" #include "wesnothd_connection_error.hpp" static lg::log_domain log_engine("engine"); @@ -123,7 +123,7 @@ config initial_level_config(saved_game& state) } // This will force connecting clients to be using the same version number as us. - level["version"] = game_config::version; + level["version"] = game_config::wesnoth_version.str(); return level; } diff --git a/src/game_initialization/multiplayer.cpp b/src/game_initialization/multiplayer.cpp index 5871d64935f..98f7bf9c87b 100644 --- a/src/game_initialization/multiplayer.cpp +++ b/src/game_initialization/multiplayer.cpp @@ -119,7 +119,7 @@ std::pair open_connection(std::string host) utils::string_map i18n_symbols; i18n_symbols["required_version"] = version; - i18n_symbols["your_version"] = game_config::version; + i18n_symbols["your_version"] = game_config::wesnoth_version.str(); const std::string errorstring = VGETTEXT("The server accepts versions '$required_version', but you are using version '$your_version'", i18n_symbols); throw wesnothd_error(errorstring); @@ -155,7 +155,7 @@ std::pair open_connection(std::string host) if(data.has_child("version")) { config cfg; config res; - cfg["version"] = game_config::version; + cfg["version"] = game_config::wesnoth_version.str(); res.add_child("version", std::move(cfg)); sock->send_data(res); } diff --git a/src/gui/dialogs/unit_create.cpp b/src/gui/dialogs/unit_create.cpp index 01649ab6617..88a43e1cee1 100644 --- a/src/gui/dialogs/unit_create.cpp +++ b/src/gui/dialogs/unit_create.cpp @@ -33,7 +33,6 @@ #include "gui/widgets/unit_preview_pane.hpp" #include "gui/widgets/window.hpp" #include "help/help.hpp" -#include "game_config.hpp" #include "gettext.hpp" #include "play_controller.hpp" #include "units/types.hpp" diff --git a/src/image.hpp b/src/image.hpp index 053c54be179..d6bbe78f9a7 100644 --- a/src/image.hpp +++ b/src/image.hpp @@ -16,7 +16,6 @@ #include "map/location.hpp" #include "terrain/translation.hpp" -#include "game_config.hpp" #include #include diff --git a/src/mouse_events.cpp b/src/mouse_events.cpp index 32bc8de78ac..bce2b593149 100644 --- a/src/mouse_events.cpp +++ b/src/mouse_events.cpp @@ -21,7 +21,6 @@ #include "config.hpp" // for config #include "cursor.hpp" // for set, CURSOR_TYPE::NORMAL, etc #include "game_board.hpp" // for game_board, etc -#include "game_config.hpp" // for red_to_green #include "game_events/pump.hpp" // for fire #include "gettext.hpp" // for _ #include "gui/dialogs/transient_message.hpp" // for show_transient_message diff --git a/src/savegame.cpp b/src/savegame.cpp index 288a9101952..832edbe7b22 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -217,7 +217,7 @@ bool loadgame::check_version_compatibility() bool loadgame::check_version_compatibility(const version_info & save_version) { - if (save_version == game_config::version) { + if (save_version == game_config::wesnoth_version) { return true; } @@ -504,7 +504,7 @@ void savegame::write_game(config_writer &out) { log_scope("write_game"); - out.write_key_val("version", game_config::version); + out.write_key_val("version", game_config::wesnoth_version.str()); gamestate_.write_general_info(out); out.open_child("statistics"); diff --git a/src/scripting/lua_kernel_base.cpp b/src/scripting/lua_kernel_base.cpp index 382611b8872..b699f0c64d8 100644 --- a/src/scripting/lua_kernel_base.cpp +++ b/src/scripting/lua_kernel_base.cpp @@ -287,7 +287,7 @@ static int intf_deprecated_message(lua_State* L) { const DEP_LEVEL level = DEP_LEVEL(luaL_checkinteger(L, 2)); const std::string ver_str = lua_isnoneornil(L, 3) ? "" : luaL_checkstring(L, 3); const std::string detail = luaW_checktstring(L, 4); - const version_info ver = ver_str.empty() ? game_config::version : ver_str; + const version_info ver = ver_str.empty() ? game_config::wesnoth_version.str() : ver_str; const std::string msg = deprecated_message(elem, level, ver, detail); if(level < DEP_LEVEL::INDEFINITE || level >= DEP_LEVEL::REMOVED) { // Invalid deprecation level or level 4 deprecation should raise an interpreter error @@ -834,7 +834,7 @@ int lua_kernel_base::impl_game_config_get(lua_State* L) return_int_attrib("rest_heal_amount", game_config::rest_heal_amount); return_int_attrib("recall_cost", game_config::recall_cost); return_int_attrib("kill_experience", game_config::kill_experience); - return_string_attrib("version", game_config::version); + return_string_attrib("version", game_config::wesnoth_version.str()); return_bool_attrib("debug", game_config::debug); return_bool_attrib("debug_lua", game_config::debug_lua); return_bool_attrib("mp_debug", game_config::mp_debug); diff --git a/src/serialization/preprocessor.cpp b/src/serialization/preprocessor.cpp index 1a4302ec369..22fcb4abaf2 100644 --- a/src/serialization/preprocessor.cpp +++ b/src/serialization/preprocessor.cpp @@ -23,7 +23,6 @@ #include "buffered_istream.hpp" #include "config.hpp" #include "filesystem.hpp" -#include "game_config.hpp" #include "log.hpp" #include "serialization/binary_or_text.hpp" #include "serialization/parser.hpp" diff --git a/src/server/server.cpp b/src/server/server.cpp index 7865df7a08e..ccdf2cab9a1 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -445,7 +445,7 @@ void server::load_config() { if (versions.empty() == false) { accepted_versions_ = utils::split(versions); } else { - accepted_versions_.push_back(game_config::version); + accepted_versions_.push_back(game_config::wesnoth_version.str()); accepted_versions_.push_back("test"); } @@ -2801,7 +2801,7 @@ int main(int argc, char** argv) { << " -V, --version Returns the server version.\n"; return 0; } else if (val == "--version" || val == "-V") { - std::cout << "Battle for Wesnoth server " << game_config::version + std::cout << "Battle for Wesnoth server " << game_config::wesnoth_version.str() << "\n"; return 0; } else if (val == "--daemon" || val == "-d") { diff --git a/src/terrain/filter.hpp b/src/terrain/filter.hpp index ddcd2b3badc..7d8382f8c75 100644 --- a/src/terrain/filter.hpp +++ b/src/terrain/filter.hpp @@ -14,7 +14,6 @@ #pragma once -#include "game_config.hpp" #include "pathutils.hpp" #include "terrain/translation.hpp" #include "variable.hpp" diff --git a/src/units/animation.hpp b/src/units/animation.hpp index 7607fad8c92..896d67da6cf 100644 --- a/src/units/animation.hpp +++ b/src/units/animation.hpp @@ -15,6 +15,7 @@ #pragma once #include "animated.hpp" +#include "color.hpp" #include "config.hpp" #include "halo.hpp" #include "units/frame.hpp" diff --git a/src/units/frame.hpp b/src/units/frame.hpp index 471f9baab24..cf2fb15d955 100644 --- a/src/units/frame.hpp +++ b/src/units/frame.hpp @@ -21,6 +21,7 @@ #include "units/frame_private.hpp" +#include "color.hpp" #include "halo.hpp" #include "image.hpp" diff --git a/src/version.cpp b/src/version.cpp index c9ae4b585a5..fa0ecef2d36 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -13,8 +13,14 @@ */ #include "version.hpp" + #include "lexical_cast.hpp" #include "serialization/string_utils.hpp" +#include "wesconfig.h" + +#ifdef LOAD_REVISION +#include "revision.h" +#endif #include #include @@ -22,6 +28,22 @@ #include +namespace game_config +{ +const version_info wesnoth_version(VERSION); +const version_info min_savegame_version(MIN_SAVEGAME_VERSION); +const version_info test_version("test"); + +#ifdef REVISION +const std::string revision = VERSION " (" REVISION ")"; +#elif defined(VCS_SHORT_HASH) && defined(VCS_WC_MODIFIED) +const std::string revision = std::string(VERSION) + " (" + VCS_SHORT_HASH + (VCS_WC_MODIFIED ? "-Modified" : "-Clean") + ")"; +#else +const std::string revision = VERSION; +#endif + +} // namespace game_config + version_info::version_info() : nums_(3,0), special_(""), special_separator_('\0') { diff --git a/src/version.hpp b/src/version.hpp index b3ac0895f4e..3833fcd8710 100644 --- a/src/version.hpp +++ b/src/version.hpp @@ -204,3 +204,13 @@ enum VERSION_COMP_OP { VERSION_COMP_OP parse_version_op(const std::string& op_str); bool do_version_check(const version_info& a, VERSION_COMP_OP op, const version_info& b); + +namespace game_config +{ +extern const version_info wesnoth_version; +extern const version_info min_savegame_version; +extern const version_info test_version; + +extern const std::string revision; + +} // namespace game_config diff --git a/src/wesnoth.cpp b/src/wesnoth.cpp index 23bc091dd1d..876587112c2 100644 --- a/src/wesnoth.cpp +++ b/src/wesnoth.cpp @@ -471,7 +471,7 @@ static int process_command_args(const commandline_options& cmdline_opts) } if(cmdline_opts.version) { - std::cout << "Battle for Wesnoth" << " " << game_config::version << "\n\n"; + std::cout << "Battle for Wesnoth" << " " << game_config::wesnoth_version.str() << "\n\n"; std::cout << "Library versions:\n" << game_config::library_versions_report() << '\n'; std::cout << "Optional features:\n" << game_config::optional_features_report();