mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-15 06:52:34 +02:00
rwengine: GameData accepts rwfs::path as path of game data
This commit is contained in:
parent
55dd0beea0
commit
820c4bd25c
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user