git-svn-id: https://svn.eduke32.com/eduke32@860 1a8010ca-5511-0410-912e-c29ae57300e0

This commit is contained in:
terminx 2008-07-16 21:21:18 +00:00
parent b367a392a7
commit f430f20201
3 changed files with 84 additions and 0 deletions

View file

@ -1030,6 +1030,7 @@ typedef struct {
char earthquaketime;
int lockclock;
int randomseed, global_random;
char scriptptrs[MAXSPRITES];
} mapstate_t;
typedef struct {

View file

@ -7742,6 +7742,7 @@ void savemapstate(mapstate_t *save)
if (save != NULL)
{
int i;
intptr_t j;
Bmemcpy(&save->numwalls,&numwalls,sizeof(numwalls));
Bmemcpy(&save->wall[0],&wall[0],sizeof(walltype)*MAXWALLS);
@ -7755,8 +7756,47 @@ void savemapstate(mapstate_t *save)
Bmemcpy(&save->headspritestat[0],&headspritestat[0],sizeof(headspritestat));
Bmemcpy(&save->prevspritestat[0],&prevspritestat[0],sizeof(prevspritestat));
Bmemcpy(&save->nextspritestat[0],&nextspritestat[0],sizeof(nextspritestat));
for (i=0;i<MAXSPRITES;i++)
{
save->scriptptrs[i] = 0;
if (actorscrptr[PN] == 0) continue;
j = (intptr_t)&script[0];
if (T2 >= j && T2 < (intptr_t)(&script[g_ScriptSize]))
{
save->scriptptrs[i] |= 1;
T2 -= j;
}
if (T5 >= j && T5 < (intptr_t)(&script[g_ScriptSize]))
{
save->scriptptrs[i] |= 2;
T5 -= j;
}
if (T6 >= j && T6 < (intptr_t)(&script[g_ScriptSize]))
{
save->scriptptrs[i] |= 4;
T6 -= j;
}
}
Bmemcpy(&save->hittype[0],&hittype[0],sizeof(actordata_t)*MAXSPRITES);
for (i=0;i<MAXSPRITES;i++)
{
if (actorscrptr[PN] == 0) continue;
j = (intptr_t)&script[0];
if (save->scriptptrs[i]&1)
T2 += j;
if (save->scriptptrs[i]&2)
T5 += j;
if (save->scriptptrs[i]&4)
T6 += j;
}
Bmemcpy(&save->numcyclers,&numcyclers,sizeof(numcyclers));
Bmemcpy(&save->cyclers[0][0],&cyclers[0][0],sizeof(cyclers));
Bmemcpy(&save->g_PlayerSpawnPoints[0],&g_PlayerSpawnPoints[0],sizeof(g_PlayerSpawnPoints));
@ -7797,6 +7837,7 @@ void restoremapstate(mapstate_t *save)
if (save != NULL)
{
int i, k, x;
intptr_t j;
pub = NUMPAGES;
pus = NUMPAGES;
@ -7816,6 +7857,14 @@ void restoremapstate(mapstate_t *save)
Bmemcpy(&nextspritestat[0],&save->nextspritestat[0],sizeof(nextspritestat));
Bmemcpy(&hittype[0],&save->hittype[0],sizeof(actordata_t)*MAXSPRITES);
for (i=0;i<MAXSPRITES;i++)
{
j = (intptr_t)(&script[0]);
if (save->scriptptrs[i]&1) T2 += j;
if (save->scriptptrs[i]&2) T5 += j;
if (save->scriptptrs[i]&4) T6 += j;
}
Bmemcpy(&numcyclers,&save->numcyclers,sizeof(numcyclers));
Bmemcpy(&cyclers[0][0],&save->cyclers[0][0],sizeof(cyclers));
Bmemcpy(&g_PlayerSpawnPoints[0],&save->g_PlayerSpawnPoints[0],sizeof(g_PlayerSpawnPoints));

View file

@ -100,6 +100,9 @@ int ReadGameVars(int fil)
{
int i;
intptr_t l;
char savedstate[MAXVOLUMES*MAXLEVELS];
Bmemset(&savedstate,0,sizeof(savedstate));
// AddLog("Reading gamevars from savegame");
@ -187,6 +190,24 @@ int ReadGameVars(int fil)
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
// AddLog(g_szBuf);
if (kdfread(&savedstate[0],sizeof(savedstate),1,fil) != 1) goto corrupt;
for (i=0;i<(MAXVOLUMES*MAXLEVELS);i++)
{
if (savedstate[i])
{
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;
}
else if (map[i].savedstate)
{
Bfree(map[i].savedstate);
map[i].savedstate = NULL;
}
}
if (kdfread(&l,sizeof(l),1,fil) != 1) goto corrupt;
if (kdfread(g_szBuf,l,1,fil) != 1) goto corrupt;
g_szBuf[l]=0;
@ -214,6 +235,9 @@ void SaveGameVars(FILE *fil)
{
int i;
intptr_t l;
char savedstate[MAXVOLUMES*MAXLEVELS];
Bmemset(&savedstate,0,sizeof(savedstate));
// AddLog("Saving Game Vars to File");
dfwrite(&iGameVarCount,sizeof(iGameVarCount),1,fil);
@ -272,6 +296,16 @@ void SaveGameVars(FILE *fil)
apScriptGameEvent[i] = (intptr_t *)l;
}
for (i=0;i<(MAXVOLUMES*MAXLEVELS);i++)
if (map[i].savedstate != NULL)
savedstate[i] = 1;
dfwrite(&savedstate[0],sizeof(savedstate),1,fil);
for (i=0;i<(MAXVOLUMES*MAXLEVELS);i++)
if (map[i].savedstate)
dfwrite(map[i].savedstate,sizeof(mapstate_t),1,fil);
Bsprintf(g_szBuf,"EOF: EDuke32");
l=strlen(g_szBuf);
dfwrite(&l,sizeof(l),1,fil);