Gamevars in savestates (in savegames)

Still needs debugging


git-svn-id: https://svn.eduke32.com/eduke32@862 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-07-18 02:46:24 +00:00
parent b909597593
commit 244a0c1a5e
6 changed files with 103 additions and 8 deletions

View file

@ -831,6 +831,7 @@ enum gamevarflags {
GAMEVAR_FLAG_SYNCCHECK = 16384, // check event sync when translating
GAMEVAR_FLAG_SHORTPTR = 32768, // plValue is a pointer to a short
GAMEVAR_FLAG_CHARPTR = 65536, // plValue is a pointer to a char
GAMEVAR_FLAG_NORESET = 131072, // var values are not reset when restoring map state
};
enum gamearrayflags {
@ -1031,6 +1032,7 @@ typedef struct {
int lockclock;
int randomseed, global_random;
char scriptptrs[MAXSPRITES];
intptr_t *vars[MAXGAMEVARS];
} mapstate_t;
typedef struct {

View file

@ -246,4 +246,6 @@ extern int getteampal(int team);
extern void se40code(int x,int y,int z,int a,int h, int smoothratio);
extern void FreeMapState(int mapnum);
#endif // __funct_h__

View file

@ -9560,7 +9560,7 @@ static void freeconmem(void)
if (map[i].musicfn1 != NULL)
Bfree(map[i].musicfn1);
if (map[i].savedstate != NULL)
Bfree(map[i].savedstate);
FreeMapState(i);
}
for (i=MAXQUOTES-1;i>=0;i--)

View file

@ -7828,10 +7828,31 @@ void savemapstate(mapstate_t *save)
Bmemcpy(&save->lockclock,&lockclock,sizeof(lockclock));
Bmemcpy(&save->randomseed,&randomseed,sizeof(randomseed));
Bmemcpy(&save->global_random,&global_random,sizeof(global_random));
for (i = 0; i<iGameVarCount;i++)
{
if (aGameVars[i].dwFlags & GAMEVAR_FLAG_NORESET) continue;
if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERPLAYER)
{
if (!save->vars[i])
save->vars[i] = Bcalloc(MAXPLAYERS,sizeof(intptr_t));
Bmemcpy(&save->vars[i][0],&aGameVars[i].plValues[0],sizeof(intptr_t) * MAXPLAYERS);
}
else if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR)
{
if (!save->vars[i])
save->vars[i] = Bcalloc(MAXSPRITES,sizeof(intptr_t));
Bmemcpy(&save->vars[i][0],&aGameVars[i].plValues[0],sizeof(intptr_t) * MAXSPRITES);
}
else save->vars[i] = (intptr_t *)aGameVars[i].lValue;
}
ototalclock = totalclock;
}
}
extern void ResetPointerVars(void);
void restoremapstate(mapstate_t *save)
{
if (save != NULL)
@ -7896,6 +7917,18 @@ void restoremapstate(mapstate_t *save)
Bmemcpy(&randomseed,&save->randomseed,sizeof(randomseed));
Bmemcpy(&global_random,&save->global_random,sizeof(global_random));
for (i = 0; i<iGameVarCount;i++)
{
if (aGameVars[i].dwFlags & GAMEVAR_FLAG_NORESET) continue;
if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERPLAYER)
Bmemcpy(&aGameVars[i].plValues[0],&save->vars[i][0],sizeof(intptr_t) * MAXPLAYERS);
else if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR)
Bmemcpy(&aGameVars[i].plValues[0],&save->vars[i][0],sizeof(intptr_t) * MAXSPRITES);
else aGameVars[i].lValue = (intptr_t)save->vars[i];
}
ResetPointerVars();
if (g_player[myconnectindex].ps->over_shoulder_on != 0)
{
cameradist = 0;

View file

@ -28,8 +28,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern int g_i,g_p;
static void ResetPointerVars(void);
void ResetPointerVars(void);
extern void FreeMapState(int mapnum);
static void FreeGameVars(void) /* called from ReadGameVars() and ResetGameVars() */
{
// call this function as many times as needed.
@ -98,7 +98,7 @@ static void ClearGameVars(void)
int ReadGameVars(int fil)
{
int i;
int i, j;
intptr_t l;
char savedstate[MAXVOLUMES*MAXLEVELS];
@ -200,11 +200,26 @@ int ReadGameVars(int fil)
if (map[i].savedstate == NULL)
map[i].savedstate = Bcalloc(1,sizeof(mapstate_t));
if (kdfread(map[i].savedstate,sizeof(mapstate_t),1,fil) != sizeof(mapstate_t)) goto corrupt;
for (j=0;j<iGameVarCount;j++)
{
if (aGameVars[j].dwFlags & GAMEVAR_FLAG_NORESET) continue;
if (aGameVars[j].dwFlags & GAMEVAR_FLAG_PERPLAYER)
{
if (!map[i].savedstate->vars[j])
map[i].savedstate->vars[j] = Bcalloc(MAXPLAYERS,sizeof(intptr_t));
if (kdfread(&map[i].savedstate->vars[j][0],sizeof(intptr_t) * MAXPLAYERS, 1, fil) != 1) goto corrupt;
}
else if (aGameVars[j].dwFlags & GAMEVAR_FLAG_PERACTOR)
{
if (!map[i].savedstate->vars[j])
map[i].savedstate->vars[j] = Bcalloc(MAXSPRITES,sizeof(intptr_t));
if (kdfread(&map[i].savedstate->vars[j][0],sizeof(intptr_t), MAXSPRITES, fil) != MAXSPRITES) goto corrupt;
}
}
}
else if (map[i].savedstate)
{
Bfree(map[i].savedstate);
map[i].savedstate = NULL;
FreeMapState(i);
}
}
@ -233,7 +248,7 @@ corrupt:
void SaveGameVars(FILE *fil)
{
int i;
int i, j;
intptr_t l;
char savedstate[MAXVOLUMES*MAXLEVELS];
@ -304,7 +319,21 @@ void SaveGameVars(FILE *fil)
for (i=0;i<(MAXVOLUMES*MAXLEVELS);i++)
if (map[i].savedstate)
{
dfwrite(map[i].savedstate,sizeof(mapstate_t),1,fil);
for (j=0;j<iGameVarCount;j++)
{
if (aGameVars[j].dwFlags & GAMEVAR_FLAG_NORESET) continue;
if (aGameVars[j].dwFlags & GAMEVAR_FLAG_PERPLAYER)
{
dfwrite(&map[i].savedstate->vars[j][0],sizeof(intptr_t) * MAXPLAYERS, 1, fil);
}
else if (aGameVars[j].dwFlags & GAMEVAR_FLAG_PERACTOR)
{
dfwrite(&map[i].savedstate->vars[j][0],sizeof(intptr_t) * MAXSPRITES, 1, fil);
}
}
}
Bsprintf(g_szBuf,"EOF: EDuke32");
l=strlen(g_szBuf);
@ -1425,7 +1454,7 @@ void InitGameVarPointers(void)
}
}
static void ResetPointerVars(void)
void ResetPointerVars(void)
{
aGameVars[GetGameID("RESPAWN_MONSTERS")].lValue = (intptr_t)&ud.respawn_monsters;
aGameVars[GetGameID("RESPAWN_ITEMS")].lValue = (intptr_t)&ud.respawn_items;

View file

@ -1236,6 +1236,13 @@ void newgame(int vn,int ln,int sk)
ResetSystemDefaults();
for (i=0;i<(MAXVOLUMES*MAXLEVELS);i++)
if (map[i].savedstate)
{
Bfree(map[i].savedstate);
map[i].savedstate = NULL;
}
if (ud.m_coop != 1)
{
for (i=0;i<MAX_WEAPONS;i++)
@ -1854,3 +1861,25 @@ int enterlevel(int g)
initprintf("E%dL%d: %s\n",ud.volume_number+1,ud.level_number+1,map[(ud.volume_number*MAXLEVELS)+ud.level_number].name);
return 0;
}
void FreeMapState(int mapnum)
{
int j;
for (j=0;j<iGameVarCount;j++)
{
if (aGameVars[j].dwFlags & GAMEVAR_FLAG_NORESET) continue;
if (aGameVars[j].dwFlags & GAMEVAR_FLAG_PERPLAYER)
{
if (map[mapnum].savedstate->vars[j])
Bfree(map[mapnum].savedstate->vars[j]);
}
else if (aGameVars[j].dwFlags & GAMEVAR_FLAG_PERACTOR)
{
if (map[mapnum].savedstate->vars[j])
Bfree(map[mapnum].savedstate->vars[j]);
}
}
Bfree(map[mapnum].savedstate);
map[mapnum].savedstate = NULL;
}