added more save/load code

This commit is contained in:
Pawel Kolodziejski 2004-11-01 16:36:41 +00:00
parent 64e1113686
commit c721d2579c
2 changed files with 87 additions and 0 deletions

View File

@ -90,6 +90,13 @@ void Engine::mainLoop() {
}
}
if (_savegameLoadRequest) {
savegameRestore();
}
if (_savegameSaveRequest) {
savegameSave();
}
if (_mode == ENGINE_MODE_SMUSH) {
if (g_smush->isPlaying()) {
movieTime_ = g_smush->getMovieTime();
@ -198,6 +205,78 @@ void Engine::mainLoop() {
}
}
void Engine::savegameGzread(void *data, int32 size) {
gzread(Engine::instance()->_savegameFileHandle, data, size);
}
void Engine::savegameGzwrite(void *data, int32 size) {
gzwrite(Engine::instance()->_savegameFileHandle, data, size);
}
void Engine::savegameRestore() {
_savegameLoadRequest = false;
char filename[200];
if (_savegameFileName == NULL) {
strcpy(filename, "grim.sav");
} else {
strcpy(filename, _savegameFileName);
}
_savegameFileHandle = gzopen(filename, "rb");
if (_savegameFileHandle == NULL) {
warning("savegameRestore() Error opening savegame file");
return;
}
//imuseStopAllSounds();
g_smush->stop();
// free all resource
// lock resources
//Chore_Restore(savegameGzread);
//Resource_Restore(savegameGzread);
//Text_Restore(savegameGzread);
//Room_Restore(savegameGzread);
//Actor_Restore(savegameGzread);
//Render_Restore(savegameGzread);
//Primitive_Restore(savegameGzread);
//Smush_Restore(savegameGzread);
//lua_Restore(savegameGzread);
// unlock resources
gzclose(_savegameFileHandle);
lua_dofile("patch05.bin");
}
void Engine::savegameCallback(void *func) {
}
void Engine::savegameSave() {
_savegameSaveRequest = false;
char filename[200];
if (_savegameFileName == NULL) {
strcpy(filename, "grim.sav");
} else {
strcpy(filename, _savegameFileName);
}
_savegameFileHandle = gzopen(filename, "wb");
if (_savegameFileHandle == NULL) {
warning("savegameSave() Error creating savegame file");
return;
}
savegameCallback(savegameGzwrite);
//Chore_Save(savegameGzwrite);
//Resource_Save(savegameGzwrite);
//Text_Save(savegameGzwrite);
//Room_Save(savegameGzwrite);
//Actor_Save(savegameGzwrite);
//Render_Save(savegameGzwrite);
//Primitive_Save(savegameGzwrite);
//Smush_Save(savegameGzwrite);
//lua_Save(savegameGzwrite);
gzclose(_savegameFileHandle);
}
void Engine::setScene(const char *name) {
Block *b = ResourceLoader::instance()->getFileBlock(name);
if (b == NULL)

View File

@ -23,6 +23,7 @@
#include <cstdlib>
#include <list>
#include <SDL_keysym.h>
#include <zlib.h>
class Actor;
@ -140,9 +141,16 @@ public:
}
}
void savegameSave();
void savegameRestore();
static void savegameGzread(void *data, int32 size);
static void savegameGzwrite(void *data, int32 size);
void savegameCallback(void *func);
bool _savegameLoadRequest;
bool _savegameSaveRequest;
char *_savegameFileName;
gzFile _savegameFileHandle;
private:
static Engine *instance_;