mirror of
https://github.com/ZDoom/Raze.git
synced 2025-01-18 22:51:50 +00:00
Fix savegame crash issue
git-svn-id: https://svn.eduke32.com/eduke32@6983 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
d4c9cc28d5
commit
220d86a583
4 changed files with 31 additions and 62 deletions
|
@ -58,10 +58,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 330
|
# define BYTEVERSION_EDUKE32 333
|
||||||
#else
|
#else
|
||||||
// Non-Lua build
|
// Non-Lua build
|
||||||
# define BYTEVERSION_EDUKE32 330
|
# define BYTEVERSION_EDUKE32 333
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#define BYTEVERSION_13 27
|
//#define BYTEVERSION_13 27
|
||||||
|
|
|
@ -2672,7 +2672,6 @@ LUNATIC_EXTERN int32_t C_SetDefName(const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultprojectile_t DefaultProjectile;
|
defaultprojectile_t DefaultProjectile;
|
||||||
int32_t g_numProjectiles = 0;
|
|
||||||
|
|
||||||
EDUKE32_STATIC_ASSERT(sizeof(projectile_t) == sizeof(DefaultProjectile));
|
EDUKE32_STATIC_ASSERT(sizeof(projectile_t) == sizeof(DefaultProjectile));
|
||||||
|
|
||||||
|
@ -2695,7 +2694,6 @@ LUNATIC_EXTERN void C_DefineProjectile(int32_t j, int32_t what, int32_t val)
|
||||||
{
|
{
|
||||||
C_AllocProjectile(j);
|
C_AllocProjectile(j);
|
||||||
*g_tile[j].proj = DefaultProjectile;
|
*g_tile[j].proj = DefaultProjectile;
|
||||||
g_numProjectiles += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
projectile_t * const proj = g_tile[j].proj;
|
projectile_t * const proj = g_tile[j].proj;
|
||||||
|
|
|
@ -162,8 +162,6 @@ void C_FreeProjectile(int32_t j);
|
||||||
void C_InitQuotes(void);
|
void C_InitQuotes(void);
|
||||||
void C_InitProjectiles(void);
|
void C_InitProjectiles(void);
|
||||||
|
|
||||||
extern int32_t g_numProjectiles;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int spriteNum;
|
int spriteNum;
|
||||||
int playerNum;
|
int playerNum;
|
||||||
|
|
|
@ -1097,10 +1097,7 @@ static uint32_t calcsz(const dataspec_t *spec)
|
||||||
static void sv_prespriteextsave();
|
static void sv_prespriteextsave();
|
||||||
static void sv_postspriteext();
|
static void sv_postspriteext();
|
||||||
#endif
|
#endif
|
||||||
#if !defined LUNATIC
|
#if defined LUNATIC
|
||||||
static void sv_prescriptsave_once();
|
|
||||||
static void sv_postscript_once();
|
|
||||||
#else
|
|
||||||
// Recreate Lua state.
|
// Recreate Lua state.
|
||||||
// XXX: It may matter a great deal when this is run from if the Lua code refers
|
// XXX: It may matter a great deal when this is run from if the Lua code refers
|
||||||
// to C-side data at file scope. Such usage is strongly discouraged though.
|
// to C-side data at file scope. Such usage is strongly discouraged though.
|
||||||
|
@ -1127,7 +1124,9 @@ static void sv_postprojectilesave();
|
||||||
static void sv_preprojectileload();
|
static void sv_preprojectileload();
|
||||||
static void sv_postprojectileload();
|
static void sv_postprojectileload();
|
||||||
|
|
||||||
static projectile_t *ProjectileData;
|
static projectile_t *savegame_projectiledata;
|
||||||
|
static uint8_t savegame_projectiles[MAXSPRITES>>3];
|
||||||
|
static int32_t savegame_projectilecnt = 0;
|
||||||
|
|
||||||
#define SVARDATALEN \
|
#define SVARDATALEN \
|
||||||
((sizeof(g_player[0].user_name)+sizeof(g_player[0].pcolor)+sizeof(g_player[0].pteam) \
|
((sizeof(g_player[0].user_name)+sizeof(g_player[0].pcolor)+sizeof(g_player[0].pteam) \
|
||||||
|
@ -1242,18 +1241,12 @@ static char svgm_script_string [] = "blK:scri";
|
||||||
static const dataspec_t svgm_script[] =
|
static const dataspec_t svgm_script[] =
|
||||||
{
|
{
|
||||||
{ DS_STRING, (void *)svgm_script_string, 0, 1 },
|
{ DS_STRING, (void *)svgm_script_string, 0, 1 },
|
||||||
#if !defined LUNATIC
|
|
||||||
{ DS_SAVEFN|DS_NOCHK, (void *)&sv_prescriptsave_once, 0, 1 },
|
|
||||||
#endif
|
|
||||||
{ DS_SAVEFN, (void *) &sv_preprojectilesave, 0, 1 },
|
{ DS_SAVEFN, (void *) &sv_preprojectilesave, 0, 1 },
|
||||||
|
{ DS_NOCHK, &savegame_projectiles, sizeof(savegame_projectiles), 1 },
|
||||||
{ DS_LOADFN, (void *) &sv_preprojectileload, 0, 1 },
|
{ DS_LOADFN, (void *) &sv_preprojectileload, 0, 1 },
|
||||||
{ DS_NOCHK, &g_tile[0], sizeof(tiledata_t), MAXTILES },
|
{ DS_DYNAMIC|DS_CNT(savegame_projectilecnt), &savegame_projectiledata, sizeof(projectile_t), (intptr_t)&savegame_projectilecnt },
|
||||||
{ DS_DYNAMIC|DS_CNT(g_numProjectiles), &ProjectileData, sizeof(projectile_t), (intptr_t)&g_numProjectiles },
|
|
||||||
{ DS_SAVEFN, (void *) &sv_postprojectilesave, 0, 1 },
|
{ DS_SAVEFN, (void *) &sv_postprojectilesave, 0, 1 },
|
||||||
{ DS_LOADFN, (void *) &sv_postprojectileload, 0, 1 },
|
{ DS_LOADFN, (void *) &sv_postprojectileload, 0, 1 },
|
||||||
#if !defined LUNATIC
|
|
||||||
{ DS_SAVEFN|DS_LOADFN|DS_NOCHK, (void *)&sv_postscript_once, 0, 1 },
|
|
||||||
#endif
|
|
||||||
{ 0, &actor[0], sizeof(actor_t), MAXSPRITES },
|
{ 0, &actor[0], sizeof(actor_t), MAXSPRITES },
|
||||||
{ DS_SAVEFN|DS_LOADFN, (void *)&sv_postactordata, 0, 1 },
|
{ DS_SAVEFN|DS_LOADFN, (void *)&sv_postactordata, 0, 1 },
|
||||||
#if defined LUNATIC
|
#if defined LUNATIC
|
||||||
|
@ -1802,20 +1795,6 @@ void sv_postyaxload(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined LUNATIC
|
|
||||||
static void sv_prescriptsave_once()
|
|
||||||
{
|
|
||||||
G_Util_PtrToIdx2(&g_tile[0].execPtr, MAXTILES, sizeof(tiledata_t), apScript, P2I_FWD_NON0);
|
|
||||||
G_Util_PtrToIdx2(&g_tile[0].loadPtr, MAXTILES, sizeof(tiledata_t), apScript, P2I_FWD_NON0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sv_postscript_once()
|
|
||||||
{
|
|
||||||
G_Util_PtrToIdx2(&g_tile[0].execPtr, MAXTILES, sizeof(tiledata_t), apScript, P2I_BACK_NON0);
|
|
||||||
G_Util_PtrToIdx2(&g_tile[0].loadPtr, MAXTILES, sizeof(tiledata_t), apScript, P2I_BACK_NON0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void sv_postactordata()
|
static void sv_postactordata()
|
||||||
{
|
{
|
||||||
#ifdef POLYMER
|
#ifdef POLYMER
|
||||||
|
@ -1869,26 +1848,25 @@ static void sv_quoteload()
|
||||||
|
|
||||||
static void sv_preprojectilesave()
|
static void sv_preprojectilesave()
|
||||||
{
|
{
|
||||||
if (ProjectileData != NULL || g_numProjectiles > 0)
|
savegame_projectilecnt = 0;
|
||||||
ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles);
|
|
||||||
#ifdef DEBUGGINGAIDS
|
for (bssize_t i=0; i<MAXTILES; i++)
|
||||||
int onumprojectiles = g_numProjectiles;
|
if (g_tile[i].proj)
|
||||||
#endif
|
savegame_projectilecnt++;
|
||||||
g_numProjectiles = 0;
|
|
||||||
|
if (savegame_projectiledata != NULL || savegame_projectilecnt > 0)
|
||||||
|
savegame_projectiledata = (projectile_t *) Xrealloc(savegame_projectiledata, sizeof(projectile_t) * savegame_projectilecnt);
|
||||||
|
|
||||||
|
int32_t cnt = 0;
|
||||||
|
|
||||||
for (bssize_t i=0; i<MAXTILES; i++)
|
for (bssize_t i=0; i<MAXTILES; i++)
|
||||||
{
|
{
|
||||||
if (g_tile[i].proj)
|
if (g_tile[i].proj)
|
||||||
{
|
{
|
||||||
Bmemcpy(&ProjectileData[g_numProjectiles], g_tile[i].proj, sizeof(projectile_t));
|
savegame_projectiles[i>>3] |= 1<<(i&7);
|
||||||
Bmemcpy(&ProjectileData[g_numProjectiles+1], g_tile[i].defproj, sizeof(projectile_t));
|
Bmemcpy(&savegame_projectiledata[cnt++], g_tile[i].proj, sizeof(projectile_t));
|
||||||
g_numProjectiles += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUGGINGAIDS
|
|
||||||
Bassert(g_numProjectiles == onumprojectiles);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sv_postprojectilesave()
|
static void sv_postprojectilesave()
|
||||||
|
@ -1898,35 +1876,30 @@ static void sv_postprojectilesave()
|
||||||
|
|
||||||
static void sv_preprojectileload()
|
static void sv_preprojectileload()
|
||||||
{
|
{
|
||||||
if (ProjectileData != NULL || g_numProjectiles > 0)
|
int32_t cnt = 0;
|
||||||
ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles);
|
|
||||||
|
|
||||||
for (bssize_t i=0; i<MAXTILES; i++)
|
for (bssize_t i=0; i<MAXTILES; i++)
|
||||||
C_FreeProjectile(i);
|
{
|
||||||
|
if (savegame_projectiles[i>>3]&(1<<(i&7)))
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (savegame_projectiledata != NULL || cnt > 0)
|
||||||
|
savegame_projectiledata = (projectile_t *) Xrealloc(savegame_projectiledata, sizeof(projectile_t) * cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sv_postprojectileload()
|
static void sv_postprojectileload()
|
||||||
{
|
{
|
||||||
#ifdef DEBUGGINGAIDS
|
int32_t cnt = 0;
|
||||||
int onumprojectiles = g_numProjectiles;
|
|
||||||
#endif
|
|
||||||
g_numProjectiles = 0;
|
|
||||||
|
|
||||||
for (bssize_t i=0; i<MAXTILES; i++)
|
for (bssize_t i=0; i<MAXTILES; i++)
|
||||||
{
|
{
|
||||||
if (g_tile[i].proj)
|
if (savegame_projectiles[i>>3]&(1<<(i&7)))
|
||||||
{
|
{
|
||||||
C_AllocProjectile(i);
|
C_AllocProjectile(i);
|
||||||
Bmemcpy(g_tile[i].proj, &ProjectileData[g_numProjectiles], sizeof(projectile_t));
|
Bmemcpy(g_tile[i].proj, &savegame_projectiledata[cnt++], sizeof(projectile_t));
|
||||||
Bmemcpy(g_tile[i].defproj, &ProjectileData[g_numProjectiles+1], sizeof(projectile_t));
|
|
||||||
g_numProjectiles += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUGGINGAIDS
|
|
||||||
Bassert(g_numProjectiles == onumprojectiles);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// DO_FREE_AND_NULL(ProjectileData);
|
// DO_FREE_AND_NULL(ProjectileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue