mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-10 11:51:52 +00:00
fixed save/restore lua state
This commit is contained in:
parent
90616dd1f8
commit
5acb883350
@ -1,3 +1,9 @@
|
||||
#include "common/endian.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
#include "engine/engine.h"
|
||||
#include "engine/savegame.h"
|
||||
|
||||
#include "engine/lua/ltask.h"
|
||||
#include "engine/lua/lauxlib.h"
|
||||
#include "engine/lua/lmem.h"
|
||||
@ -9,9 +15,6 @@
|
||||
#include "engine/lua/lstring.h"
|
||||
#include "engine/lua/lua.h"
|
||||
|
||||
#include "common/endian.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
RestoreCallback restoreCallbackPtr = NULL;
|
||||
|
||||
static void restoreObjectValue(TObject *object, RestoreSint32 restoreSint32, RestoreUint32 restoreUint32) {
|
||||
@ -251,32 +254,35 @@ void lua_Restore(RestoreStream restoreStream, RestoreSint32 restoreSint32, Resto
|
||||
maxStringsLength = restoreSint32();
|
||||
char *tempStringBuffer = (char *)luaM_malloc(maxStringsLength);
|
||||
|
||||
//printf("1: %d\n", g_engine->_savedState->getBufferPos());
|
||||
|
||||
int32 i;
|
||||
for (i = 0; i < arrayStringsCount; i++) {
|
||||
arraysObj->idObj.low = restoreSint32();
|
||||
arraysObj->idObj.hi = restoreSint32();
|
||||
int32 constIndex = restoreSint32();
|
||||
lua_Type tag = (lua_Type)restoreSint32();
|
||||
PointerId ptr;
|
||||
ptr.low = restoreUint32();
|
||||
ptr.hi = restoreUint32();
|
||||
|
||||
TaggedString *tempString;
|
||||
if (constIndex != -1) {
|
||||
TObject obj;
|
||||
restoreObjectValue(&obj, restoreSint32, restoreUint32);
|
||||
int32 length = restoreSint32();
|
||||
restoreStream(tempStringBuffer, length);
|
||||
tempString = luaS_newlstr(tempStringBuffer, length);
|
||||
tempString->u.s.globalval.ttype = tag;
|
||||
tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
|
||||
tempString->u.s.globalval = obj;
|
||||
} else {
|
||||
PointerId ptr;
|
||||
lua_Type tag = (lua_Type)restoreSint32();
|
||||
ptr.low = restoreUint32();
|
||||
ptr.hi = restoreUint32();
|
||||
if (tag == 0)
|
||||
tempString = luaS_createudata((void *)makePointerFromId(ptr), LUA_ANYTAG);
|
||||
else
|
||||
tempString = luaS_createudata((void *)makePointerFromId(ptr), tag);
|
||||
if (restoreCallbackPtr) {
|
||||
PointerId ptr = makeIdFromPointer(tempString->u.s.globalval.value.ts);
|
||||
ptr = restoreCallbackPtr(tempString->u.s.globalval.ttype, ptr, restoreSint32);
|
||||
tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
|
||||
PointerId ptr = makeIdFromPointer(tempString->u.d.v);
|
||||
ptr = restoreCallbackPtr(tempString->u.d.tag, ptr, restoreSint32);
|
||||
tempString->u.d.v = makePointerFromId(ptr);
|
||||
}
|
||||
}
|
||||
tempString->constindex = constIndex;
|
||||
@ -285,6 +291,8 @@ void lua_Restore(RestoreStream restoreStream, RestoreSint32 restoreSint32, Resto
|
||||
}
|
||||
luaM_free(tempStringBuffer);
|
||||
|
||||
//printf("2: %d\n", g_engine->_savedState->getBufferPos());
|
||||
|
||||
int32 l;
|
||||
Closure *tempClosure;
|
||||
arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayClosuresCount);
|
||||
|
@ -1,3 +1,9 @@
|
||||
#include "engine/savegame.h"
|
||||
#include "engine/engine.h"
|
||||
|
||||
#include "common/endian.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
#include "engine/lua/ltask.h"
|
||||
#include "engine/lua/lauxlib.h"
|
||||
#include "engine/lua/lmem.h"
|
||||
@ -9,9 +15,6 @@
|
||||
#include "engine/lua/lstring.h"
|
||||
#include "engine/lua/lua.h"
|
||||
|
||||
#include "common/endian.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
PointerId makeIdFromPointer(void *ptr) {
|
||||
PointerId pointer;
|
||||
|
||||
@ -218,6 +221,8 @@ void lua_Save(SaveStream saveStream, SaveSint32 saveSint32, SaveUint32 saveUint3
|
||||
// save maximum length for string
|
||||
saveSint32(maxStringLength);
|
||||
|
||||
//printf("1: %d\n", g_engine->_savedState->getBufferPos());
|
||||
|
||||
// save hash tables for strings and user data
|
||||
TaggedString *tempString;
|
||||
for (i = 0; i < NUM_HASHS; i++) {
|
||||
@ -234,16 +239,18 @@ void lua_Save(SaveStream saveStream, SaveSint32 saveSint32, SaveUint32 saveUint3
|
||||
saveStream(tempString->str, tempString->u.s.len);
|
||||
} else {
|
||||
if (saveCallbackPtr) {
|
||||
PointerId ptr = makeIdFromPointer(tempString->u.s.globalval.value.ts);
|
||||
ptr = saveCallbackPtr(tempString->u.s.globalval.ttype, ptr, saveSint32);
|
||||
tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
|
||||
PointerId ptr = makeIdFromPointer(tempString->u.d.v);
|
||||
ptr = saveCallbackPtr(tempString->u.d.tag, ptr, saveSint32);
|
||||
tempString->u.d.v = makePointerFromId(ptr);
|
||||
}
|
||||
saveObjectValue(&tempString->u.s.globalval, saveSint32, saveUint32);
|
||||
saveObjectValue((TObject *)&tempString->u.d, saveSint32, saveUint32);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//printf("2: %d\n", g_engine->_savedState->getBufferPos());
|
||||
|
||||
Closure *tempClosure = (Closure *)L->rootcl.next;
|
||||
while (tempClosure) {
|
||||
saveUint32(makeIdFromPointer(tempClosure).low);
|
||||
|
@ -94,7 +94,6 @@ void lua_close() {
|
||||
luaM_free(L->Mbuffer);
|
||||
luaM_free(L);
|
||||
L = NULL;
|
||||
lua_iolibclose();
|
||||
#ifdef LUA_DEBUG
|
||||
printf("total de blocos: %ld\n", numblocks);
|
||||
printf("total de memoria: %ld\n", totalmem);
|
||||
|
@ -166,6 +166,7 @@ void quit() {
|
||||
if (g_lua_initialized) {
|
||||
lua_removelibslists();
|
||||
lua_close();
|
||||
lua_iolibclose();
|
||||
g_lua_initialized = false;
|
||||
}
|
||||
if (g_registry) {
|
||||
|
@ -108,6 +108,13 @@ void SaveGame::endSection() {
|
||||
_currentSection = 0;
|
||||
}
|
||||
|
||||
uint32 SaveGame::getBufferPos() {
|
||||
if (_saving)
|
||||
return _sectionSize;
|
||||
else
|
||||
return _sectionPtr;
|
||||
}
|
||||
|
||||
void SaveGame::read(void *data, int size) {
|
||||
if (_saving)
|
||||
error("SaveGame::readBlock called when storing a savegame!");
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
|
||||
uint32 beginSection(uint32 sectionTag);
|
||||
void endSection();
|
||||
uint32 getBufferPos();
|
||||
void read(void *data, int size);
|
||||
void write(const void *data, int size);
|
||||
uint32 readLEUint32();
|
||||
|
Loading…
Reference in New Issue
Block a user