1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-02 16:49:46 +02: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 <sstream>
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
}

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -46,11 +46,11 @@ RWGame::RWGame(Logger& log, int argc, char* argv[])
? 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())) {
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");

View File

@ -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() {

View File

@ -34,7 +34,7 @@ FileHandle FileIndex::openFilePath(const std::string& file_path) {
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)) {
if (!rwfs::is_regular_file(path)) {
continue;

View File

@ -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

View File

@ -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");

View File

@ -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