1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

Merge pull request #137 from haphzd/patch-1

File loading improvements
This commit is contained in:
Daniel Evans 2016-06-29 22:26:58 +01:00 committed by GitHub
commit 30e4a7faf1
8 changed files with 13 additions and 24 deletions

View File

@ -105,7 +105,7 @@ public:
void loadHandling(const std::string& path);
SCMFile* loadSCM(const std::string& path);
SCMFile* loadSCM(const std::string& name);
void loadGXT(const std::string& name);

View File

@ -341,22 +341,12 @@ void GameData::loadHandling(const std::string& path)
l.loadHandling(path, vehicleInfo);
}
SCMFile *GameData::loadSCM(const std::string &path)
SCMFile *GameData::loadSCM(const std::string &name)
{
std::ifstream f(datpath + "/" + path);
if(! f.is_open() ) return nullptr;
f.seekg(0, std::ios_base::end);
unsigned int size = f.tellg();
f.seekg(0);
char* buff = new char[size];
f.read(buff, size);
auto scm_h = openFile(name);
SCMFile* scm = new SCMFile;
scm->loadFile(buff, size);
delete[] buff;
scm->loadFile(scm_h->data, scm_h->length);
scm_h.reset();
return scm;
}
@ -371,7 +361,7 @@ void GameData::loadGXT(const std::string &name)
void GameData::loadWaterpro(const std::string& path)
{
std::ifstream ifstr(path.c_str());
std::ifstream ifstr(path.c_str(), std::ios_base::binary);
if(ifstr.is_open()) {
uint32_t numlevels;

View File

@ -510,7 +510,7 @@ template<class T> bool readBlock(std::FILE* str, T& out) {
bool SaveGame::loadGame(GameState& state, const std::string& file)
{
std::FILE* loadFile = std::fopen(file.c_str(), "r");
std::FILE* loadFile = std::fopen(file.c_str(), "rb");
if (loadFile == nullptr) {
std::cerr << "Failed to open save file" << std::endl;
return false;
@ -1202,7 +1202,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file)
#include <dirent.h>
bool SaveGame::getSaveInfo(const std::string& file, BasicState *basicState)
{
std::FILE* loadFile = std::fopen(file.c_str(), "r");
std::FILE* loadFile = std::fopen(file.c_str(), "rb");
SaveGameInfo info;
info.savePath = file;

View File

@ -107,7 +107,6 @@ RWGame::RWGame(int argc, char* argv[])
data->loadIMG("/models/gta3");
//engine->data.loadIMG("/models/txd");
data->loadIMG("/anim/cuts");
data->loadTXD("/models/hud.txd");
data->load();
@ -215,7 +214,7 @@ void RWGame::loadGame(const std::string& savename)
newGame();
startScript("data/main.scm");
startScript("main.scm");
if(! SaveGame::loadGame(*state, savename) )
{

View File

@ -74,7 +74,7 @@ void IngameState::startTest()
void IngameState::startGame()
{
game->startScript("data/main.scm");
game->startScript("main.scm");
game->getScript()->startThread(0);
getWorld()->sound.playBackground( getWorld()->data->getDataPath() + "/audio/City.wav" );
}

View File

@ -155,7 +155,7 @@ FileHandle FileIndex::openFile(const std::string& filename)
}
else
{
std::ifstream dfile(fsName.c_str());
std::ifstream dfile(fsName.c_str(), std::ios_base::binary);
if ( ! dfile.is_open()) {
throw std::runtime_error("Unable to open file: " + fsName);
}

View File

@ -106,7 +106,7 @@ void dumpOpcodes(SCMFile* scm, SCMOpcodes* codes, unsigned int offset, unsigned
void disassemble(const std::string& scmname)
{
std::ifstream scmfile(scmname.c_str());
std::ifstream scmfile(scmname.c_str(), std::ios_base::binary);
if( !scmfile.is_open() ) {
std::cerr << "Failed to open " << scmname << std::endl;

View File

@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(test_load_game)
GameState state;
GameWorld world();
SCMOpcodes s;
auto file = Global::get().d->loadSCM("data/main.scm");
auto file = Global::get().d->loadSCM("main.scm");
ScriptMachine machine(&state, file, &s);
state.world = Global::get().e;