Skip to content

Commit

Permalink
Moved game version stuff from game_config.hpp to version.hpp
Browse files Browse the repository at this point in the history
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 b8d051c)
  • Loading branch information
Vultraz committed Oct 7, 2018
1 parent 0a409c3 commit 553cacd
Show file tree
Hide file tree
Showing 25 changed files with 51 additions and 48 deletions.
1 change: 0 additions & 1 deletion src/addon/info.cpp
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/ai/testing.cpp
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/build_info.cpp
Expand Up @@ -21,6 +21,7 @@
#include "filesystem.hpp"
#include "formatter.hpp"
#include "gettext.hpp"
#include "version.hpp"

#include <algorithm>

Expand Down
1 change: 0 additions & 1 deletion src/color_range.cpp
Expand Up @@ -20,7 +20,6 @@

#include "color_range.hpp"

#include "game_config.hpp"
#include "map/map.hpp"

#include <iomanip>
Expand Down
1 change: 0 additions & 1 deletion src/deprecation.cpp
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/display.hpp
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/game_classification.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 1 addition & 19 deletions src/game_config.cpp
Expand Up @@ -23,34 +23,16 @@
#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)
#define ERR_NG LOG_STREAM(err, log_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
Expand Down
7 changes: 0 additions & 7 deletions src/game_config.hpp
Expand Up @@ -15,7 +15,6 @@
#pragma once

class config;
class version_info;
class color_range;

#include "color.hpp"
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion src/game_end_exceptions.cpp
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/game_initialization/mp_game_utils.cpp
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/game_initialization/multiplayer.cpp
Expand Up @@ -119,7 +119,7 @@ std::pair<wesnothd_connection_ptr, config> 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);
Expand Down Expand Up @@ -155,7 +155,7 @@ std::pair<wesnothd_connection_ptr, config> 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);
}
Expand Down
1 change: 0 additions & 1 deletion src/gui/dialogs/unit_create.cpp
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion src/image.hpp
Expand Up @@ -16,7 +16,6 @@

#include "map/location.hpp"
#include "terrain/translation.hpp"
#include "game_config.hpp"

#include <SDL.h>
#include <unordered_map>
Expand Down
1 change: 0 additions & 1 deletion src/mouse_events.cpp
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/savegame.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/scripting/lua_kernel_base.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/serialization/preprocessor.cpp
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/server/server.cpp
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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") {
Expand Down
1 change: 0 additions & 1 deletion src/terrain/filter.hpp
Expand Up @@ -14,7 +14,6 @@

#pragma once

#include "game_config.hpp"
#include "pathutils.hpp"
#include "terrain/translation.hpp"
#include "variable.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/units/animation.hpp
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "animated.hpp"
#include "color.hpp"
#include "config.hpp"
#include "halo.hpp"
#include "units/frame.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/units/frame.hpp
Expand Up @@ -21,6 +21,7 @@

#include "units/frame_private.hpp"

#include "color.hpp"
#include "halo.hpp"
#include "image.hpp"

Expand Down
22 changes: 22 additions & 0 deletions src/version.cpp
Expand Up @@ -13,15 +13,37 @@
*/

#include "version.hpp"

#include "lexical_cast.hpp"
#include "serialization/string_utils.hpp"
#include "wesconfig.h"

#ifdef LOAD_REVISION
#include "revision.h"
#endif

#include <cassert>
#include <functional>
#include <locale>

#include <boost/algorithm/string.hpp>

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')
{
Expand Down
10 changes: 10 additions & 0 deletions src/version.hpp
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/wesnoth.cpp
Expand Up @@ -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();

Expand Down

0 comments on commit 553cacd

Please sign in to comment.