diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index f60cb5f17..9ab06b19b 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "duke3d.h" #include "gamedef.h" #include "gameexec.h" +#include "savegame.h" #include "osd.h" @@ -1126,27 +1127,9 @@ static int32_t C_SetScriptSize(int32_t newsize) else scriptptrs[i] = 0; } - for (i=MAXTILES-1; i>=0; i--) - { - if (actorscrptr[i]) - { - j = (intptr_t)actorscrptr[i]-(intptr_t)&script[0]; - actorscrptr[i] = (intptr_t *)j; - } - - if (actorLoadEventScrptr[i]) - { - j = (intptr_t)actorLoadEventScrptr[i]-(intptr_t)&script[0]; - actorLoadEventScrptr[i] = (intptr_t *)j; - } - } - - for (i=MAXGAMEEVENTS-1; i>=0; i--) - if (apScriptGameEvent[i]) - { - j = (intptr_t)apScriptGameEvent[i]-(intptr_t)&script[0]; - apScriptGameEvent[i] = (intptr_t *)j; - } + G_Util_PtrToIdx(actorscrptr, MAXTILES, script, P2I_FWD_NON0); + G_Util_PtrToIdx(actorLoadEventScrptr, MAXTILES, script, P2I_FWD_NON0); + G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_FWD_NON0); initprintf("Resizing code buffer to %d*%d bytes\n",newsize, (int32_t)sizeof(intptr_t)); @@ -1194,7 +1177,7 @@ static int32_t C_SetScriptSize(int32_t newsize) { if (labelcode[i] && labeltype[i] != LABEL_DEFINE) { - j = (intptr_t)labelcode[i]+(intptr_t)&script[0]; + j = (intptr_t)labelcode[i]+(intptr_t)&script[0]; labelcode[i] = j; } } @@ -1202,30 +1185,13 @@ static int32_t C_SetScriptSize(int32_t newsize) for (i=(((newsize>=osize)?osize:newsize))-1; i>=0; i--) if (scriptptrs[i]) { - j = (intptr_t)script[i]+(intptr_t)&script[0]; + j = (intptr_t)script[i]+(intptr_t)&script[0]; script[i] = j; } - for (i=MAXTILES-1; i>=0; i--) - { - if (actorscrptr[i]) - { - j = (intptr_t)actorscrptr[i]+(intptr_t)&script[0]; - actorscrptr[i] = (intptr_t *)j; - } - if (actorLoadEventScrptr[i]) - { - j = (intptr_t)actorLoadEventScrptr[i]+(intptr_t)&script[0]; - actorLoadEventScrptr[i] = (intptr_t *)j; - } - } - - for (i=MAXGAMEEVENTS-1; i>=0; i--) - if (apScriptGameEvent[i]) - { - j = (intptr_t)apScriptGameEvent[i]+(intptr_t)&script[0]; - apScriptGameEvent[i] = (intptr_t *)j; - } + G_Util_PtrToIdx(actorscrptr, MAXTILES, script, P2I_BACK_NON0); + G_Util_PtrToIdx(actorLoadEventScrptr, MAXTILES, script, P2I_BACK_NON0); + G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_BACK_NON0); Bfree(scriptptrs); return 0; diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 121380a04..92a9841c8 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -5029,9 +5029,11 @@ void G_SaveMapState(mapstate_t *save) Bmemcpy(&save->animatevel[0],&animatevel[0],sizeof(animatevel)); Bmemcpy(&save->g_animateCount,&g_animateCount,sizeof(g_animateCount)); Bmemcpy(&save->animatesect[0],&animatesect[0],sizeof(animatesect)); - for (i = g_animateCount-1; i>=0; i--) animateptr[i] = (int32_t *)((intptr_t)animateptr[i]-(intptr_t)(§or[0])); + + G_Util_PtrToIdx(animateptr, g_animateCount, sector, P2I_FWD); Bmemcpy(&save->animateptr[0],&animateptr[0],sizeof(animateptr)); - for (i = g_animateCount-1; i>=0; i--) animateptr[i] = (int32_t *)((intptr_t)animateptr[i]+(intptr_t)(§or[0])); + G_Util_PtrToIdx(animateptr, g_animateCount, sector, P2I_BACK); + Bmemcpy(&save->g_numPlayerSprites,&g_numPlayerSprites,sizeof(g_numPlayerSprites)); Bmemcpy(&save->g_earthquakeTime,&g_earthquakeTime,sizeof(g_earthquakeTime)); Bmemcpy(&save->lockclock,&lockclock,sizeof(lockclock)); @@ -5122,8 +5124,10 @@ void G_RestoreMapState(mapstate_t *save) Bmemcpy(&animatevel[0],&save->animatevel[0],sizeof(animatevel)); Bmemcpy(&g_animateCount,&save->g_animateCount,sizeof(g_animateCount)); Bmemcpy(&animatesect[0],&save->animatesect[0],sizeof(animatesect)); + Bmemcpy(&animateptr[0],&save->animateptr[0],sizeof(animateptr)); - for (i = g_animateCount-1; i>=0; i--) animateptr[i] = (int32_t *)((intptr_t)animateptr[i]+(intptr_t)(§or[0])); + G_Util_PtrToIdx(animateptr, g_animateCount, sector, P2I_BACK); + Bmemcpy(&g_numPlayerSprites,&save->g_numPlayerSprites,sizeof(g_numPlayerSprites)); Bmemcpy(&g_earthquakeTime,&save->g_earthquakeTime,sizeof(g_earthquakeTime)); Bmemcpy(&lockclock,&save->lockclock,sizeof(lockclock)); diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index 3525ee338..429019fb1 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "gamevars.h" #include "gamedef.h" #include "osd.h" +#include "savegame.h" #define _gamevars_c_ #include "gamestructures.c" @@ -165,12 +166,7 @@ int32_t Gv_ReadSave(int32_t fil, int32_t newbehav) // Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__); // AddLog(g_szBuf); if (kdfread(apScriptGameEvent,sizeof(apScriptGameEvent),1,fil) != 1) goto corrupt; - for (i=0; i "small int" +// back_p==1: "small int" -> ptr +// +// mode: see enum in savegame.h +void G_Util_PtrToIdx(void *ptr, uint32_t len, const void *base, int32_t mode) +{ + uint32_t i; + intptr_t *iptr = ptr, ibase = (intptr_t)base; + int32_t back_p = mode&P2I_BACK_BIT; + int32_t onlynon0_p = mode&P2I_ONLYNON0_BIT; + + // TODO: convert to proper offsets/indices for (a step towards) cross- + // compatibility between 32- and 64-bit systems in the netplay. + // REMEMBER to bump BYTEVERSION then. + + for (i=0; i>3)+1) * sizeof(uint8_t)); if (kdfread(&bitptr[0],sizeof(uint8_t),(g_scriptSize+7)>>3,fil) != ((g_scriptSize+7)>>3)) goto corrupt; + if (script != NULL) Bfree(script); script = Bcalloc(1,g_scriptSize * sizeof(intptr_t)); @@ -367,19 +396,10 @@ int32_t G_LoadPlayer(int32_t spot) } if (kdfread(&actorscrptr[0],sizeof(actorscrptr[0]),MAXTILES,fil) != MAXTILES) goto corrupt; - for (i=0; i=0; i--) animateptr[i] = (int32_t *)((intptr_t)animateptr[i]+(intptr_t)(§or[0])); + G_Util_PtrToIdx(animateptr, g_animateCount, sector, P2I_BACK); + if (kdfread(&animategoal[0],sizeof(animategoal[0]),MAXANIMATES,fil) != MAXANIMATES) goto corrupt; if (kdfread(&animatevel[0],sizeof(animatevel[0]),MAXANIMATES,fil) != MAXANIMATES) goto corrupt; @@ -780,33 +801,13 @@ int32_t G_SavePlayer(int32_t spot) script[i] = j; } - for (i=0; i=0; i--) animateptr[i] = (int32_t *)((intptr_t)animateptr[i]-(intptr_t)(§or[0])); + + G_Util_PtrToIdx(animateptr, g_animateCount, sector, P2I_FWD); dfwrite(&animateptr[0],sizeof(animateptr[0]),MAXANIMATES,fil); - for (i = g_animateCount-1; i>=0; i--) animateptr[i] = (int32_t *)((intptr_t)animateptr[i]+(intptr_t)(§or[0])); + G_Util_PtrToIdx(animateptr, g_animateCount, sector, P2I_BACK); + dfwrite(&animategoal[0],sizeof(animategoal[0]),MAXANIMATES,fil); dfwrite(&animatevel[0],sizeof(animatevel[0]),MAXANIMATES,fil); @@ -1902,12 +1905,9 @@ static void sv_prescriptsave_once() for (i=0; i>3]&(BITPTR_POINTER<<(i&7))) script[i] = (intptr_t)((intptr_t *)script[i] - &script[0]); - for (i=0; i>3]&(BITPTR_POINTER<<(i&7))) script[i] = (intptr_t)(script[i] + &script[0]); @@ -1948,7 +1946,7 @@ static void sv_preactordatasave() static void sv_postactordata() { int32_t i; - intptr_t j=(intptr_t)&script[0]; + intptr_t j=(intptr_t)script; #if POLYMER if (getrendermode() == 4) @@ -1971,15 +1969,11 @@ static void sv_postactordata() static void sv_preanimateptrsave() { - int32_t i; - for (i=g_animateCount-1; i>=0; i--) - animateptr[i] = (int32_t *)((intptr_t)animateptr[i]-(intptr_t)§or[0]); + G_Util_PtrToIdx(animateptr, g_animateCount, sector, P2I_FWD); } static void sv_postanimateptr() { - int32_t i; - for (i=g_animateCount-1; i>=0; i--) - animateptr[i] = (int32_t *)((intptr_t)animateptr[i]+(intptr_t)§or[0]); + G_Util_PtrToIdx(animateptr, g_animateCount, sector, P2I_BACK); } static void sv_prequote() { diff --git a/polymer/eduke32/source/savegame.h b/polymer/eduke32/source/savegame.h index 46e452fbf..8239f7deb 100644 --- a/polymer/eduke32/source/savegame.h +++ b/polymer/eduke32/source/savegame.h @@ -43,4 +43,18 @@ int32_t G_LoadPlayer(int32_t spot); int32_t G_LoadSaveHeader(char spot,struct savehead *saveh); void ReadSaveGameHeaders(void); extern char *bitptr; + +enum +{ + P2I_BACK_BIT = 1, + P2I_ONLYNON0_BIT = 2, + + P2I_FWD = 0, + P2I_BACK = 1, + + P2I_FWD_NON0 = 0+2, + P2I_BACK_NON0 = 1+2, +}; +void G_Util_PtrToIdx(void *ptr, uint32_t len, const void *base, int32_t mode); + #endif