From 820c4bd25c5caeefbeda5e040c989162eced7fac Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 2 Nov 2017 04:11:00 +0100 Subject: [PATCH] rwengine: GameData accepts rwfs::path as path of game data --- rwengine/src/engine/GameData.cpp | 10 ++++++---- rwengine/src/engine/GameData.hpp | 8 ++++---- rwengine/src/script/modules/GTA3ModuleImpl.inl | 2 +- rwgame/GameConfig.hpp | 4 ++-- rwgame/RWGame.cpp | 6 +++--- rwgame/states/IngameState.cpp | 4 ++-- rwlib/source/platform/FileIndex.cpp | 2 +- rwlib/source/platform/FileIndex.hpp | 2 +- tests/test_Config.cpp | 6 +++--- tests/test_Globals.cpp | 2 +- 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/rwengine/src/engine/GameData.cpp b/rwengine/src/engine/GameData.cpp index 1e02aa32..61e3c43d 100644 --- a/rwengine/src/engine/GameData.cpp +++ b/rwengine/src/engine/GameData.cpp @@ -20,7 +20,7 @@ #include #include -GameData::GameData(Logger* log, const std::string& path) +GameData::GameData(Logger* log, const rwfs::path& path) : datpath(path), logger(log), engine(nullptr) { dffLoader.setTextureLookupCallback( [&](const std::string& texture, const std::string&) { @@ -696,11 +696,13 @@ float GameData::getWaveHeightAt(const glm::vec3& ws) const { WATER_HEIGHT; } -bool GameData::isValidGameDirectory(const std::string& path) { - if (path.empty()) { +bool GameData::isValidGameDirectory(const rwfs::path& path) { + rwfs::error_code ec; + if (!rwfs::is_directory(path, ec)) { + std::cerr << "first test failed\n"; return false; } LoaderIMG i; - return i.load(path + "/models/gta3.img"); + return i.load((path / "models/gta3.img").string()); //FIXME: to path } diff --git a/rwengine/src/engine/GameData.hpp b/rwengine/src/engine/GameData.hpp index 1c1313e6..f68bdd18 100644 --- a/rwengine/src/engine/GameData.hpp +++ b/rwengine/src/engine/GameData.hpp @@ -38,7 +38,7 @@ class SCMFile; */ class GameData { private: - std::string datpath; + rwfs::path datpath; std::string splash; std::string currenttextureslot; @@ -50,7 +50,7 @@ public: * ctor * @param path Path to the root of the game data. */ - GameData(Logger* log, const std::string& path = ""); + GameData(Logger* log, const rwfs::path& path); ~GameData(); GameWorld* engine; @@ -65,7 +65,7 @@ public: /** * Returns the game data path */ - const std::string& getDataPath() const { + const rwfs::path& getDataPath() const { return datpath; } @@ -361,7 +361,7 @@ public: /** * Determines whether the given path is a valid game directory. */ - static bool isValidGameDirectory(const std::string& path); + static bool isValidGameDirectory(const rwfs::path& path); }; #endif diff --git a/rwengine/src/script/modules/GTA3ModuleImpl.inl b/rwengine/src/script/modules/GTA3ModuleImpl.inl index 3915b407..60aa8d88 100644 --- a/rwengine/src/script/modules/GTA3ModuleImpl.inl +++ b/rwengine/src/script/modules/GTA3ModuleImpl.inl @@ -9684,7 +9684,7 @@ void opcode_0354(const ScriptArguments& args, const ScriptFloat arg1) { vehicle0->setPrimaryColour(c1);\ vehicle0->setSecondaryColour(c2);\ args.getWorld()->chase.addChaseVehicle(vehicle0, path,\ - args.getWorld()->data->getDataPath()+"/data/paths/CHASE" #path ".DAT");\ + args.getWorld()->data->getDataPath().string()+"/data/paths/CHASE" #path ".DAT");\ } CHASE_VEHICLE(116, 273.5422f, -1167.1907f, 24.9906f, 64.f, 2, 1, 0); diff --git a/rwgame/GameConfig.hpp b/rwgame/GameConfig.hpp index 813b0094..8fb3c280 100644 --- a/rwgame/GameConfig.hpp +++ b/rwgame/GameConfig.hpp @@ -213,8 +213,8 @@ public: */ std::string getDefaultINIString(); - const std::string &getGameDataPath() const { - return m_gamePath.string(); //FIXME: change to path + const rwfs::path &getGameDataPath() const { + return m_gamePath; } const std::string &getGameLanguage() const { return m_gameLanguage; diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index 47139f68..ef49edc6 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -46,11 +46,11 @@ RWGame::RWGame(Logger& log, int argc, char* argv[]) ? options["benchmark"].as() : ""); - log.info("Game", "Game directory: " + config.getGameDataPath()); + log.info("Game", "Game directory: " + config.getGameDataPath().string()); if (!GameData::isValidGameDirectory(config.getGameDataPath())) { throw std::runtime_error("Invalid game directory path: " + - config.getGameDataPath()); + config.getGameDataPath().string()); } data.load(); @@ -70,7 +70,7 @@ RWGame::RWGame(Logger& log, int argc, char* argv[]) btIDebugDraw::DBG_DrawConstraintLimits); debug.setShaderProgram(renderer.worldProg.get()); - data.loadDynamicObjects(config.getGameDataPath() + "/data/object.dat"); + data.loadDynamicObjects((config.getGameDataPath() / "data/object.dat").string()); // FIXME: use path data.loadGXT("text/" + config.getGameLanguage() + ".gxt"); diff --git a/rwgame/states/IngameState.cpp b/rwgame/states/IngameState.cpp index 056a5c2e..6298ed96 100644 --- a/rwgame/states/IngameState.cpp +++ b/rwgame/states/IngameState.cpp @@ -64,8 +64,8 @@ void IngameState::startTest() { void IngameState::startGame() { game->startScript("data/main.scm"); game->getScriptVM()->startThread(0); - getWorld()->sound.playBackground(getWorld()->data->getDataPath() + - "/audio/City.wav"); + getWorld()->sound.playBackground(getWorld()->data->getDataPath().string() + + "/audio/City.wav"); //FIXME: use path } void IngameState::enter() { diff --git a/rwlib/source/platform/FileIndex.cpp b/rwlib/source/platform/FileIndex.cpp index 5f01da10..14a19a71 100644 --- a/rwlib/source/platform/FileIndex.cpp +++ b/rwlib/source/platform/FileIndex.cpp @@ -34,7 +34,7 @@ FileHandle FileIndex::openFilePath(const std::string& file_path) { return std::make_shared(data, length); } -void FileIndex::indexTree(const std::string& root) { +void FileIndex::indexTree(const rwfs::path& root) { for (const rwfs::path& path : rwfs::recursive_directory_iterator(root)) { if (!rwfs::is_regular_file(path)) { continue; diff --git a/rwlib/source/platform/FileIndex.hpp b/rwlib/source/platform/FileIndex.hpp index fe24b21b..03838b8a 100644 --- a/rwlib/source/platform/FileIndex.hpp +++ b/rwlib/source/platform/FileIndex.hpp @@ -68,7 +68,7 @@ public: * Adds the files contained within the given directory tree to the * file index. */ - void indexTree(const std::string& root); + void indexTree(const rwfs::path& root); /** * Adds the files contained within the given Archive file to the diff --git a/tests/test_Config.cpp b/tests/test_Config.cpp index f7952e52..e9d88346 100644 --- a/tests/test_Config.cpp +++ b/tests/test_Config.cpp @@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(test_config_valid) { 0); BOOST_CHECK_EQUAL(config.getParseResult().getKeysInvalidData().size(), 0); - BOOST_CHECK_EQUAL(config.getGameDataPath(), "/dev/test"); + BOOST_CHECK_EQUAL(config.getGameDataPath().string(), "/dev/test"); BOOST_CHECK_EQUAL(config.getGameLanguage(), "american"); BOOST_CHECK(config.getInputInvertY()); } @@ -300,7 +300,7 @@ BOOST_AUTO_TEST_CASE(test_config_valid_modified) { BOOST_CHECK_EQUAL(config.getParseResult().getKeysInvalidData().size(), 0); BOOST_CHECK(!config.getInputInvertY()); - BOOST_CHECK_EQUAL(config.getGameDataPath(), "Liberty City"); + BOOST_CHECK_EQUAL(config.getGameDataPath().string(), "Liberty City"); } BOOST_AUTO_TEST_CASE(test_config_save) { @@ -325,7 +325,7 @@ BOOST_AUTO_TEST_CASE(test_config_save) { GameConfig config2; config2.loadFile(tempFile.path()); - BOOST_CHECK_EQUAL(config2.getGameDataPath(), "Liberty City"); + BOOST_CHECK_EQUAL(config2.getGameDataPath().string(), "Liberty City"); simpleConfig_t cfg2 = readConfig(tempFile.path()); BOOST_CHECK_EQUAL(cfg2["game"]["path"], "Liberty City"); diff --git a/tests/test_Globals.cpp b/tests/test_Globals.cpp index 6ca00866..1ba30e87 100644 --- a/tests/test_Globals.cpp +++ b/tests/test_Globals.cpp @@ -6,6 +6,6 @@ std::string Global::getGamePath() { GameConfig config; config.loadFile(GameConfig::getDefaultConfigPath() / "openrw.ini"); - return config.getGameDataPath(); + return config.getGameDataPath().string(); //FIXME: use path } #endif