From f430f2020117ff91440042b229bd23196456b20b Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 16 Jul 2008 21:21:18 +0000 Subject: [PATCH] git-svn-id: https://svn.eduke32.com/eduke32@860 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/duke3d.h | 1 + polymer/eduke32/source/gameexec.c | 49 +++++++++++++++++++++++++++++++ polymer/eduke32/source/gamevars.c | 34 +++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index 1eeb72325..2baad8676 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -1030,6 +1030,7 @@ typedef struct { char earthquaketime; int lockclock; int randomseed, global_random; + char scriptptrs[MAXSPRITES]; } mapstate_t; typedef struct { diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index b22ef95dd..c9372a502 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -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;iscriptptrs[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;iscriptptrs[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;iscriptptrs[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)); diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index b5aceb6a7..07d81e718 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -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);