diff options
Diffstat (limited to 'src/headless/main.cpp')
-rw-r--r-- | src/headless/main.cpp | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/src/headless/main.cpp b/src/headless/main.cpp index 69e1e67..9366f12 100644 --- a/src/headless/main.cpp +++ b/src/headless/main.cpp @@ -1,13 +1,13 @@ #ifdef OPENVIC_SIM_HEADLESS -#include <openvic/utility/Logger.hpp> #include <openvic/GameManager.hpp> #include <openvic/dataloader/Dataloader.hpp> +#include <openvic/utility/Logger.hpp> using namespace OpenVic; static char const* get_program_name(char const* name) { - static char const* const missing_name = "<program>"; + static constexpr char const* missing_name = "<program>"; if (name == nullptr) return missing_name; char const* last_separator = name; while (*name != '\0') { @@ -20,14 +20,8 @@ static char const* get_program_name(char const* name) { return last_separator; } -int main(int argc, char const* argv[]) { - if (argc < 2) { - std::cout << "Usage: " << get_program_name(argc > 0 ? argv[0] : nullptr) << " <base defines dir> [[mod defines dir]+]" << std::endl; - std::cout << "Requires defines path(s) as arguments, starting with the base defines and continuing with mods (paths with spaces need to be enclosed in \"quotes\")." << std::endl; - return -1; - } - - std::cout << "!!! HEADLESS SIMULATION START !!!" << std::endl; +static return_t headless_load(std::vector<std::filesystem::path> const& roots) { + return_t ret = SUCCESS; Logger::set_info_func([](std::string&& str) { std::cout << str; }); Logger::set_error_func([](std::string&& str) { std::cerr << str; }); @@ -37,20 +31,47 @@ int main(int argc, char const* argv[]) { } }; Dataloader dataloader; - std::vector<std::filesystem::path> roots; - for (int i = 1; i < argc; ++i) { - roots.push_back(argv[i]); + if (dataloader.set_roots(roots) != SUCCESS) { + Logger::error("Failed to set dataloader roots!"); + ret = FAILURE; } - dataloader.set_roots(roots); - if (dataloader.load_defines(game_manager) != SUCCESS) { Logger::error("Failed to load defines!"); + ret = FAILURE; } if (game_manager.load_hardcoded_defines() != SUCCESS) { Logger::error("Failed to load hardcoded defines!"); + ret = FAILURE; } + return ret; +} + +int main(int argc, char const* argv[]) { + std::vector<std::filesystem::path> roots; + if (argc < 2) { + // TODO - non-Windows default paths + static const std::filesystem::path default_path = "C:/Program Files (x86)/Steam/steamapps/common/Victoria 2"; + + std::cout << "Usage: " << get_program_name(argc > 0 ? argv[0] : nullptr) << " <base defines dir> [[mod defines dir]+]\n" + << "Requires defines path(s) as arguments, starting with the base defines and continuing with mods.\n" + << "(Paths with spaces need to be enclosed in \"quotes\").\n" + << "Defaulting to " << default_path << std::endl; + roots.push_back(default_path); + } else { + for (int i = 1; i < argc; ++i) { + roots.push_back(argv[i]); + } + } + + std::cout << "!!! HEADLESS SIMULATION START !!!" << std::endl; + + const return_t ret = headless_load(roots); + std::cout << "!!! HEADLESS SIMULATION END !!!" << std::endl; - return 0; + + std::cout << "\nLoad returned: " << (ret == SUCCESS ? "SUCCESS" : "FAILURE") << std::endl; + + return ret == SUCCESS ? 0 : -1; } #endif |