[Scummvm-cvs-logs] CVS: residual/lua lua.h,1.7,1.8 lrestore.cpp,1.7,1.8 lsave.cpp,1.7,1.8
Erich Edgar Hoover
compholio at users.sourceforge.net
Sun Dec 25 18:37:03 CET 2005
- Previous message: [Scummvm-cvs-logs] CVS: residual savegame.cpp,NONE,1.1 savegame.h,NONE,1.1 lua.cpp,1.161,1.162 engine.cpp,1.97,1.98 engine.h,1.38,1.39 Makefile.common,1.20,1.21
- Next message: [Scummvm-cvs-logs] CVS: residual/imuse imuse.cpp,1.18,1.19 imuse.h,1.19,1.20
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/residual/lua
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8997/lua
Modified Files:
lua.h lrestore.cpp lsave.cpp
Log Message:
Centralized save/restore system, x86-64 fixes for lua_Save and lua_Restore (should be more portable now), stored screenshots for savegames
Index: lua.h
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lua.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- lua.h 20 Aug 2005 22:05:55 -0000 1.7
+++ lua.h 26 Dec 2005 02:35:59 -0000 1.8
@@ -28,14 +28,15 @@
typedef struct lua_State lua_State;
extern lua_State *lua_state;
-typedef void (*SaveRestoreFunc)(void *, int);
-typedef int (*SaveRestoreCallback)(int, int, SaveRestoreFunc);
+#include "savegame.h"
+
+typedef int (*SaveRestoreCallback)(int, int, SaveGame *);
extern SaveRestoreCallback saveCallback;
extern SaveRestoreCallback restoreCallback;
-void lua_Save(SaveRestoreFunc);
-void lua_Restore(SaveRestoreFunc);
+void lua_Save(SaveGame *);
+void lua_Restore(SaveGame *);
void lua_removelibslists(void);
Index: lrestore.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lrestore.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- lrestore.cpp 8 Apr 2005 22:29:06 -0000 1.7
+++ lrestore.cpp 26 Dec 2005 02:35:59 -0000 1.8
@@ -42,7 +42,7 @@
static void recreateObj(TObject *obj) {
if (obj->ttype == LUA_T_CPROTO) {
- long some = ((long)(obj->value.f)) >> 16;
+ unsigned long some = ((unsigned long)(obj->value.f)) >> 16;
luaL_libList *list = list_of_libs;
while (list != NULL) {
if (some == 0)
@@ -106,51 +106,68 @@
}
}
-void lua_Restore(SaveRestoreFunc restoreFunc) {
+void restoreObjectValue(lua_Type *objectType, void *objectValue, SaveGame *savedState) {
+ int length;
+ savedState->readBlock(objectType, sizeof(lua_Type));
+ savedState->readBlock(&length, sizeof(int));
+ savedState->readBlock(objectValue, length);
+}
+
+void lua_Restore(SaveGame *savedState) {
printf("lua_Restore() started.\n");
lua_close();
L = luaM_new(lua_State);
lua_resetglobals();
- restoreFunc(&arrayStringsCount, sizeof(int));
- restoreFunc(&arrayClosuresCount, sizeof(int));
- restoreFunc(&arrayHashTablesCount, sizeof(int));
- restoreFunc(&arrayProtoFuncsCount, sizeof(int));
+ savedState->beginSection('LUAS');
+ savedState->readBlock(&arrayStringsCount, sizeof(int));
+ savedState->readBlock(&arrayClosuresCount, sizeof(int));
+ savedState->readBlock(&arrayHashTablesCount, sizeof(int));
+ savedState->readBlock(&arrayProtoFuncsCount, sizeof(int));
int rootGlobalCount;
- restoreFunc(&rootGlobalCount, sizeof(int));
+ savedState->readBlock(&rootGlobalCount, sizeof(int));
arrayStrings = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayStringsCount);
ArrayIDObj *arraysObj = arrayStrings;
int maxStringsLength;
- restoreFunc(&maxStringsLength, sizeof(int));
+ savedState->readBlock(&maxStringsLength, sizeof(int));
char *tempStringBuffer = (char *)luaM_malloc(maxStringsLength);
int i;
for (i = 0; i < arrayStringsCount; i++) {
- restoreFunc(&arraysObj->idObj, sizeof(unsigned int));
int constIndex;
- restoreFunc(&constIndex, sizeof(int));
lua_Type tag;
- restoreFunc(&tag, sizeof(int));
void *value;
- restoreFunc(&value, sizeof(void *));
-
+
+ // Restore the string object
+ savedState->readBlock(&arraysObj->idObj, sizeof(TaggedString *));
+ // Restore the constant index
+ savedState->readBlock(&constIndex, sizeof(int));
+ // Restore the object value
+ restoreObjectValue(&tag, &value, savedState);
+
TaggedString *tempString;
if (constIndex != -1) {
long length;
- restoreFunc(&length, sizeof(long));
- restoreFunc(tempStringBuffer, length);
- tempString = luaS_newlstr(tempStringBuffer, length);
+ // Restore the string length
+ savedState->readBlock(&length, sizeof(long));
+ if (length == 0) {
+ tempString = luaS_newlstr("", 0);
+ } else {
+ // Restore the string value
+ savedState->readBlock(tempStringBuffer, length);
+ tempString = luaS_newlstr(tempStringBuffer, length);
+ }
tempString->u.s.globalval.ttype = tag;
- tempString->u.s.globalval.value.ts = (TaggedString *)value;
+ tempString->u.s.globalval.value.ts = (TaggedString *) value;
} else {
if (tag == 0)
tempString = luaS_createudata(value, LUA_ANYTAG);
else
tempString = luaS_createudata(value, tag);
if (restoreCallback != NULL) {
- tempString->u.s.globalval.value.ts = (TaggedString *)restoreCallback(tempString->u.s.globalval.ttype, (long)tempString->u.s.globalval.value.ts, restoreFunc);
+ tempString->u.s.globalval.value.ts = (TaggedString *)restoreCallback(tempString->u.s.globalval.ttype, (long)tempString->u.s.globalval.value.ts, savedState);
}
}
tempString->constindex = constIndex;
@@ -164,16 +181,15 @@
arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayClosuresCount);
arrayClosures = arraysObj;
for (i = 0; i < arrayClosuresCount; i++) {
- restoreFunc(&arraysObj->idObj, sizeof(unsigned int));
+ savedState->readBlock(&arraysObj->idObj, sizeof(Closure *));
int countElements;
- restoreFunc(&countElements, sizeof(int));
+ savedState->readBlock(&countElements, sizeof(int));
tempClosure = (Closure *)luaM_malloc((countElements * sizeof(TObject)) + sizeof(Closure));
luaO_insertlist(&L->rootcl, (GCnode *)tempClosure);
tempClosure->nelems = countElements;
for (l = 0; l <= tempClosure->nelems; l++) {
- restoreFunc(&tempClosure->consts[l].ttype, sizeof(lua_Type));
- restoreFunc(&tempClosure->consts[l].value, sizeof(Value));
+ restoreObjectValue(&tempClosure->consts[l].ttype, &tempClosure->consts[l].value, savedState);
}
arraysObj->object = tempClosure;
arraysObj++;
@@ -183,19 +199,17 @@
arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayHashTablesCount);
arrayHashTables = arraysObj;
for (i = 0; i < arrayHashTablesCount; i++) {
- restoreFunc(&arraysObj->idObj, sizeof(unsigned int));
+ savedState->readBlock(&arraysObj->idObj, sizeof(Hash *));
tempHash = luaM_new(Hash);
- restoreFunc(&tempHash->nhash, sizeof(int));
- restoreFunc(&tempHash->nuse, sizeof(int));
- restoreFunc(&tempHash->htag, sizeof(int));
+ savedState->readBlock(&tempHash->nhash, sizeof(unsigned int));
+ savedState->readBlock(&tempHash->nuse, sizeof(int));
+ savedState->readBlock(&tempHash->htag, sizeof(int));
tempHash->node = hashnodecreate(tempHash->nhash);
luaO_insertlist(&L->roottable, (GCnode *)tempHash);
for (l = 0; l < tempHash->nuse; l++) {
- restoreFunc(&tempHash->node[l].ref.ttype, sizeof(lua_Type));
- restoreFunc(&tempHash->node[l].ref.value, sizeof(Value));
- restoreFunc(&tempHash->node[l].val.ttype, sizeof(lua_Type));
- restoreFunc(&tempHash->node[l].val.value, sizeof(Value));
+ restoreObjectValue(&tempHash->node[l].ref.ttype, &tempHash->node[l].ref.value, savedState);
+ restoreObjectValue(&tempHash->node[l].val.ttype, &tempHash->node[l].val.value, savedState);
}
arraysObj->object = tempHash;
arraysObj++;
@@ -205,21 +219,20 @@
arrayProtoFuncs = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayProtoFuncsCount);
arraysObj = arrayProtoFuncs;
for (i = 0; i < arrayProtoFuncsCount; i++) {
- restoreFunc(&arraysObj->idObj, sizeof(unsigned int));
+ savedState->readBlock(&arraysObj->idObj, sizeof(TProtoFunc *));
tempProtoFunc = luaM_new(TProtoFunc);
luaO_insertlist(&L->rootproto, (GCnode *)tempProtoFunc);
- restoreFunc(&tempProtoFunc->fileName, sizeof(TaggedString *));
- restoreFunc(&tempProtoFunc->lineDefined, sizeof(int));
- restoreFunc(&tempProtoFunc->nconsts, sizeof(int));
+ savedState->readBlock(&tempProtoFunc->fileName, sizeof(TaggedString *));
+ savedState->readBlock(&tempProtoFunc->lineDefined, sizeof(unsigned int));
+ savedState->readBlock(&tempProtoFunc->nconsts, sizeof(unsigned int));
tempProtoFunc->consts = (TObject *)luaM_malloc(tempProtoFunc->nconsts * sizeof(TObject));
for (l = 0; l < tempProtoFunc->nconsts; l++) {
- restoreFunc(&tempProtoFunc->consts[l].ttype, sizeof(lua_Type));
- restoreFunc(&tempProtoFunc->consts[l].value, sizeof(Value));
+ restoreObjectValue(&tempProtoFunc->consts[l].ttype, &tempProtoFunc->consts[l].value, savedState);
}
int countVariables;
- restoreFunc(&countVariables, sizeof(int));
+ savedState->readBlock(&countVariables, sizeof(int));
if (countVariables != 0) {
tempProtoFunc->locvars = (LocVar *)luaM_malloc(countVariables * sizeof(LocVar));
} else {
@@ -227,14 +240,14 @@
}
for (l = 0; l < countVariables; l++) {
- restoreFunc(&tempProtoFunc->locvars[l].varname, sizeof(TaggedString *));
- restoreFunc(&tempProtoFunc->locvars[l].line, sizeof(int));
+ savedState->readBlock(&tempProtoFunc->locvars[l].varname, sizeof(TaggedString *));
+ savedState->readBlock(&tempProtoFunc->locvars[l].line, sizeof(int));
}
int codeSize;
- restoreFunc(&codeSize, sizeof(int));
+ savedState->readBlock(&codeSize, sizeof(int));
tempProtoFunc->code = (lua_Byte *)luaM_malloc(codeSize);
- restoreFunc(tempProtoFunc->code, codeSize);
+ savedState->readBlock(tempProtoFunc->code, codeSize);
arraysObj->object = tempProtoFunc;
arraysObj++;
}
@@ -305,7 +318,7 @@
TObject tempObj;
TaggedString *tempString = NULL;
tempObj.ttype = LUA_T_STRING;
- restoreFunc(&tempObj.value, sizeof(TaggedString *));
+ savedState->readBlock(&tempObj.value, sizeof(TaggedString *));
recreateObj(&tempObj);
tempString = (TaggedString *)tempObj.value.ts;
assert(tempString);
@@ -314,47 +327,44 @@
}
tempListString->head.next = NULL;
- restoreFunc(&L->errorim.ttype, sizeof(lua_Type));
- restoreFunc(&L->errorim.value, sizeof(Value));
+ restoreObjectValue(&L->errorim.ttype, &L->errorim.value, savedState);
recreateObj(&L->errorim);
- restoreFunc(&L->IMtable_size, sizeof(int));
+ savedState->readBlock(&L->IMtable_size, sizeof(int));
L->IMtable = (IM *)luaM_malloc(L->IMtable_size * sizeof(IM));
for (i = 0; i < L->IMtable_size; i++) {
IM *im = &L->IMtable[i];
for (l = 0; l < IM_N; l++) {
- restoreFunc(&im->int_method[l].ttype, sizeof(lua_Type));
- restoreFunc(&im->int_method[l].value, sizeof(Value));
+ restoreObjectValue(&im->int_method[l].ttype, &im->int_method[l].value, savedState);
recreateObj(&im->int_method[l]);
}
}
- restoreFunc(&L->last_tag, sizeof(int));
- restoreFunc(&L->refSize, sizeof(int));
+ savedState->readBlock(&L->last_tag, sizeof(int));
+ savedState->readBlock(&L->refSize, sizeof(int));
L->refArray = (ref *)luaM_malloc(L->refSize * sizeof(ref));
for (i = 0; i < L->refSize; i++) {
- restoreFunc(&L->refArray[i].o.ttype, sizeof(lua_Type));
- restoreFunc(&L->refArray[i].o.value, sizeof(Value));
+ restoreObjectValue(&L->refArray[i].o.ttype, &L->refArray[i].o.value, savedState);
recreateObj(&L->refArray[i].o);
- restoreFunc(&L->refArray[i].status, sizeof(Status));
+ savedState->readBlock(&L->refArray[i].status, sizeof(Status));
}
- restoreFunc(&L->GCthreshold, sizeof(unsigned long));
- restoreFunc(&L->nblocks, sizeof(unsigned long));
+ savedState->readBlock(&L->GCthreshold, sizeof(unsigned long));
+ savedState->readBlock(&L->nblocks, sizeof(unsigned long));
- restoreFunc(&L->Mbuffsize, sizeof(int));
+ savedState->readBlock(&L->Mbuffsize, sizeof(int));
L->Mbuffer = (char *)luaM_malloc(L->Mbuffsize);
- restoreFunc(L->Mbuffer, L->Mbuffsize);
+ savedState->readBlock(L->Mbuffer, L->Mbuffsize);
int MbaseOffset;
- restoreFunc(&MbaseOffset, sizeof(int));
+ savedState->readBlock(&MbaseOffset, sizeof(int));
L->Mbuffbase = MbaseOffset + L->Mbuffer;
- restoreFunc(&L->Mbuffnext, sizeof(int));
+ savedState->readBlock(&L->Mbuffnext, sizeof(int));
- restoreFunc(&globalTaskSerialId, sizeof(int));
+ savedState->readBlock(&globalTaskSerialId, sizeof(int));
int countTasks;
lua_Task *tempTask = NULL;
- restoreFunc(&countTasks, sizeof(int));
+ savedState->readBlock(&countTasks, sizeof(int));
lua_Task *prevTask = L->root_task;
for (l = 0; l < countTasks; l++) {
tempTask = luaM_new(lua_Task);
@@ -363,32 +373,31 @@
prevTask = tempTask;
int stackLastSize;
- restoreFunc(&stackLastSize, sizeof(int));
+ savedState->readBlock(&stackLastSize, sizeof(int));
tempTask->stack.stack = (TObject *)luaM_malloc(stackLastSize * sizeof(TObject));
tempTask->stack.last = tempTask->stack.stack + stackLastSize - 1;
int stackTopSize;
- restoreFunc(&stackTopSize, sizeof(int));
+ savedState->readBlock(&stackTopSize, sizeof(int));
tempTask->stack.top = tempTask->stack.stack + stackTopSize;
for (i = 0; i < stackTopSize; i++) {
- restoreFunc(&tempTask->stack.stack[i].ttype, sizeof(lua_Type));
- restoreFunc(&tempTask->stack.stack[i].value, sizeof(Value));
+ restoreObjectValue(&tempTask->stack.stack[i].ttype, &tempTask->stack.stack[i].value, savedState);
recreateObj(&tempTask->stack.stack[i]);
}
- restoreFunc(&tempTask->Cstack.base, sizeof(StkId));
- restoreFunc(&tempTask->Cstack.lua2C, sizeof(StkId));
- restoreFunc(&tempTask->Cstack.num, sizeof(int));
+ savedState->readBlock(&tempTask->Cstack.base, sizeof(StkId));
+ savedState->readBlock(&tempTask->Cstack.lua2C, sizeof(StkId));
+ savedState->readBlock(&tempTask->Cstack.num, sizeof(int));
- restoreFunc(&tempTask->numCblocks, sizeof(int));
+ savedState->readBlock(&tempTask->numCblocks, sizeof(int));
for (i = 0; i < tempTask->numCblocks; i++) {
- restoreFunc(&tempTask->Cblocks[i].base, sizeof(StkId));
- restoreFunc(&tempTask->Cblocks[i].lua2C, sizeof(StkId));
- restoreFunc(&tempTask->Cblocks[i].num, sizeof(int));
+ savedState->readBlock(&tempTask->Cblocks[i].base, sizeof(StkId));
+ savedState->readBlock(&tempTask->Cblocks[i].lua2C, sizeof(StkId));
+ savedState->readBlock(&tempTask->Cblocks[i].num, sizeof(int));
}
int pcOffset, taskCi;
- restoreFunc(&tempTask->base_ci_size, sizeof(int));
+ savedState->readBlock(&tempTask->base_ci_size, sizeof(int));
tempTask->base_ci = (CallInfo *)luaM_malloc(tempTask->base_ci_size * sizeof(CallInfo));
memset(tempTask->base_ci, 0, sizeof(CallInfo) * tempTask->base_ci_size);
CallInfo *tempCi = tempTask->base_ci;
@@ -396,35 +405,35 @@
for (i = 0; i < countCi; i++) {
TObject tempObj;
tempObj.ttype = LUA_T_CLOSURE;
- restoreFunc(&tempObj.value, sizeof(Closure *));
+ savedState->readBlock(&tempObj.value, sizeof(Closure *));
recreateObj(&tempObj);
tempCi->c = (Closure *)tempObj.value.cl;
tempObj.ttype = LUA_T_PROTO;
- restoreFunc(&tempObj.value, sizeof(TProtoFunc *));
+ savedState->readBlock(&tempObj.value, sizeof(TProtoFunc *));
recreateObj(&tempObj);
tempCi->tf = (TProtoFunc *)tempObj.value.tf;
- restoreFunc(&pcOffset, sizeof(int));
+ savedState->readBlock(&pcOffset, sizeof(int));
if (pcOffset != 0)
tempCi->pc = tempCi->tf->code + pcOffset;
else
tempCi->pc = NULL;
- restoreFunc(&tempCi->base, sizeof(StkId));
- restoreFunc(&tempCi->nResults, sizeof(int));
+ savedState->readBlock(&tempCi->base, sizeof(StkId));
+ savedState->readBlock(&tempCi->nResults, sizeof(int));
tempCi++;
}
- restoreFunc(&taskCi, sizeof(int));
+ savedState->readBlock(&taskCi, sizeof(int));
tempTask->ci = tempTask->base_ci + taskCi;
tempTask->end_ci = tempTask->base_ci + countCi;
int Mbasepos;
- restoreFunc(&Mbasepos, sizeof(int));
+ savedState->readBlock(&Mbasepos, sizeof(int));
tempTask->Mbuffbase = Mbasepos + tempTask->Mbuffer;
- restoreFunc(&tempTask->Mbuffnext, sizeof(int));
+ savedState->readBlock(&tempTask->Mbuffnext, sizeof(int));
- restoreFunc(&tempTask->Tstate, sizeof(TaskState));
- restoreFunc(&tempTask->id, sizeof(int));
+ savedState->readBlock(&tempTask->Tstate, sizeof(TaskState));
+ savedState->readBlock(&tempTask->id, sizeof(int));
}
L->last_task = tempTask;
@@ -442,5 +451,6 @@
arrayProtoFuncs = NULL;
arrayStrings = NULL;
+ savedState->endSection();
printf("lua_Restore() finished.\n");
}
Index: lsave.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lsave.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- lsave.cpp 8 Apr 2005 22:29:06 -0000 1.7
+++ lsave.cpp 26 Dec 2005 02:35:59 -0000 1.8
@@ -14,16 +14,22 @@
SaveRestoreCallback saveCallback = NULL;
-static void saveObjectValue(TObject *object, SaveRestoreFunc saveFunc) {
- saveFunc(&object->ttype, sizeof(lua_Type));
+static void saveObjectValue(TObject *object, SaveGame *savedState) {
+ int length;
+
+ // Note: Now stores the length of the object value
+ // ("unsigned int" and "Value" are different lengths)
+ savedState->writeBlock(&object->ttype, sizeof(lua_Type));
if (object->ttype == LUA_T_CPROTO) {
luaL_libList *list = list_of_libs;
- unsigned int idObj = 0;
+ unsigned long idObj = 0;
while (list != NULL) {
for (int l = 0; l < list->number; l++) {
if (list->list[l].func == object->value.f) {
idObj = (idObj << 16) | l;
- saveFunc(&idObj, sizeof(unsigned int));
+ length = sizeof(unsigned long);
+ savedState->writeBlock(&length, sizeof(int));
+ savedState->writeBlock(&idObj, length);
return;
}
}
@@ -32,7 +38,9 @@
}
assert(0);
} else {
- saveFunc(&object->value, sizeof(Value));
+ length = sizeof(Value);
+ savedState->writeBlock(&length, sizeof(int));
+ savedState->writeBlock(&object->value, length);
}
}
@@ -52,9 +60,10 @@
2, 3, 2, 3, 2, 3, 2, 1, 1, 3, 2, 2, 2, 2, 3, 2, 1, 1
};
-void lua_Save(SaveRestoreFunc saveFunc) {
+void lua_Save(SaveGame *savedState) {
printf("lua_Save() started.\n");
+ savedState->beginSection('LUAS');
lua_collectgarbage(0);
int i, l;
int countElements = 0;
@@ -73,7 +82,7 @@
}
}
- saveFunc(&countElements, sizeof(int));
+ savedState->writeBlock(&countElements, sizeof(int));
countElements = 0;
GCnode *tempNode;
@@ -82,7 +91,7 @@
countElements++;
tempNode = tempNode->next;
}
- saveFunc(&countElements, sizeof(int));
+ savedState->writeBlock(&countElements, sizeof(int));
countElements = 0;
tempNode = L->roottable.next;
@@ -90,7 +99,7 @@
countElements++;
tempNode = tempNode->next;
}
- saveFunc(&countElements, sizeof(int));
+ savedState->writeBlock(&countElements, sizeof(int));
countElements = 0;
tempNode = L->rootproto.next;
@@ -98,7 +107,7 @@
countElements++;
tempNode = tempNode->next;
}
- saveFunc(&countElements, sizeof(int));
+ savedState->writeBlock(&countElements, sizeof(int));
countElements = 0;
tempNode = L->rootglobal.next;
@@ -106,9 +115,9 @@
countElements++;
tempNode = tempNode->next;
}
- saveFunc(&countElements, sizeof(int));
+ savedState->writeBlock(&countElements, sizeof(int));
- saveFunc(&maxStringLength, sizeof(int));
+ savedState->writeBlock(&maxStringLength, sizeof(int));
TaggedString *tempString;
for (i = 0; i < NUM_HASHS; i++) {
@@ -116,17 +125,24 @@
for (l = 0; l < tempStringTable->size; l++) {
if ((tempStringTable->hash[l] != NULL) && (tempStringTable->hash[l] != &EMPTY)) {
tempString = tempStringTable->hash[l];
- saveFunc(&tempString, sizeof(TaggedString *));
- saveFunc(&tempString->constindex, sizeof(int));
+ // Save the string object
+ savedState->writeBlock(&tempString, sizeof(TaggedString *));
+ // Save the constant index
+ savedState->writeBlock(&tempString->constindex, sizeof(int));
if (tempString->constindex != -1) {
- saveObjectValue(&tempString->u.s.globalval, saveFunc);
- saveFunc(&tempString->u.s.len, sizeof(long));
- saveFunc(tempString->str, tempString->u.s.len);
+ // Save the object value
+ saveObjectValue(&tempString->u.s.globalval, savedState);
+ // Save the string length
+ savedState->writeBlock(&tempString->u.s.len, sizeof(long));
+ // Save the string value
+ if (tempString->u.s.len != 0)
+ savedState->writeBlock(tempString->str, tempString->u.s.len);
} else {
if (saveCallback != NULL) {
- tempString->u.s.globalval.value.ts = (TaggedString *)saveCallback(tempString->u.s.globalval.ttype, (long)tempString->u.s.globalval.value.ts, saveFunc);
+ tempString->u.s.globalval.value.ts = (TaggedString *)saveCallback(tempString->u.s.globalval.ttype, (long)tempString->u.s.globalval.value.ts, savedState);
}
- saveObjectValue(&tempString->u.s.globalval, saveFunc);
+ // Save the object value
+ saveObjectValue(&tempString->u.s.globalval, savedState);
}
}
}
@@ -134,18 +150,18 @@
Closure *tempClosure = (Closure *)L->rootcl.next;
while (tempClosure != NULL) {
- saveFunc(&tempClosure, sizeof(Closure *));
- saveFunc(&tempClosure->nelems, sizeof(int));
+ savedState->writeBlock(&tempClosure, sizeof(Closure *));
+ savedState->writeBlock(&tempClosure->nelems, sizeof(int));
for(i = 0; i <= tempClosure->nelems; i++) {
- saveObjectValue(&tempClosure->consts[i], saveFunc);
+ saveObjectValue(&tempClosure->consts[i], savedState);
}
tempClosure = (Closure *)tempClosure->head.next;
}
Hash *tempHash = (Hash *)L->roottable.next;
while (tempHash != NULL) {
- saveFunc(&tempHash, sizeof(Hash *));
- saveFunc(&tempHash->nhash, sizeof(unsigned int));
+ savedState->writeBlock(&tempHash, sizeof(Hash *));
+ savedState->writeBlock(&tempHash->nhash, sizeof(unsigned int));
int countUsedHash = 0;
for(i = 0; i < tempHash->nhash; i++) {
Node *newNode = &tempHash->node[i];
@@ -153,13 +169,13 @@
countUsedHash++;
}
}
- saveFunc(&countUsedHash, sizeof(int));
- saveFunc(&tempHash->htag, sizeof(int));
+ savedState->writeBlock(&countUsedHash, sizeof(int));
+ savedState->writeBlock(&tempHash->htag, sizeof(int));
for (i = 0; i < tempHash->nhash; i++) {
Node *newNode = &tempHash->node[i];
if ((newNode->val.ttype != LUA_T_NIL) && (newNode->ref.ttype != LUA_T_NIL)) {
- saveObjectValue(&tempHash->node[i].ref, saveFunc);
- saveObjectValue(&tempHash->node[i].val, saveFunc);
+ saveObjectValue(&tempHash->node[i].ref, savedState);
+ saveObjectValue(&tempHash->node[i].val, savedState);
}
}
tempHash = (Hash *)tempHash->head.next;
@@ -167,22 +183,22 @@
TProtoFunc *tempProtoFunc = (TProtoFunc *)L->rootproto.next;
while (tempProtoFunc != NULL) {
- saveFunc(&tempProtoFunc, sizeof(TProtoFunc *));
- saveFunc(&tempProtoFunc->fileName, sizeof(TaggedString *));
- saveFunc(&tempProtoFunc->lineDefined, sizeof(unsigned int));
- saveFunc(&tempProtoFunc->nconsts, sizeof(unsigned int));
+ savedState->writeBlock(&tempProtoFunc, sizeof(TProtoFunc *));
+ savedState->writeBlock(&tempProtoFunc->fileName, sizeof(TaggedString *));
+ savedState->writeBlock(&tempProtoFunc->lineDefined, sizeof(unsigned int));
+ savedState->writeBlock(&tempProtoFunc->nconsts, sizeof(unsigned int));
for (i = 0; i < tempProtoFunc->nconsts; i++) {
- saveObjectValue(&tempProtoFunc->consts[i], saveFunc);
+ saveObjectValue(&tempProtoFunc->consts[i], savedState);
}
int countVariables = 0;
if (tempProtoFunc->locvars) {
for (; tempProtoFunc->locvars[countVariables++].line != -1;) { }
}
- saveFunc(&countVariables, sizeof(int));
+ savedState->writeBlock(&countVariables, sizeof(int));
for (i = 0; i < countVariables; i++) {
- saveFunc(&tempProtoFunc->locvars[i].varname, sizeof(TaggedString *));
- saveFunc(&tempProtoFunc->locvars[i].line, sizeof(int));
+ savedState->writeBlock(&tempProtoFunc->locvars[i].varname, sizeof(TaggedString *));
+ savedState->writeBlock(&tempProtoFunc->locvars[i].line, sizeof(int));
}
Byte *codePtr = tempProtoFunc->code + 2;
@@ -193,45 +209,45 @@
tmpPtr += opcodeSizeTable[opcodeId];
} while (opcodeId != ENDCODE);
int codeSize = (tmpPtr - codePtr) + 2;
- saveFunc(&codeSize, sizeof(int));
- saveFunc(tempProtoFunc->code, codeSize);
+ savedState->writeBlock(&codeSize, sizeof(int));
+ savedState->writeBlock(tempProtoFunc->code, codeSize);
tempProtoFunc = (TProtoFunc *)tempProtoFunc->head.next;
}
tempString = (TaggedString *)L->rootglobal.next;
while (tempString != NULL) {
- saveFunc(&tempString, sizeof(TaggedString *));
+ savedState->writeBlock(&tempString, sizeof(TaggedString *));
tempString = (TaggedString *)tempString->head.next;
}
- saveObjectValue(&L->errorim, saveFunc);
+ saveObjectValue(&L->errorim, savedState);
IM *tempIm = L->IMtable;
- saveFunc(&L->IMtable_size, sizeof(int));
+ savedState->writeBlock(&L->IMtable_size, sizeof(int));
for (i = 0; i < L->IMtable_size; i++) {
for (l = 0; l < IM_N; l++) {
- saveObjectValue(&tempIm->int_method[l], saveFunc);
+ saveObjectValue(&tempIm->int_method[l], savedState);
}
tempIm++;
}
- saveFunc(&L->last_tag, sizeof(int));
- saveFunc(&L->refSize, sizeof(int));
+ savedState->writeBlock(&L->last_tag, sizeof(int));
+ savedState->writeBlock(&L->refSize, sizeof(int));
for (i = 0 ; i < L->refSize; i++) {
- saveObjectValue(&L->refArray[i].o, saveFunc);
- saveFunc(&L->refArray[i].status, sizeof(Status));
+ saveObjectValue(&L->refArray[i].o, savedState);
+ savedState->writeBlock(&L->refArray[i].status, sizeof(Status));
}
- saveFunc(&L->GCthreshold, sizeof(unsigned long));
- saveFunc(&L->nblocks, sizeof(unsigned long));
+ savedState->writeBlock(&L->GCthreshold, sizeof(unsigned long));
+ savedState->writeBlock(&L->nblocks, sizeof(unsigned long));
- saveFunc(&L->Mbuffsize, sizeof(int));
- saveFunc(L->Mbuffer, L->Mbuffsize);
+ savedState->writeBlock(&L->Mbuffsize, sizeof(int));
+ savedState->writeBlock(L->Mbuffer, L->Mbuffsize);
int MbaseOffset = L->Mbuffbase - L->Mbuffer;
- saveFunc(&MbaseOffset, sizeof(int));
- saveFunc(&L->Mbuffnext, sizeof(int));
+ savedState->writeBlock(&MbaseOffset, sizeof(int));
+ savedState->writeBlock(&L->Mbuffnext, sizeof(int));
- saveFunc(&globalTaskSerialId, sizeof(int));
+ savedState->writeBlock(&globalTaskSerialId, sizeof(int));
int countTasks = 0;
lua_Task *tempTask = L->root_task->next;
@@ -239,60 +255,61 @@
countTasks++;
tempTask = tempTask->next;
}
- saveFunc(&countTasks, sizeof(int));
+ savedState->writeBlock(&countTasks, sizeof(int));
tempTask = L->root_task->next;
while (tempTask != NULL) {
int stackLastSize = (tempTask->stack.last - tempTask->stack.stack) + 1;
- saveFunc(&stackLastSize, sizeof(int));
+ savedState->writeBlock(&stackLastSize, sizeof(int));
int stackTopSize = tempTask->stack.top - tempTask->stack.stack;
- saveFunc(&stackTopSize, sizeof(int));
+ savedState->writeBlock(&stackTopSize, sizeof(int));
for (i = 0; i < stackTopSize; i++) {
- saveObjectValue(&tempTask->stack.stack[i], saveFunc);
+ saveObjectValue(&tempTask->stack.stack[i], savedState);
}
- saveFunc(&tempTask->Cstack.base, sizeof(StkId));
- saveFunc(&tempTask->Cstack.lua2C, sizeof(StkId));
- saveFunc(&tempTask->Cstack.num, sizeof(int));
+ savedState->writeBlock(&tempTask->Cstack.base, sizeof(StkId));
+ savedState->writeBlock(&tempTask->Cstack.lua2C, sizeof(StkId));
+ savedState->writeBlock(&tempTask->Cstack.num, sizeof(int));
- saveFunc(&tempTask->numCblocks, sizeof(int));
+ savedState->writeBlock(&tempTask->numCblocks, sizeof(int));
for (i = 0; i < tempTask->numCblocks; i++) {
- saveFunc(&tempTask->Cblocks[i].base, sizeof(StkId));
- saveFunc(&tempTask->Cblocks[i].lua2C, sizeof(StkId));
- saveFunc(&tempTask->Cblocks[i].num, sizeof(int));
+ savedState->writeBlock(&tempTask->Cblocks[i].base, sizeof(StkId));
+ savedState->writeBlock(&tempTask->Cblocks[i].lua2C, sizeof(StkId));
+ savedState->writeBlock(&tempTask->Cblocks[i].num, sizeof(int));
}
int pcOffset, taskCi = -1;
- saveFunc(&tempTask->base_ci_size, sizeof(int));
+ savedState->writeBlock(&tempTask->base_ci_size, sizeof(int));
assert(tempTask->base_ci);
CallInfo *tempCi = tempTask->base_ci;
int countCi = tempTask->base_ci_size / sizeof(CallInfo);
for (i = 0; i < countCi; i++) {
- saveFunc(&tempCi->c, sizeof(Closure *));
- saveFunc(&tempCi->tf, sizeof(TProtoFunc *));
+ savedState->writeBlock(&tempCi->c, sizeof(Closure *));
+ savedState->writeBlock(&tempCi->tf, sizeof(TProtoFunc *));
if ((tempCi->pc != NULL) && (tempTask->ci->tf != NULL))
pcOffset = tempCi->pc - tempCi->tf->code;
else
pcOffset = 0;
- saveFunc(&pcOffset, sizeof(int));
- saveFunc(&tempCi->base, sizeof(StkId));
- saveFunc(&tempCi->nResults, sizeof(int));
+ savedState->writeBlock(&pcOffset, sizeof(int));
+ savedState->writeBlock(&tempCi->base, sizeof(StkId));
+ savedState->writeBlock(&tempCi->nResults, sizeof(int));
if (tempCi == tempTask->ci)
taskCi = i;
tempCi++;
}
assert(taskCi != -1);
- saveFunc(&taskCi, sizeof(int));
+ savedState->writeBlock(&taskCi, sizeof(int));
MbaseOffset = tempTask->Mbuffbase - tempTask->Mbuffer;
- saveFunc(&MbaseOffset, sizeof(int));
- saveFunc(&tempTask->Mbuffnext, sizeof(int));
+ savedState->writeBlock(&MbaseOffset, sizeof(int));
+ savedState->writeBlock(&tempTask->Mbuffnext, sizeof(int));
- saveFunc(&tempTask->Tstate, sizeof(TaskState));
- saveFunc(&tempTask->id, sizeof(int));
+ savedState->writeBlock(&tempTask->Tstate, sizeof(TaskState));
+ savedState->writeBlock(&tempTask->id, sizeof(int));
tempTask = tempTask->next;
}
+ savedState->endSection();
printf("lua_Save() finished.\n");
}
- Previous message: [Scummvm-cvs-logs] CVS: residual savegame.cpp,NONE,1.1 savegame.h,NONE,1.1 lua.cpp,1.161,1.162 engine.cpp,1.97,1.98 engine.h,1.38,1.39 Makefile.common,1.20,1.21
- Next message: [Scummvm-cvs-logs] CVS: residual/imuse imuse.cpp,1.18,1.19 imuse.h,1.19,1.20
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list