1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

rwengine: GameData accepts rwfs::path as path of game data

This commit is contained in:
Anonymous Maarten 2017-11-02 04:11:00 +01:00 committed by Daniel Evans
parent 55dd0beea0
commit 820c4bd25c
10 changed files with 24 additions and 22 deletions

View File

@ -20,7 +20,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
GameData::GameData(Logger* log, const std::string& path) GameData::GameData(Logger* log, const rwfs::path& path)
: datpath(path), logger(log), engine(nullptr) { : datpath(path), logger(log), engine(nullptr) {
dffLoader.setTextureLookupCallback( dffLoader.setTextureLookupCallback(
[&](const std::string& texture, const std::string&) { [&](const std::string& texture, const std::string&) {
@ -696,11 +696,13 @@ float GameData::getWaveHeightAt(const glm::vec3& ws) const {
WATER_HEIGHT; WATER_HEIGHT;
} }
bool GameData::isValidGameDirectory(const std::string& path) { bool GameData::isValidGameDirectory(const rwfs::path& path) {
if (path.empty()) { rwfs::error_code ec;
if (!rwfs::is_directory(path, ec)) {
std::cerr << "first test failed\n";
return false; return false;
} }
LoaderIMG i; LoaderIMG i;
return i.load(path + "/models/gta3.img"); return i.load((path / "models/gta3.img").string()); //FIXME: to path
} }

View File

@ -38,7 +38,7 @@ class SCMFile;
*/ */
class GameData { class GameData {
private: private:
std::string datpath; rwfs::path datpath;
std::string splash; std::string splash;
std::string currenttextureslot; std::string currenttextureslot;
@ -50,7 +50,7 @@ public:
* ctor * ctor
* @param path Path to the root of the game data. * @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(); ~GameData();
GameWorld* engine; GameWorld* engine;
@ -65,7 +65,7 @@ public:
/** /**
* Returns the game data path * Returns the game data path
*/ */
const std::string& getDataPath() const { const rwfs::path& getDataPath() const {
return datpath; return datpath;
} }
@ -361,7 +361,7 @@ public:
/** /**
* Determines whether the given path is a valid game directory. * 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 #endif

View File

@ -9684,7 +9684,7 @@ void opcode_0354(const ScriptArguments& args, const ScriptFloat arg1) {
vehicle0->setPrimaryColour(c1);\ vehicle0->setPrimaryColour(c1);\
vehicle0->setSecondaryColour(c2);\ vehicle0->setSecondaryColour(c2);\
args.getWorld()->chase.addChaseVehicle(vehicle0, path,\ 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); CHASE_VEHICLE(116, 273.5422f, -1167.1907f, 24.9906f, 64.f, 2, 1, 0);

View File

@ -213,8 +213,8 @@ public:
*/ */
std::string getDefaultINIString(); std::string getDefaultINIString();
const std::string &getGameDataPath() const { const rwfs::path &getGameDataPath() const {
return m_gamePath.string(); //FIXME: change to path return m_gamePath;
} }
const std::string &getGameLanguage() const { const std::string &getGameLanguage() const {
return m_gameLanguage; return m_gameLanguage;

View File

@ -46,11 +46,11 @@ RWGame::RWGame(Logger& log, int argc, char* argv[])
? options["benchmark"].as<std::string>() ? options["benchmark"].as<std::string>()
: ""); : "");
log.info("Game", "Game directory: " + config.getGameDataPath()); log.info("Game", "Game directory: " + config.getGameDataPath().string());
if (!GameData::isValidGameDirectory(config.getGameDataPath())) { if (!GameData::isValidGameDirectory(config.getGameDataPath())) {
throw std::runtime_error("Invalid game directory path: " + throw std::runtime_error("Invalid game directory path: " +
config.getGameDataPath()); config.getGameDataPath().string());
} }
data.load(); data.load();
@ -70,7 +70,7 @@ RWGame::RWGame(Logger& log, int argc, char* argv[])
btIDebugDraw::DBG_DrawConstraintLimits); btIDebugDraw::DBG_DrawConstraintLimits);
debug.setShaderProgram(renderer.worldProg.get()); 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"); data.loadGXT("text/" + config.getGameLanguage() + ".gxt");

View File

@ -64,8 +64,8 @@ void IngameState::startTest() {
void IngameState::startGame() { void IngameState::startGame() {
game->startScript("data/main.scm"); game->startScript("data/main.scm");
game->getScriptVM()->startThread(0); game->getScriptVM()->startThread(0);
getWorld()->sound.playBackground(getWorld()->data->getDataPath() + getWorld()->sound.playBackground(getWorld()->data->getDataPath().string() +
"/audio/City.wav"); "/audio/City.wav"); //FIXME: use path
} }
void IngameState::enter() { void IngameState::enter() {

View File

@ -34,7 +34,7 @@ FileHandle FileIndex::openFilePath(const std::string& file_path) {
return std::make_shared<FileContentsInfo>(data, length); return std::make_shared<FileContentsInfo>(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)) { for (const rwfs::path& path : rwfs::recursive_directory_iterator(root)) {
if (!rwfs::is_regular_file(path)) { if (!rwfs::is_regular_file(path)) {
continue; continue;

View File

@ -68,7 +68,7 @@ public:
* Adds the files contained within the given directory tree to the * Adds the files contained within the given directory tree to the
* file index. * 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 * Adds the files contained within the given Archive file to the

View File

@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(test_config_valid) {
0); 0);
BOOST_CHECK_EQUAL(config.getParseResult().getKeysInvalidData().size(), 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_EQUAL(config.getGameLanguage(), "american");
BOOST_CHECK(config.getInputInvertY()); 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_EQUAL(config.getParseResult().getKeysInvalidData().size(), 0);
BOOST_CHECK(!config.getInputInvertY()); 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) { BOOST_AUTO_TEST_CASE(test_config_save) {
@ -325,7 +325,7 @@ BOOST_AUTO_TEST_CASE(test_config_save) {
GameConfig config2; GameConfig config2;
config2.loadFile(tempFile.path()); 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()); simpleConfig_t cfg2 = readConfig(tempFile.path());
BOOST_CHECK_EQUAL(cfg2["game"]["path"], "Liberty City"); BOOST_CHECK_EQUAL(cfg2["game"]["path"], "Liberty City");

View File

@ -6,6 +6,6 @@
std::string Global::getGamePath() { std::string Global::getGamePath() {
GameConfig config; GameConfig config;
config.loadFile(GameConfig::getDefaultConfigPath() / "openrw.ini"); config.loadFile(GameConfig::getDefaultConfigPath() / "openrw.ini");
return config.getGameDataPath(); return config.getGameDataPath().string(); //FIXME: use path
} }
#endif #endif