Fix issue with savemapstate/loadmapstate and gamearrays

git-svn-id: https://svn.eduke32.com/eduke32@6487 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2017-10-16 21:17:47 +00:00
parent c746b486b7
commit 3b9587cfa2
4 changed files with 20 additions and 6 deletions

View file

@ -66,10 +66,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// increase by 3, because atomic GRP adds 1, and Shareware adds 2 // increase by 3, because atomic GRP adds 1, and Shareware adds 2
#ifdef LUNATIC #ifdef LUNATIC
// Lunatic // Lunatic
# define BYTEVERSION_EDUKE32 315 # define BYTEVERSION_EDUKE32 318
#else #else
// Non-Lua build // Non-Lua build
# define BYTEVERSION_EDUKE32 315 # define BYTEVERSION_EDUKE32 318
#endif #endif
//#define BYTEVERSION_13 27 //#define BYTEVERSION_13 27

View file

@ -5516,6 +5516,8 @@ static void G_Cleanup(void)
// Bfree(MusicPtr); // Bfree(MusicPtr);
Gv_Clear();
hash_free(&h_gamevars); hash_free(&h_gamevars);
hash_free(&h_arrays); hash_free(&h_arrays);
hash_free(&h_labels); hash_free(&h_labels);

View file

@ -62,7 +62,7 @@ intptr_t *aplWeaponFlashColor[MAX_WEAPONS]; // Muzzle flash color
// counts to zero. Call this function as many times as needed. // counts to zero. Call this function as many times as needed.
// //
// Returns: old g_gameVarCount | (g_gameArrayCount<<16). // Returns: old g_gameVarCount | (g_gameArrayCount<<16).
static int Gv_Free(void) int Gv_Free(void)
{ {
for (bssize_t i=0; i<g_gameVarCount; ++i) for (bssize_t i=0; i<g_gameVarCount; ++i)
{ {
@ -93,7 +93,7 @@ static int Gv_Free(void)
// Calls Gv_Free() and in addition frees the labels of all game variables and // Calls Gv_Free() and in addition frees the labels of all game variables and
// arrays. // arrays.
// Only call this function ONCE... // Only call this function ONCE...
static void Gv_Clear(void) void Gv_Clear(void)
{ {
int gameVarCount = Gv_Free(); int gameVarCount = Gv_Free();
int const gameArrayCount = gameVarCount >> 16; int const gameArrayCount = gameVarCount >> 16;
@ -115,7 +115,7 @@ int Gv_ReadSave(int32_t kFile)
if (kread(kFile, tbuf, 12)!=12) goto corrupt; if (kread(kFile, tbuf, 12)!=12) goto corrupt;
if (Bmemcmp(tbuf, "BEG: EDuke32", 12)) { OSD_Printf("BEG ERR\n"); return 2; } if (Bmemcmp(tbuf, "BEG: EDuke32", 12)) { OSD_Printf("BEG ERR\n"); return 2; }
Bmemset(&savedstate,0,sizeof(savedstate)); Bmemset(savedstate, 0, sizeof(savedstate));
// AddLog("Reading gamevars from savegame"); // AddLog("Reading gamevars from savegame");
@ -218,6 +218,13 @@ int Gv_ReadSave(int32_t kFile)
if (kdfread(&g_mapInfo[i].savedstate->vars[j][0],sizeof(intptr_t), MAXSPRITES, kFile) != MAXSPRITES) goto corrupt; if (kdfread(&g_mapInfo[i].savedstate->vars[j][0],sizeof(intptr_t), MAXSPRITES, kFile) != MAXSPRITES) goto corrupt;
} }
} }
for (bssize_t j=0; j<g_gameArrayCount; j++)
if (aGameArrays[j].flags & GAMEARRAY_RESTORE)
{
g_mapInfo[i].savedstate->arrays[j] = (intptr_t *) Xaligned_alloc(16, Gv_GetArrayAllocSize(j));
if (kdfread(&g_mapInfo[i].savedstate->arrays[j][0], Gv_GetArrayAllocSize(j), 1, kFile) != (int32_t)Gv_GetArrayAllocSize(j)) goto corrupt;
}
} }
else else
{ {
@ -250,7 +257,7 @@ void Gv_WriteSave(FILE *fil)
{ {
char savedstate[MAXVOLUMES*MAXLEVELS]; char savedstate[MAXVOLUMES*MAXLEVELS];
Bmemset(&savedstate,0,sizeof(savedstate)); Bmemset(savedstate, 0, sizeof(savedstate));
// AddLog("Saving Game Vars to File"); // AddLog("Saving Game Vars to File");
fwrite("BEG: EDuke32", 12, 1, fil); fwrite("BEG: EDuke32", 12, 1, fil);
@ -312,6 +319,10 @@ void Gv_WriteSave(FILE *fil)
dfwrite(&g_mapInfo[i].savedstate->vars[j][0],sizeof(intptr_t), MAXSPRITES, fil); dfwrite(&g_mapInfo[i].savedstate->vars[j][0],sizeof(intptr_t), MAXSPRITES, fil);
} }
} }
for (bssize_t j=0; j<g_gameArrayCount; j++)
if (aGameArrays[j].flags & GAMEARRAY_RESTORE)
dfwrite(&g_mapInfo[i].savedstate->arrays[j][0], Gv_GetArrayAllocSize(j), 1, fil);
} }
fwrite("EOF: EDuke32", 12, 1, fil); fwrite("EOF: EDuke32", 12, 1, fil);

View file

@ -143,6 +143,7 @@ void Gv_RefreshPointers(void);
void Gv_ResetVars(void); void Gv_ResetVars(void);
int Gv_ReadSave(int32_t kFile); int Gv_ReadSave(int32_t kFile);
void Gv_WriteSave(FILE *fil); void Gv_WriteSave(FILE *fil);
void Gv_Clear(void);
#else #else
extern int32_t g_noResetVars; extern int32_t g_noResetVars;
extern LUNATIC_CB void (*A_ResetVars)(int32_t spriteNum); extern LUNATIC_CB void (*A_ResetVars)(int32_t spriteNum);