2006-04-13 20:47:06 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
2010-05-25 10:56:00 +00:00
|
|
|
Copyright (C) 2010 EDuke32 developers and contributors
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
This file is part of EDuke32.
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
EDuke32 is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-04-13 20:47:06 +00:00
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "duke3d.h"
|
2010-08-02 08:13:51 +00:00
|
|
|
#include "premap.h"
|
2011-12-25 15:34:06 +00:00
|
|
|
#include "menus.h" // menutext
|
2010-06-23 04:20:46 +00:00
|
|
|
#include "prlights.h"
|
2011-07-29 22:07:49 +00:00
|
|
|
#include "savegame.h"
|
2013-05-20 19:31:42 +00:00
|
|
|
#ifdef LUNATIC
|
|
|
|
# include "lunatic_game.h"
|
|
|
|
static int32_t g_savedOK;
|
|
|
|
const char *g_failedVarname;
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-16 22:15:46 +00:00
|
|
|
extern char *bitptr;
|
|
|
|
|
2014-05-17 12:36:40 +00:00
|
|
|
uint8_t g_oldverSavegame[MAXSAVEGAMES];
|
2012-11-13 10:50:06 +00:00
|
|
|
|
2008-08-17 09:01:31 +00:00
|
|
|
#define BITPTR_POINTER 1
|
|
|
|
|
2011-07-29 22:07:49 +00:00
|
|
|
// For storing pointers in files.
|
|
|
|
// back_p==0: ptr -> "small int"
|
|
|
|
// back_p==1: "small int" -> ptr
|
|
|
|
//
|
|
|
|
// mode: see enum in savegame.h
|
2015-03-24 00:40:12 +00:00
|
|
|
void G_Util_PtrToIdx(void *ptr, int32_t const count, const void *base, int32_t const mode)
|
2011-07-29 22:07:49 +00:00
|
|
|
{
|
2012-11-15 14:28:36 +00:00
|
|
|
intptr_t *iptr = (intptr_t *)ptr;
|
2015-02-11 05:22:23 +00:00
|
|
|
intptr_t const ibase = (intptr_t)base;
|
|
|
|
int32_t const onlynon0_p = mode&P2I_ONLYNON0_BIT;
|
2011-07-29 22:07:49 +00:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2015-02-11 05:22:23 +00:00
|
|
|
// WARNING: C std doesn't say that bit pattern of NULL is necessarily 0!
|
|
|
|
if ((mode & P2I_BACK_BIT) == 0)
|
|
|
|
{
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i = 0; i < count; i++)
|
2015-02-11 05:22:23 +00:00
|
|
|
if (!onlynon0_p || iptr[i])
|
2011-07-29 22:07:49 +00:00
|
|
|
iptr[i] -= ibase;
|
2015-02-11 05:22:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i = 0; i < count; i++)
|
2015-02-11 05:22:23 +00:00
|
|
|
if (!onlynon0_p || iptr[i])
|
2011-07-29 22:07:49 +00:00
|
|
|
iptr[i] += ibase;
|
2015-02-11 05:22:23 +00:00
|
|
|
}
|
2011-07-29 22:07:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 00:40:12 +00:00
|
|
|
void G_Util_PtrToIdx2(void *ptr, int32_t const count, size_t const stride, const void *base, int32_t const mode)
|
2012-10-30 15:54:35 +00:00
|
|
|
{
|
2012-11-11 17:57:01 +00:00
|
|
|
uint8_t *iptr = (uint8_t *)ptr;
|
2015-02-11 05:22:23 +00:00
|
|
|
intptr_t const ibase = (intptr_t)base;
|
|
|
|
int32_t const onlynon0_p = mode&P2I_ONLYNON0_BIT;
|
2012-10-30 15:54:35 +00:00
|
|
|
|
2015-02-11 05:22:23 +00:00
|
|
|
if ((mode & P2I_BACK_BIT) == 0)
|
2012-10-30 15:54:35 +00:00
|
|
|
{
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i = 0; i < count; ++i)
|
2012-10-30 15:54:35 +00:00
|
|
|
{
|
2015-02-11 05:22:23 +00:00
|
|
|
if (!onlynon0_p || *(intptr_t *)iptr)
|
2012-10-30 15:54:35 +00:00
|
|
|
*(intptr_t *)iptr -= ibase;
|
2015-02-11 05:22:23 +00:00
|
|
|
|
|
|
|
iptr += stride;
|
2012-10-30 15:54:35 +00:00
|
|
|
}
|
2015-02-11 05:22:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i = 0; i < count; ++i)
|
2015-02-11 05:22:23 +00:00
|
|
|
{
|
|
|
|
if (!onlynon0_p || *(intptr_t *)iptr)
|
|
|
|
*(intptr_t *)iptr += ibase;
|
2012-10-30 15:54:35 +00:00
|
|
|
|
2015-02-11 05:22:23 +00:00
|
|
|
iptr += stride;
|
|
|
|
}
|
2012-10-30 15:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-29 22:07:28 +00:00
|
|
|
// TODO: sync with TROR special interpolations? (e.g. upper floor of subway)
|
|
|
|
void G_ResetInterpolations(void)
|
|
|
|
{
|
|
|
|
int32_t k, i;
|
|
|
|
|
2016-08-27 01:42:01 +00:00
|
|
|
g_interpolationCnt = 0;
|
2011-07-29 22:07:28 +00:00
|
|
|
|
|
|
|
k = headspritestat[STAT_EFFECTOR];
|
|
|
|
while (k >= 0)
|
|
|
|
{
|
|
|
|
switch (sprite[k].lotag)
|
|
|
|
{
|
2012-08-26 22:16:08 +00:00
|
|
|
case SE_31_FLOOR_RISE_FALL:
|
2011-07-29 22:07:28 +00:00
|
|
|
G_SetInterpolation(§or[sprite[k].sectnum].floorz);
|
|
|
|
break;
|
2012-08-26 22:16:08 +00:00
|
|
|
case SE_32_CEILING_RISE_FALL:
|
2011-07-29 22:07:28 +00:00
|
|
|
G_SetInterpolation(§or[sprite[k].sectnum].ceilingz);
|
|
|
|
break;
|
2012-08-26 22:16:08 +00:00
|
|
|
case SE_17_WARP_ELEVATOR:
|
|
|
|
case SE_25_PISTON:
|
2011-07-29 22:07:28 +00:00
|
|
|
G_SetInterpolation(§or[sprite[k].sectnum].floorz);
|
|
|
|
G_SetInterpolation(§or[sprite[k].sectnum].ceilingz);
|
|
|
|
break;
|
2012-09-08 22:18:44 +00:00
|
|
|
case SE_0_ROTATING_SECTOR:
|
|
|
|
case SE_5:
|
|
|
|
case SE_6_SUBWAY:
|
|
|
|
case SE_11_SWINGING_DOOR:
|
|
|
|
case SE_14_SUBWAY_CAR:
|
|
|
|
case SE_15_SLIDING_DOOR:
|
2012-08-26 22:16:08 +00:00
|
|
|
case SE_16_REACTOR:
|
|
|
|
case SE_26:
|
|
|
|
case SE_30_TWO_WAY_TRAIN:
|
2011-07-29 22:07:28 +00:00
|
|
|
Sect_SetInterpolation(sprite[k].sectnum);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
k = nextspritestat[k];
|
|
|
|
}
|
|
|
|
|
2016-08-27 01:42:01 +00:00
|
|
|
for (i=g_interpolationCnt-1; i>=0; i--) bakipos[i] = *curipos[i];
|
|
|
|
for (i = g_animateCnt-1; i>=0; i--)
|
|
|
|
G_SetInterpolation(g_animatePtr[i]);
|
2011-07-29 22:07:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
void ReadSaveGameHeaders(void)
|
|
|
|
{
|
|
|
|
char fn[16];
|
|
|
|
int32_t fil, i;
|
|
|
|
|
|
|
|
savehead_t h;
|
|
|
|
|
2013-08-04 20:37:45 +00:00
|
|
|
EDUKE32_STATIC_ASSERT(sizeof(h.savename) == sizeof(ud.savegame[0]));
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
Bstrcpy(fn, "dukesav0.esv");
|
|
|
|
|
2014-05-17 12:36:40 +00:00
|
|
|
for (i=0; i<MAXSAVEGAMES; i++)
|
2011-12-25 15:34:06 +00:00
|
|
|
{
|
|
|
|
int32_t k;
|
|
|
|
|
|
|
|
fn[7] = i + '0';
|
|
|
|
fil = kopen4loadfrommod(fn, 0);
|
|
|
|
if (fil == -1)
|
|
|
|
{
|
|
|
|
Bmemset(ud.savegame[i], 0, sizeof(ud.savegame[i]));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
k = sv_loadheader(fil, i, &h);
|
|
|
|
if (k)
|
|
|
|
{
|
2012-11-13 10:50:06 +00:00
|
|
|
// old version, signal to menu code
|
2011-12-25 15:34:06 +00:00
|
|
|
if (k==2 || k==3)
|
2012-11-13 10:50:06 +00:00
|
|
|
g_oldverSavegame[i] = 1;
|
2011-12-25 15:34:06 +00:00
|
|
|
// else h.savename is all zeros (fatal failure, like wrong header
|
|
|
|
// magic or too short header)
|
|
|
|
}
|
|
|
|
|
|
|
|
Bmemcpy(ud.savegame[i], h.savename, sizeof(ud.savegame[i]));
|
|
|
|
|
|
|
|
kclose(fil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t G_LoadSaveHeaderNew(int32_t spot, savehead_t *saveh)
|
|
|
|
{
|
|
|
|
char fn[16];
|
2011-12-25 15:34:52 +00:00
|
|
|
int32_t fil, screenshotofs, i;
|
2011-12-25 15:34:06 +00:00
|
|
|
|
2014-05-17 12:36:40 +00:00
|
|
|
Bassert(spot < MAXSAVEGAMES);
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
Bstrcpy(fn, "dukesav0.esv");
|
|
|
|
fn[7] = spot + '0';
|
|
|
|
|
|
|
|
fil = kopen4loadfrommod(fn, 0);
|
|
|
|
if (fil == -1)
|
|
|
|
return -1;
|
|
|
|
|
2011-12-25 15:34:52 +00:00
|
|
|
i = sv_loadheader(fil, spot, saveh);
|
|
|
|
if (i && (i != 2 && i != 3))
|
2011-12-25 15:34:06 +00:00
|
|
|
goto corrupt;
|
|
|
|
|
|
|
|
if (kread(fil, &screenshotofs, 4) != 4)
|
|
|
|
goto corrupt;
|
|
|
|
|
|
|
|
walock[TILE_LOADSHOT] = 255;
|
|
|
|
if (waloff[TILE_LOADSHOT] == 0)
|
|
|
|
allocache(&waloff[TILE_LOADSHOT], 320*200, &walock[TILE_LOADSHOT]);
|
2014-09-30 04:14:21 +00:00
|
|
|
tilesiz[TILE_LOADSHOT].x = 200;
|
|
|
|
tilesiz[TILE_LOADSHOT].y = 320;
|
2011-12-25 15:34:06 +00:00
|
|
|
if (screenshotofs)
|
|
|
|
{
|
|
|
|
if (kdfread((char *)waloff[TILE_LOADSHOT], 320, 200, fil) != 200)
|
2011-12-25 15:34:52 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("G_LoadSaveHeaderNew(%d): failed reading screenshot\n", spot);
|
2011-12-25 15:34:06 +00:00
|
|
|
goto corrupt;
|
2011-12-25 15:34:52 +00:00
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Bmemset((char *)waloff[TILE_LOADSHOT], 0, 320*200);
|
|
|
|
}
|
|
|
|
invalidatetile(TILE_LOADSHOT, 0, 255);
|
|
|
|
|
|
|
|
kclose(fil);
|
|
|
|
return 0;
|
2006-12-10 06:49:01 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
corrupt:
|
|
|
|
kclose(fil);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sv_postudload();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2013-05-19 19:29:18 +00:00
|
|
|
// XXX: keyboard input 'blocked' after load fail? (at least ESC?)
|
2011-12-25 15:34:06 +00:00
|
|
|
int32_t G_LoadPlayer(int32_t spot)
|
|
|
|
{
|
|
|
|
char fn[16];
|
|
|
|
int32_t fil, i;
|
|
|
|
|
|
|
|
savehead_t h;
|
|
|
|
|
2014-05-17 12:36:40 +00:00
|
|
|
Bassert(spot < MAXSAVEGAMES);
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
Bstrcpy(fn, "dukesav0.esv");
|
|
|
|
fn[7] = spot + '0';
|
|
|
|
|
|
|
|
fil = kopen4loadfrommod(fn, 0);
|
|
|
|
if (fil == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ready2send = 0;
|
|
|
|
|
|
|
|
i = sv_loadheader(fil, spot, &h);
|
2014-09-30 04:07:41 +00:00
|
|
|
if ((i && i != 2) || h.numplayers != ud.multimode)
|
2011-12-25 15:34:06 +00:00
|
|
|
{
|
|
|
|
if (i == 2 || i == 3)
|
|
|
|
P_DoQuote(QUOTE_SAVE_BAD_VERSION, g_player[myconnectindex].ps);
|
|
|
|
else if (h.numplayers!=ud.multimode)
|
|
|
|
P_DoQuote(QUOTE_SAVE_BAD_PLAYERS, g_player[myconnectindex].ps);
|
|
|
|
|
|
|
|
kclose(fil);
|
|
|
|
ototalclock = totalclock;
|
|
|
|
ready2send = 1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// some setup first
|
|
|
|
ud.multimode = h.numplayers;
|
|
|
|
|
|
|
|
if (numplayers > 1)
|
|
|
|
{
|
|
|
|
pub = NUMPAGES;
|
|
|
|
pus = NUMPAGES;
|
|
|
|
G_UpdateScreenArea();
|
|
|
|
G_DrawBackground();
|
|
|
|
menutext(160,100, 0,0, "LOADING...");
|
|
|
|
nextpage();
|
|
|
|
}
|
|
|
|
|
|
|
|
Net_WaitForServer();
|
|
|
|
|
|
|
|
FX_StopAllSounds();
|
|
|
|
S_ClearSoundLocks();
|
|
|
|
|
|
|
|
if (spot >= 0 && numplayers==1)
|
|
|
|
{
|
|
|
|
Bmemcpy(ud.savegame[spot], h.savename, sizeof(ud.savegame[0]));
|
|
|
|
ud.savegame[spot][sizeof(ud.savegame[0])-1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// non-"m_" fields will be loaded from svgm_udnetw
|
|
|
|
ud.m_volume_number = h.volnum;
|
|
|
|
ud.m_level_number = h.levnum;
|
|
|
|
ud.m_player_skill = h.skill;
|
|
|
|
|
2015-04-20 20:46:42 +00:00
|
|
|
// NOTE: Bmemcpy needed for SAVEGAME_MUSIC.
|
|
|
|
EDUKE32_STATIC_ASSERT(sizeof(boardfilename) == sizeof(h.boardfn));
|
|
|
|
Bmemcpy(boardfilename, h.boardfn, sizeof(boardfilename));
|
2014-09-07 18:10:15 +00:00
|
|
|
|
2015-04-20 20:46:42 +00:00
|
|
|
const int mapIdx = h.volnum*MAXLEVELS + h.levnum;
|
2011-12-25 15:34:06 +00:00
|
|
|
|
|
|
|
if (boardfilename[0])
|
|
|
|
Bstrcpy(currentboardfilename, boardfilename);
|
2016-08-27 01:42:01 +00:00
|
|
|
else if (g_mapInfo[mapIdx].filename)
|
|
|
|
Bstrcpy(currentboardfilename, g_mapInfo[mapIdx].filename);
|
2011-12-25 15:34:06 +00:00
|
|
|
|
|
|
|
if (currentboardfilename[0])
|
|
|
|
{
|
2015-04-20 20:46:42 +00:00
|
|
|
E_MapArt_Setup(currentboardfilename);
|
2013-05-06 19:43:38 +00:00
|
|
|
append_ext_UNSAFE(currentboardfilename, ".mhk");
|
2011-12-25 15:34:06 +00:00
|
|
|
loadmaphack(currentboardfilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bmemcpy(currentboardfilename, boardfilename, BMAX_PATH);
|
|
|
|
|
2014-09-30 04:03:30 +00:00
|
|
|
if (i == 2)
|
2011-12-25 15:34:06 +00:00
|
|
|
{
|
2014-09-30 04:03:30 +00:00
|
|
|
G_NewGame_EnterLevel();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// read the rest...
|
|
|
|
i = sv_loadsnapshot(fil, spot, &h);
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
// in theory, we could load into an initial dump first and trivially
|
|
|
|
// recover if things go wrong...
|
|
|
|
Bsprintf(tempbuf, "Loading save game file \"%s\" failed (code %d), cannot recover.", fn, i);
|
|
|
|
G_GameExit(tempbuf);
|
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
}
|
|
|
|
sv_postudload(); // ud.m_XXX = ud.XXX
|
|
|
|
|
2014-11-22 12:29:25 +00:00
|
|
|
VM_OnEvent(EVENT_LOADGAME, g_player[myconnectindex].ps->i, myconnectindex);
|
2012-05-25 05:14:19 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-19 22:42:21 +00:00
|
|
|
////////// TIMER SAVING/RESTORING //////////
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
int32_t totalclock, totalclocklock; // engine
|
|
|
|
int32_t ototalclock, lockclock; // game
|
|
|
|
} g_timers;
|
|
|
|
|
|
|
|
static void G_SaveTimers(void)
|
|
|
|
{
|
|
|
|
g_timers.totalclock = totalclock;
|
|
|
|
g_timers.totalclocklock = totalclocklock;
|
|
|
|
g_timers.ototalclock = ototalclock;
|
|
|
|
g_timers.lockclock = lockclock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void G_RestoreTimers(void)
|
|
|
|
{
|
|
|
|
sampletimer();
|
|
|
|
|
|
|
|
totalclock = g_timers.totalclock;
|
|
|
|
totalclocklock = g_timers.totalclocklock;
|
|
|
|
ototalclock = g_timers.ototalclock;
|
|
|
|
lockclock = g_timers.lockclock;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////
|
2011-12-25 15:34:06 +00:00
|
|
|
|
2015-02-11 05:22:23 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
static void G_SavePalette(void)
|
|
|
|
{
|
|
|
|
int32_t pfil;
|
|
|
|
|
|
|
|
if ((pfil = kopen4load("palette.dat", 0)) != -1)
|
|
|
|
{
|
|
|
|
int len = kfilelength(pfil);
|
|
|
|
|
|
|
|
FILE *fil = fopen("palette.dat", "rb");
|
|
|
|
|
|
|
|
if (!fil)
|
|
|
|
{
|
|
|
|
fil = fopen("palette.dat", "wb");
|
|
|
|
|
|
|
|
if (fil)
|
|
|
|
{
|
|
|
|
char *buf = (char *) Xaligned_alloc(16, len);
|
|
|
|
|
|
|
|
kread(pfil, buf, len);
|
|
|
|
fwrite(buf, len, 1, fil);
|
|
|
|
fclose(fil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else fclose(fil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
int32_t G_SavePlayer(int32_t spot)
|
|
|
|
{
|
|
|
|
char fn[16];
|
|
|
|
FILE *fil;
|
|
|
|
|
2015-02-11 05:22:23 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
G_SavePalette();
|
|
|
|
#endif
|
|
|
|
|
2014-05-17 12:36:40 +00:00
|
|
|
Bassert(spot < MAXSAVEGAMES);
|
|
|
|
|
2014-04-19 22:42:21 +00:00
|
|
|
G_SaveTimers();
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
Bstrcpy(fn, "dukesav0.esv");
|
|
|
|
fn[7] = spot + '0';
|
|
|
|
|
|
|
|
// Bstrcpy(mpfn, "edukA_00.esv");
|
|
|
|
|
|
|
|
Net_WaitForServer();
|
|
|
|
ready2send = 0;
|
|
|
|
|
|
|
|
{
|
|
|
|
char temp[BMAX_PATH];
|
|
|
|
|
2012-09-05 17:25:37 +00:00
|
|
|
if (G_ModDirSnprintf(temp, sizeof(temp), "%s", fn))
|
|
|
|
{
|
|
|
|
OSD_Printf("G_SavePlayer: file name \"%s\" too long\n", fn);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
|
2012-03-01 23:35:53 +00:00
|
|
|
errno = 0;
|
2011-12-25 15:34:06 +00:00
|
|
|
fil = fopen(temp, "wb");
|
|
|
|
if (!fil)
|
2012-03-01 23:35:53 +00:00
|
|
|
{
|
2012-03-26 05:05:57 +00:00
|
|
|
OSD_Printf("G_SavePlayer: failed opening \"%s\" for writing: %s\n",
|
2012-03-01 23:35:53 +00:00
|
|
|
temp, strerror(errno));
|
2012-09-05 17:25:40 +00:00
|
|
|
return -1;
|
2012-03-01 23:35:53 +00:00
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 21:58:23 +00:00
|
|
|
#ifdef POLYMER
|
2013-05-17 03:44:09 +00:00
|
|
|
if (getrendermode() == REND_POLYMER)
|
2012-01-05 21:58:23 +00:00
|
|
|
polymer_resetlights();
|
|
|
|
#endif
|
|
|
|
|
2014-11-22 12:29:25 +00:00
|
|
|
VM_OnEvent(EVENT_SAVEGAME, g_player[myconnectindex].ps->i, myconnectindex);
|
2012-05-25 05:14:19 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
// SAVE!
|
2011-12-28 20:33:54 +00:00
|
|
|
sv_saveandmakesnapshot(fil, spot, 0, 0, 0);
|
2011-12-25 15:34:06 +00:00
|
|
|
|
|
|
|
fclose(fil);
|
|
|
|
|
|
|
|
if (!g_netServer && ud.multimode < 2)
|
|
|
|
{
|
2013-05-20 19:31:42 +00:00
|
|
|
#ifdef LUNATIC
|
|
|
|
if (!g_savedOK)
|
2016-08-27 01:40:35 +00:00
|
|
|
Bstrcpy(apStrings[QUOTE_RESERVED4], "^10Failed Saving Game");
|
2013-05-20 19:31:42 +00:00
|
|
|
else
|
|
|
|
#endif
|
2016-08-27 01:40:35 +00:00
|
|
|
Bstrcpy(apStrings[QUOTE_RESERVED4], "Game Saved");
|
2011-12-25 15:34:06 +00:00
|
|
|
P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
ready2send = 1;
|
|
|
|
Net_WaitForServer();
|
|
|
|
|
2014-04-19 22:42:21 +00:00
|
|
|
G_RestoreTimers();
|
2011-12-25 15:34:06 +00:00
|
|
|
ototalclock = totalclock;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-09-05 17:25:43 +00:00
|
|
|
void G_LoadPlayerMaybeMulti(int32_t slot)
|
|
|
|
{
|
|
|
|
if (g_netServer || ud.multimode > 1)
|
|
|
|
{
|
2016-08-27 01:40:35 +00:00
|
|
|
Bstrcpy(apStrings[QUOTE_RESERVED4], "Multiplayer Loading Not Yet Supported");
|
2012-09-05 17:25:43 +00:00
|
|
|
P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps);
|
|
|
|
|
|
|
|
// G_LoadPlayer(-1-g_lastSaveSlot);
|
|
|
|
// g_player[myconnectindex].ps->gm = MODE_GAME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int32_t c = G_LoadPlayer(slot);
|
|
|
|
if (c == 0)
|
|
|
|
g_player[myconnectindex].ps->gm = MODE_GAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void G_SavePlayerMaybeMulti(int32_t slot)
|
|
|
|
{
|
|
|
|
Bassert(slot >= 0);
|
|
|
|
|
2013-04-03 17:26:49 +00:00
|
|
|
CONFIG_WriteSetup(2);
|
2013-03-19 06:23:12 +00:00
|
|
|
|
2012-09-05 17:25:43 +00:00
|
|
|
if (g_netServer || ud.multimode > 1)
|
|
|
|
{
|
2016-08-27 01:40:35 +00:00
|
|
|
Bstrcpy(apStrings[QUOTE_RESERVED4], "Multiplayer Saving Not Yet Supported");
|
2012-09-05 17:25:43 +00:00
|
|
|
P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps);
|
|
|
|
// G_SavePlayer(-1-slot);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
G_SavePlayer(slot);
|
|
|
|
}
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
////////// GENERIC SAVING/LOADING SYSTEM //////////
|
|
|
|
|
|
|
|
typedef struct dataspec_
|
|
|
|
{
|
|
|
|
uint32_t flags;
|
2016-01-11 05:05:38 +00:00
|
|
|
void * const ptr;
|
2010-01-24 23:33:17 +00:00
|
|
|
uint32_t size;
|
|
|
|
intptr_t cnt;
|
|
|
|
} dataspec_t;
|
|
|
|
|
2016-01-11 05:05:38 +00:00
|
|
|
typedef struct dataspec_gv_
|
|
|
|
{
|
|
|
|
uint32_t flags;
|
|
|
|
void * ptr;
|
|
|
|
uint32_t size;
|
|
|
|
intptr_t cnt;
|
|
|
|
} dataspec_gv_t;
|
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
#define SV_DEFAULTCOMPRTHRES 8
|
|
|
|
static uint8_t savegame_diffcompress; // 0:none, 1:Ken's LZW in cache1d.c
|
|
|
|
static uint8_t savegame_comprthres;
|
|
|
|
|
|
|
|
|
|
|
|
#define DS_DYNAMIC 1 // dereference .ptr one more time
|
|
|
|
#define DS_STRING 2
|
|
|
|
#define DS_CMP 4
|
|
|
|
// 8
|
|
|
|
#define DS_CNT(x) ((sizeof(x))<<3) // .cnt is pointer to...
|
|
|
|
#define DS_CNT16 16
|
|
|
|
#define DS_CNT32 32
|
|
|
|
#define DS_CNTMASK (8|DS_CNT16|DS_CNT32|64)
|
|
|
|
// 64
|
|
|
|
#define DS_LOADFN 128 // .ptr is function that is run when loading
|
|
|
|
#define DS_SAVEFN 256 // .ptr is function that is run when saving
|
2011-02-21 23:08:21 +00:00
|
|
|
#define DS_NOCHK 1024 // don't check for diffs (and don't write out in dump) since assumed constant throughout demo
|
2011-05-12 23:31:13 +00:00
|
|
|
#define DS_PROTECTFN 512
|
2010-01-24 23:33:17 +00:00
|
|
|
#define DS_END (0x70000000)
|
|
|
|
|
|
|
|
static int32_t ds_getcnt(const dataspec_t *sp)
|
|
|
|
{
|
2015-02-11 05:22:23 +00:00
|
|
|
int rv = -1;
|
|
|
|
|
|
|
|
switch (sp->flags & DS_CNTMASK)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2015-02-11 05:22:23 +00:00
|
|
|
case 0: rv = sp->cnt; break;
|
|
|
|
case DS_CNT16: rv = *((int16_t *)sp->cnt); break;
|
|
|
|
case DS_CNT32: rv = *((int32_t *)sp->cnt); break;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
2015-02-11 05:22:23 +00:00
|
|
|
|
|
|
|
return rv;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
2015-02-11 05:22:23 +00:00
|
|
|
static inline void ds_get(const dataspec_t *sp, void **ptr, int32_t *cnt)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
|
|
|
*cnt = ds_getcnt(sp);
|
2015-02-11 05:22:23 +00:00
|
|
|
*ptr = (sp->flags&DS_DYNAMIC) ? *((void **)sp->ptr) : sp->ptr;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// write state to file and/or to dump
|
|
|
|
static uint8_t *writespecdata(const dataspec_t *spec, FILE *fil, uint8_t *dump)
|
|
|
|
{
|
|
|
|
int32_t cnt;
|
2012-01-05 20:48:20 +00:00
|
|
|
void *ptr;
|
2010-01-24 23:33:17 +00:00
|
|
|
const dataspec_t *sp=spec;
|
|
|
|
|
|
|
|
for (; sp->flags!=DS_END; sp++)
|
|
|
|
{
|
|
|
|
if (sp->flags&(DS_SAVEFN|DS_LOADFN))
|
|
|
|
{
|
|
|
|
if (sp->flags&DS_SAVEFN)
|
2011-12-25 15:34:06 +00:00
|
|
|
(*(void (*)(void))sp->ptr)();
|
2010-01-24 23:33:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fil && (sp->flags&(DS_NOCHK|DS_CMP|DS_STRING)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sp->flags&DS_STRING)
|
|
|
|
{
|
2012-11-15 14:28:36 +00:00
|
|
|
fwrite(sp->ptr, Bstrlen((const char *)sp->ptr), 1, fil); // not null-terminated!
|
2010-01-24 23:33:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_get(sp, &ptr, &cnt);
|
|
|
|
if (cnt < 0) { OSD_Printf("wsd: cnt=%d, f=0x%x.\n",cnt,sp->flags); continue; }
|
|
|
|
|
2015-03-29 02:40:27 +00:00
|
|
|
if (!ptr || !cnt)
|
|
|
|
continue;
|
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
if (fil)
|
|
|
|
{
|
2011-12-09 19:08:29 +00:00
|
|
|
if (((sp->flags&DS_CNTMASK)==0 && sp->size*cnt<=savegame_comprthres)
|
2010-02-23 18:13:46 +00:00
|
|
|
|| (sp->flags&DS_CMP))
|
2010-01-24 23:33:17 +00:00
|
|
|
fwrite(ptr, sp->size, cnt, fil);
|
|
|
|
else
|
|
|
|
dfwrite((void *)ptr, sp->size, cnt, fil);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dump && (sp->flags&(DS_NOCHK|DS_CMP))==0)
|
|
|
|
{
|
|
|
|
Bmemcpy(dump, ptr, sp->size*cnt);
|
|
|
|
dump += sp->size*cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dump;
|
|
|
|
}
|
|
|
|
|
|
|
|
// let havedump=dumpvar&&*dumpvar
|
|
|
|
// (fil>=0 && havedump): first restore dump from file, then restore state from dump
|
|
|
|
// (fil<0 && havedump): only restore state from dump
|
|
|
|
// (fil>=0 && !havedump): only restore state from file
|
|
|
|
static int32_t readspecdata(const dataspec_t *spec, int32_t fil, uint8_t **dumpvar)
|
|
|
|
{
|
|
|
|
int32_t cnt, i, j;
|
|
|
|
void *ptr;
|
|
|
|
uint8_t *dump=dumpvar?*dumpvar:NULL, *mem;
|
|
|
|
const dataspec_t *sp=spec;
|
|
|
|
static char cmpstrbuf[32];
|
|
|
|
|
|
|
|
for (; sp->flags!=DS_END; sp++)
|
|
|
|
{
|
|
|
|
if (fil < 0 && sp->flags&(DS_NOCHK|DS_STRING|DS_CMP)) // we're updating
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sp->flags&(DS_LOADFN|DS_SAVEFN))
|
|
|
|
{
|
|
|
|
if (sp->flags&DS_LOADFN)
|
2012-03-28 19:45:25 +00:00
|
|
|
(*(void (*)())sp->ptr)();
|
2010-01-24 23:33:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sp->flags&(DS_STRING|DS_CMP)) // DS_STRING and DS_CMP is for static data only
|
|
|
|
{
|
|
|
|
if (sp->flags&(DS_STRING))
|
2012-11-15 14:28:36 +00:00
|
|
|
i = Bstrlen((const char *)sp->ptr);
|
2010-01-24 23:33:17 +00:00
|
|
|
else
|
|
|
|
i = sp->size*sp->cnt;
|
|
|
|
|
|
|
|
j=kread(fil, cmpstrbuf, i);
|
|
|
|
if (j!=i || Bmemcmp(sp->ptr, cmpstrbuf, i))
|
|
|
|
{
|
2011-12-26 14:37:34 +00:00
|
|
|
OSD_Printf("rsd: spec=%s, idx=%d:\n", (char *)spec->ptr, (int32_t)(sp-spec));
|
2010-01-24 23:33:17 +00:00
|
|
|
if (j!=i)
|
2011-12-25 15:34:06 +00:00
|
|
|
OSD_Printf(" kread returned %d, expected %d.\n", j, i);
|
2010-01-24 23:33:17 +00:00
|
|
|
else
|
2011-12-25 15:34:06 +00:00
|
|
|
OSD_Printf(" sp->ptr and cmpstrbuf not identical!\n");
|
2010-01-24 23:33:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:48:20 +00:00
|
|
|
ds_get(sp, &ptr, &cnt);
|
2010-01-24 23:33:17 +00:00
|
|
|
if (cnt < 0) { OSD_Printf("rsd: cnt<0... wtf?\n"); return -1; }
|
|
|
|
|
2015-03-29 02:40:27 +00:00
|
|
|
if (!ptr || !cnt)
|
|
|
|
continue;
|
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
if (fil>=0)
|
|
|
|
{
|
2012-11-15 14:28:36 +00:00
|
|
|
mem = (dump && (sp->flags&DS_NOCHK)==0) ? dump : (uint8_t *)ptr;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-09 19:08:29 +00:00
|
|
|
if ((sp->flags&DS_CNTMASK)==0 && sp->size*cnt<=savegame_comprthres)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
|
|
|
i = kread(fil, mem, cnt*sp->size);
|
|
|
|
j = cnt*sp->size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = kdfread(mem, sp->size, cnt, fil);
|
|
|
|
j = cnt;
|
|
|
|
}
|
|
|
|
if (i!=j)
|
|
|
|
{
|
2011-12-26 14:37:34 +00:00
|
|
|
OSD_Printf("rsd: spec=%s, idx=%d, mem=%p\n", (char *)spec->ptr, (int32_t)(sp-spec), mem);
|
2011-12-25 15:34:06 +00:00
|
|
|
OSD_Printf(" (%s): read %d, expected %d!\n",
|
2011-12-09 19:08:29 +00:00
|
|
|
((sp->flags&DS_CNTMASK)==0 && sp->size*cnt<=savegame_comprthres)?
|
2011-12-25 15:34:06 +00:00
|
|
|
"uncompressed":"compressed", i, j);
|
2010-02-23 18:13:46 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
if (i==-1)
|
2011-12-21 18:42:12 +00:00
|
|
|
OSD_Printf(" read: %s\n", strerror(errno));
|
2010-01-24 23:33:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dump && (sp->flags&DS_NOCHK)==0)
|
|
|
|
{
|
|
|
|
Bmemcpy(ptr, dump, sp->size*cnt);
|
|
|
|
dump += sp->size*cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dumpvar)
|
|
|
|
*dumpvar = dump;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define UINT(bits) uint##bits##_t
|
|
|
|
#define BYTES(bits) (bits>>3)
|
2016-01-11 05:05:38 +00:00
|
|
|
#define VAL(bits,p) (*(UINT(bits) const *)(p))
|
|
|
|
#define WVAL(bits,p) (*(UINT(bits) *)(p))
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
static void docmpsd(const void *ptr, void *dump, uint32_t size, uint32_t cnt, uint8_t **diffvar)
|
|
|
|
{
|
|
|
|
uint8_t *retdiff = *diffvar;
|
|
|
|
|
|
|
|
// Hail to the C preprocessor, baby!
|
2010-02-23 18:13:46 +00:00
|
|
|
#define CPSINGLEVAL(Datbits) \
|
2010-01-24 23:33:17 +00:00
|
|
|
if (VAL(Datbits, ptr) != VAL(Datbits, dump)) \
|
|
|
|
{ \
|
2016-01-11 05:05:38 +00:00
|
|
|
WVAL(Datbits, retdiff) = WVAL(Datbits, dump) = VAL(Datbits, ptr); \
|
2010-01-24 23:33:17 +00:00
|
|
|
*diffvar = retdiff+BYTES(Datbits); \
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt==1)
|
|
|
|
switch (size)
|
|
|
|
{
|
|
|
|
case 8: CPSINGLEVAL(64); return;
|
|
|
|
case 4: CPSINGLEVAL(32); return;
|
|
|
|
case 2: CPSINGLEVAL(16); return;
|
|
|
|
case 1: CPSINGLEVAL(8); return;
|
|
|
|
}
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
#define CPELTS(Idxbits, Datbits) do \
|
2010-01-24 23:33:17 +00:00
|
|
|
{ \
|
|
|
|
for (i=0; i<nelts; i++) \
|
|
|
|
{ \
|
|
|
|
if (*p!=*op) \
|
|
|
|
{ \
|
2012-11-15 14:28:47 +00:00
|
|
|
*op = *p; \
|
2016-01-11 05:05:38 +00:00
|
|
|
WVAL(Idxbits, retdiff) = i; \
|
2010-01-24 23:33:17 +00:00
|
|
|
retdiff += BYTES(Idxbits); \
|
2016-01-11 05:05:38 +00:00
|
|
|
WVAL(Datbits, retdiff) = *p; \
|
2010-01-24 23:33:17 +00:00
|
|
|
retdiff += BYTES(Datbits); \
|
|
|
|
} \
|
|
|
|
p++; \
|
|
|
|
op++; \
|
|
|
|
} \
|
2016-01-11 05:05:38 +00:00
|
|
|
WVAL(Idxbits, retdiff) = -1; \
|
2010-01-24 23:33:17 +00:00
|
|
|
retdiff += BYTES(Idxbits); \
|
|
|
|
} while (0)
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
#define CPDATA(Datbits) do \
|
2010-01-24 23:33:17 +00:00
|
|
|
{ \
|
2016-01-11 05:05:38 +00:00
|
|
|
const UINT(Datbits) *p=(UINT(Datbits) const *)ptr; \
|
2012-11-15 14:28:36 +00:00
|
|
|
UINT(Datbits) *op=(UINT(Datbits) *)dump; \
|
2014-10-25 03:29:21 +00:00
|
|
|
uint32_t i, nelts=tabledivide32_noinline(size*cnt, BYTES(Datbits)); \
|
2012-11-15 14:28:36 +00:00
|
|
|
if (nelts>65536) \
|
|
|
|
CPELTS(32,Datbits); \
|
|
|
|
else if (nelts>256) \
|
|
|
|
CPELTS(16,Datbits); \
|
|
|
|
else \
|
|
|
|
CPELTS(8,Datbits); \
|
2010-01-24 23:33:17 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
if (size==8)
|
|
|
|
CPDATA(64);
|
|
|
|
else if ((size&3)==0)
|
|
|
|
CPDATA(32);
|
|
|
|
else if ((size&1)==0)
|
|
|
|
CPDATA(16);
|
|
|
|
else
|
|
|
|
CPDATA(8);
|
|
|
|
|
|
|
|
*diffvar = retdiff;
|
|
|
|
return;
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
#undef CPELTS
|
|
|
|
#undef CPSINGLEVAL
|
|
|
|
#undef CPDATA
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the number of elements to be monitored for changes
|
|
|
|
static int32_t getnumvar(const dataspec_t *spec)
|
|
|
|
{
|
|
|
|
int32_t n=0;
|
2010-02-23 18:13:46 +00:00
|
|
|
for (; spec->flags!=DS_END; spec++)
|
2010-01-24 23:33:17 +00:00
|
|
|
n += (spec->flags&(DS_STRING|DS_CMP|DS_NOCHK|DS_SAVEFN|DS_LOADFN) ? 0 : 1);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update dump at *dumpvar with new state and write diff to *diffvar
|
|
|
|
static void cmpspecdata(const dataspec_t *spec, uint8_t **dumpvar, uint8_t **diffvar)
|
|
|
|
{
|
2012-01-05 20:48:20 +00:00
|
|
|
void *ptr;
|
2010-01-24 23:33:17 +00:00
|
|
|
uint8_t *dump=*dumpvar, *diff=*diffvar, *tmptr;
|
|
|
|
const dataspec_t *sp=spec;
|
2012-11-15 14:28:36 +00:00
|
|
|
int32_t cnt, eltnum=0, nbytes=(getnumvar(spec)+7)>>3, l=Bstrlen((const char *)spec->ptr);
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
Bmemcpy(diff, spec->ptr, l);
|
|
|
|
diff+=l;
|
|
|
|
|
|
|
|
while (nbytes--)
|
|
|
|
*(diff++) = 0; // the bitmap of indices which elements of spec have changed go here
|
|
|
|
|
|
|
|
for (sp++; sp->flags!=DS_END; sp++)
|
|
|
|
{
|
|
|
|
if ((sp->flags&(DS_NOCHK|DS_STRING|DS_CMP)))
|
|
|
|
continue;
|
|
|
|
|
* New m32script commands:
- sethighlightsector <sectnum> <on?>
- updatehighlightsector
- collectsectors <<array_to_collect_sectnums>> <initial_sector> <<num_collected_sectors>> <sector_filtering_state>
The latter does a breadth-first search starting from an initial sector and collects nextsectors only when the filtering state, given a sectnum as RETURN input, writes a nonzero value into RETURN. As a usage example, a.m32 includes the state 'collect_teleporting_sectors', that collects all sectors containing an SE7 and highlights them afterwards. This way, it should be possible to retrofit old maps with TROR by distributing small scripts that do most of the work (right now, joining has to be done by hand, though).
* corruption checker: for the 'nextwall inconsistent with nextsector' corruption, suggest an alternative fix by searching fitting nextwalls and changing the nextwall of the corrupt wall (as opposed to the nextsector). It will display with a leading '?' in the listing, and can be demanded by suffixing 'corruptcheck tryfix' with it. For example,
corruptcheck tryfix 9-21 ?
would fix some corruptions in Billy Boy's cranium.map without introducing drawing errors.
* fix demo playback (tueidj figured this out)
git-svn-id: https://svn.eduke32.com/eduke32@1927 1a8010ca-5511-0410-912e-c29ae57300e0
2011-07-03 22:51:28 +00:00
|
|
|
if (sp->flags&(DS_LOADFN|DS_SAVEFN))
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
* New m32script commands:
- sethighlightsector <sectnum> <on?>
- updatehighlightsector
- collectsectors <<array_to_collect_sectnums>> <initial_sector> <<num_collected_sectors>> <sector_filtering_state>
The latter does a breadth-first search starting from an initial sector and collects nextsectors only when the filtering state, given a sectnum as RETURN input, writes a nonzero value into RETURN. As a usage example, a.m32 includes the state 'collect_teleporting_sectors', that collects all sectors containing an SE7 and highlights them afterwards. This way, it should be possible to retrofit old maps with TROR by distributing small scripts that do most of the work (right now, joining has to be done by hand, though).
* corruption checker: for the 'nextwall inconsistent with nextsector' corruption, suggest an alternative fix by searching fitting nextwalls and changing the nextwall of the corrupt wall (as opposed to the nextsector). It will display with a leading '?' in the listing, and can be demanded by suffixing 'corruptcheck tryfix' with it. For example,
corruptcheck tryfix 9-21 ?
would fix some corruptions in Billy Boy's cranium.map without introducing drawing errors.
* fix demo playback (tueidj figured this out)
git-svn-id: https://svn.eduke32.com/eduke32@1927 1a8010ca-5511-0410-912e-c29ae57300e0
2011-07-03 22:51:28 +00:00
|
|
|
if ((sp->flags&(DS_PROTECTFN))==0)
|
2011-12-25 15:34:06 +00:00
|
|
|
(*(void (*)())sp->ptr)();
|
2010-01-24 23:33:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_get(sp, &ptr, &cnt);
|
|
|
|
if (cnt < 0) { OSD_Printf("csd: cnt=%d, f=0x%x\n", cnt, sp->flags); continue; }
|
|
|
|
|
|
|
|
tmptr = diff;
|
|
|
|
docmpsd(ptr, dump, sp->size, cnt, &diff);
|
|
|
|
if (diff != tmptr)
|
|
|
|
(*diffvar + l)[eltnum>>3] |= 1<<(eltnum&7);
|
|
|
|
dump += sp->size*cnt;
|
|
|
|
eltnum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*diffvar = diff;
|
|
|
|
*dumpvar = dump;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VALOFS(bits,p,ofs) (*(((UINT(bits) *)(p)) + (ofs)))
|
|
|
|
|
|
|
|
// apply diff to dump, not to state! state is restored from dump afterwards.
|
|
|
|
static int32_t applydiff(const dataspec_t *spec, uint8_t **dumpvar, uint8_t **diffvar)
|
|
|
|
{
|
|
|
|
uint8_t *dumptr=*dumpvar, *diffptr=*diffvar;
|
|
|
|
const dataspec_t *sp=spec;
|
2016-08-27 01:41:21 +00:00
|
|
|
bssize_t cnt, eltnum=-1, nbytes=(getnumvar(spec)+7)>>3, l=Bstrlen((const char *)spec->ptr);
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
if (Bmemcmp(diffptr, spec->ptr, l)) // check STRING magic (sync check)
|
|
|
|
return 1;
|
2011-12-21 18:40:47 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
diffptr += l+nbytes;
|
|
|
|
|
|
|
|
for (sp++; sp->flags!=DS_END; sp++)
|
|
|
|
{
|
|
|
|
if ((sp->flags&(DS_NOCHK|DS_STRING|DS_CMP|DS_LOADFN|DS_SAVEFN)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cnt = ds_getcnt(sp);
|
|
|
|
if (cnt < 0) return 1;
|
|
|
|
|
|
|
|
eltnum++;
|
|
|
|
if (((*diffvar + l)[eltnum>>3]&(1<<(eltnum&7))) == 0)
|
|
|
|
{
|
|
|
|
dumptr += sp->size*cnt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
2010-02-23 18:13:46 +00:00
|
|
|
#define CPSINGLEVAL(Datbits) \
|
2016-01-11 05:05:38 +00:00
|
|
|
WVAL(Datbits, dumptr) = VAL(Datbits, diffptr); \
|
2010-01-24 23:33:17 +00:00
|
|
|
diffptr += BYTES(Datbits); \
|
|
|
|
dumptr += BYTES(Datbits)
|
|
|
|
|
|
|
|
if (cnt==1)
|
|
|
|
{
|
|
|
|
switch (sp->size)
|
|
|
|
{
|
|
|
|
case 8: CPSINGLEVAL(64); continue;
|
|
|
|
case 4: CPSINGLEVAL(32); continue;
|
|
|
|
case 2: CPSINGLEVAL(16); continue;
|
|
|
|
case 1: CPSINGLEVAL(8); continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
#define CPELTS(Idxbits, Datbits) do \
|
2010-01-24 23:33:17 +00:00
|
|
|
{ \
|
|
|
|
UINT(Idxbits) idx; \
|
|
|
|
goto readidx_##Idxbits##_##Datbits; \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
VALOFS(Datbits, dumptr, idx) = VAL(Datbits, diffptr); \
|
|
|
|
diffptr += BYTES(Datbits); \
|
|
|
|
readidx_##Idxbits##_##Datbits: \
|
|
|
|
idx = VAL(Idxbits, diffptr); \
|
|
|
|
diffptr += BYTES(Idxbits); \
|
|
|
|
} while ((int##Idxbits##_t)idx != -1); \
|
|
|
|
} while (0)
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
#define CPDATA(Datbits) do \
|
2010-01-24 23:33:17 +00:00
|
|
|
{ \
|
2014-10-25 03:29:21 +00:00
|
|
|
uint32_t nelts=tabledivide32_noinline(sp->size*cnt, BYTES(Datbits)); \
|
2010-01-24 23:33:17 +00:00
|
|
|
if (nelts>65536) \
|
|
|
|
CPELTS(32,Datbits); \
|
|
|
|
else if (nelts>256) \
|
|
|
|
CPELTS(16,Datbits); \
|
|
|
|
else \
|
|
|
|
CPELTS(8,Datbits); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
if (sp->size==8)
|
|
|
|
CPDATA(64);
|
|
|
|
else if ((sp->size&3)==0)
|
|
|
|
CPDATA(32);
|
|
|
|
else if ((sp->size&1)==0)
|
|
|
|
CPDATA(16);
|
|
|
|
else
|
|
|
|
CPDATA(8);
|
|
|
|
dumptr += sp->size*cnt;
|
|
|
|
// ----------
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
#undef CPELTS
|
|
|
|
#undef CPSINGLEVAL
|
|
|
|
#undef CPDATA
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*diffvar = diffptr;
|
|
|
|
*dumpvar = dumptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef VAL
|
|
|
|
#undef VALOFS
|
|
|
|
#undef BYTES
|
|
|
|
#undef UINT
|
|
|
|
|
|
|
|
// calculate size needed for dump
|
|
|
|
static uint32_t calcsz(const dataspec_t *spec)
|
|
|
|
{
|
|
|
|
const dataspec_t *sp=spec;
|
2016-08-27 01:41:21 +00:00
|
|
|
bssize_t cnt;
|
2010-01-24 23:33:17 +00:00
|
|
|
uint32_t dasiz=0;
|
|
|
|
|
|
|
|
for (; sp->flags!=DS_END; sp++)
|
|
|
|
{
|
|
|
|
// DS_STRINGs are used as sync checks in the diffs but not in the dump
|
|
|
|
if ((sp->flags&(DS_CMP|DS_NOCHK|DS_SAVEFN|DS_LOADFN|DS_STRING)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cnt = ds_getcnt(sp);
|
|
|
|
if (cnt<=0) continue;
|
|
|
|
|
|
|
|
dasiz += cnt*sp->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dasiz;
|
|
|
|
}
|
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2010-01-25 01:11:34 +00:00
|
|
|
static void sv_prespriteextsave();
|
|
|
|
static void sv_postspriteext();
|
2011-02-27 22:11:39 +00:00
|
|
|
#endif
|
2013-02-03 12:48:17 +00:00
|
|
|
#if !defined LUNATIC
|
2010-01-25 01:11:34 +00:00
|
|
|
static void sv_calcbitptrsize();
|
|
|
|
static void sv_prescriptsave_once();
|
2010-02-13 21:46:42 +00:00
|
|
|
static void sv_prescriptload_once();
|
2010-01-25 01:11:34 +00:00
|
|
|
static void sv_postscript_once();
|
2013-06-07 10:18:17 +00:00
|
|
|
#else
|
|
|
|
// Recreate Lua state.
|
|
|
|
// 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.
|
|
|
|
static void sv_create_lua_state(void)
|
|
|
|
{
|
|
|
|
El_CreateGameState();
|
|
|
|
G_PostCreateGameState();
|
|
|
|
}
|
2013-02-03 12:48:17 +00:00
|
|
|
#endif
|
2010-01-25 01:11:34 +00:00
|
|
|
static void sv_preactordatasave();
|
|
|
|
static void sv_postactordata();
|
|
|
|
static void sv_preanimateptrsave();
|
|
|
|
static void sv_postanimateptr();
|
|
|
|
static void sv_prequote();
|
|
|
|
static void sv_quotesave();
|
|
|
|
static void sv_quoteload();
|
|
|
|
static void sv_prequoteredef();
|
|
|
|
static void sv_quoteredefsave();
|
|
|
|
static void sv_quoteredefload();
|
|
|
|
static void sv_postquoteredef();
|
|
|
|
static void sv_restsave();
|
|
|
|
static void sv_restload();
|
2015-03-24 00:40:55 +00:00
|
|
|
static void sv_preprojectilesave();
|
|
|
|
static void sv_postprojectilesave();
|
|
|
|
static void sv_preprojectileload();
|
|
|
|
static void sv_postprojectileload();
|
|
|
|
|
|
|
|
static projectile_t *ProjectileData;
|
2010-01-25 01:11:34 +00:00
|
|
|
|
|
|
|
#define SVARDATALEN \
|
|
|
|
((sizeof(g_player[0].user_name)+sizeof(g_player[0].pcolor)+sizeof(g_player[0].pteam) \
|
2012-12-09 13:24:32 +00:00
|
|
|
+sizeof(g_player[0].frags)+sizeof(DukePlayer_t))*MAXPLAYERS)
|
2010-01-25 01:11:34 +00:00
|
|
|
|
2013-06-07 10:18:17 +00:00
|
|
|
#if !defined LUNATIC
|
2010-01-25 01:11:34 +00:00
|
|
|
static uint32_t savegame_bitptrsize;
|
2013-06-07 10:18:17 +00:00
|
|
|
#endif
|
2010-01-25 01:11:34 +00:00
|
|
|
static uint8_t savegame_quotedef[MAXQUOTES>>3];
|
2010-02-23 18:13:46 +00:00
|
|
|
static char(*savegame_quotes)[MAXQUOTELEN];
|
|
|
|
static char(*savegame_quoteredefs)[MAXQUOTELEN];
|
2010-01-25 01:11:34 +00:00
|
|
|
static uint8_t savegame_restdata[SVARDATALEN];
|
|
|
|
|
2016-01-11 05:05:38 +00:00
|
|
|
static char svgm_udnetw_string [] = "blK:udnt";
|
2010-01-25 01:11:34 +00:00
|
|
|
static const dataspec_t svgm_udnetw[] =
|
|
|
|
{
|
2016-01-11 05:05:38 +00:00
|
|
|
{ DS_STRING, (void *)svgm_udnetw_string, 0, 1 },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ 0, &ud.multimode, sizeof(ud.multimode), 1 },
|
2016-08-27 01:42:01 +00:00
|
|
|
{ 0, &g_playerSpawnCnt, sizeof(g_playerSpawnCnt), 1 },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ 0, &g_playerSpawnPoints, sizeof(g_playerSpawnPoints), 1 },
|
|
|
|
|
|
|
|
{ DS_NOCHK, &ud.volume_number, sizeof(ud.volume_number), 1 },
|
|
|
|
{ DS_NOCHK, &ud.level_number, sizeof(ud.level_number), 1 },
|
|
|
|
{ DS_NOCHK, &ud.player_skill, sizeof(ud.player_skill), 1 },
|
|
|
|
|
|
|
|
{ DS_NOCHK, &ud.from_bonus, sizeof(ud.from_bonus), 1 },
|
|
|
|
{ DS_NOCHK, &ud.secretlevel, sizeof(ud.secretlevel), 1 },
|
|
|
|
{ DS_NOCHK, &ud.respawn_monsters, sizeof(ud.respawn_monsters), 1 },
|
|
|
|
{ DS_NOCHK, &ud.respawn_items, sizeof(ud.respawn_items), 1 },
|
|
|
|
{ DS_NOCHK, &ud.respawn_inventory, sizeof(ud.respawn_inventory), 1 },
|
|
|
|
{ 0, &ud.god, sizeof(ud.god), 1 },
|
|
|
|
{ 0, &ud.auto_run, sizeof(ud.auto_run), 1 },
|
|
|
|
// { DS_NOCHK, &ud.crosshair, sizeof(ud.crosshair), 1 },
|
|
|
|
{ DS_NOCHK, &ud.monsters_off, sizeof(ud.monsters_off), 1 },
|
|
|
|
{ DS_NOCHK, &ud.last_level, sizeof(ud.last_level), 1 },
|
|
|
|
{ 0, &ud.eog, sizeof(ud.eog), 1 },
|
|
|
|
{ DS_NOCHK, &ud.coop, sizeof(ud.coop), 1 },
|
|
|
|
{ DS_NOCHK, &ud.marker, sizeof(ud.marker), 1 },
|
|
|
|
{ DS_NOCHK, &ud.ffire, sizeof(ud.ffire), 1 },
|
|
|
|
{ DS_NOCHK, &ud.noexits, sizeof(ud.noexits), 1 },
|
|
|
|
{ DS_NOCHK, &ud.playerai, sizeof(ud.playerai), 1 },
|
2010-02-13 21:46:42 +00:00
|
|
|
{ 0, &ud.pause_on, sizeof(ud.pause_on), 1 },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_NOCHK, ¤tboardfilename[0], BMAX_PATH, 1 },
|
2011-12-25 15:34:06 +00:00
|
|
|
// { DS_LOADFN, (void *)&sv_postudload, 0, 1 },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ 0, connectpoint2, sizeof(connectpoint2), 1 },
|
|
|
|
{ 0, &randomseed, sizeof(randomseed), 1 },
|
|
|
|
{ 0, &g_globalRandom, sizeof(g_globalRandom), 1 },
|
2013-07-04 19:38:46 +00:00
|
|
|
#ifdef LUNATIC
|
|
|
|
// Save game tic count for Lunatic because it is exposed to userland. See
|
|
|
|
// test/helixspawner.lua for an example.
|
|
|
|
{ 0, &g_moveThingsCount, sizeof(g_moveThingsCount), 1 },
|
|
|
|
#endif
|
2010-01-25 01:11:34 +00:00
|
|
|
// { 0, &lockclock_dummy, sizeof(lockclock), 1 },
|
|
|
|
{ DS_END, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
Inreased debugging level for catching oob accesses to 'main' arrays.
If enabled, this makes the following arrays be allocated statically:
spriteext, spritesmooth, sector, wall, sprite, tsprite, while
necessarily disabling the clipshape feature (because it relies on
setting sector/wall to different malloc'd block temporarily).
To compile, pass DEBUGANYWAY=1 in addition to RELEASE=0 to 'make',
and it's really only useful with CC=clang, of course.
git-svn-id: https://svn.eduke32.com/eduke32@2270 1a8010ca-5511-0410-912e-c29ae57300e0
2012-01-19 23:17:34 +00:00
|
|
|
#if !defined DEBUG_MAIN_ARRAYS
|
|
|
|
# define DS_MAINAR DS_DYNAMIC
|
|
|
|
#else
|
|
|
|
# define DS_MAINAR 0
|
|
|
|
#endif
|
|
|
|
|
2016-01-11 05:05:38 +00:00
|
|
|
static char svgm_secwsp_string [] = "blK:swsp";
|
2010-01-25 01:11:34 +00:00
|
|
|
static const dataspec_t svgm_secwsp[] =
|
|
|
|
{
|
2016-01-11 05:05:38 +00:00
|
|
|
{ DS_STRING, (void *)svgm_secwsp_string, 0, 1 },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_NOCHK, &numwalls, sizeof(numwalls), 1 },
|
Inreased debugging level for catching oob accesses to 'main' arrays.
If enabled, this makes the following arrays be allocated statically:
spriteext, spritesmooth, sector, wall, sprite, tsprite, while
necessarily disabling the clipshape feature (because it relies on
setting sector/wall to different malloc'd block temporarily).
To compile, pass DEBUGANYWAY=1 in addition to RELEASE=0 to 'make',
and it's really only useful with CC=clang, of course.
git-svn-id: https://svn.eduke32.com/eduke32@2270 1a8010ca-5511-0410-912e-c29ae57300e0
2012-01-19 23:17:34 +00:00
|
|
|
{ DS_MAINAR|DS_CNT(numwalls), &wall, sizeof(walltype), (intptr_t)&numwalls },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_NOCHK, &numsectors, sizeof(numsectors), 1 },
|
Inreased debugging level for catching oob accesses to 'main' arrays.
If enabled, this makes the following arrays be allocated statically:
spriteext, spritesmooth, sector, wall, sprite, tsprite, while
necessarily disabling the clipshape feature (because it relies on
setting sector/wall to different malloc'd block temporarily).
To compile, pass DEBUGANYWAY=1 in addition to RELEASE=0 to 'make',
and it's really only useful with CC=clang, of course.
git-svn-id: https://svn.eduke32.com/eduke32@2270 1a8010ca-5511-0410-912e-c29ae57300e0
2012-01-19 23:17:34 +00:00
|
|
|
{ DS_MAINAR|DS_CNT(numsectors), §or, sizeof(sectortype), (intptr_t)&numsectors },
|
|
|
|
{ DS_MAINAR, &sprite, sizeof(spritetype), MAXSPRITES },
|
2011-05-12 23:31:13 +00:00
|
|
|
#ifdef YAX_ENABLE
|
|
|
|
{ DS_NOCHK, &numyaxbunches, sizeof(numyaxbunches), 1 },
|
2013-04-09 17:35:11 +00:00
|
|
|
# if !defined NEW_MAP_FORMAT
|
2011-05-12 23:31:13 +00:00
|
|
|
{ DS_CNT(numsectors), yax_bunchnum, sizeof(yax_bunchnum[0]), (intptr_t)&numsectors },
|
|
|
|
{ DS_CNT(numwalls), yax_nextwall, sizeof(yax_nextwall[0]), (intptr_t)&numwalls },
|
2013-04-09 17:35:11 +00:00
|
|
|
# endif
|
2011-05-12 23:31:13 +00:00
|
|
|
{ DS_LOADFN|DS_PROTECTFN, (void *)&sv_postyaxload, 0, 1 },
|
|
|
|
#endif
|
2012-03-14 22:31:49 +00:00
|
|
|
{ 0, &Numsprites, sizeof(Numsprites), 1 },
|
2012-03-13 20:07:17 +00:00
|
|
|
{ 0, &tailspritefree, sizeof(tailspritefree), 1 },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ 0, &headspritesect[0], sizeof(headspritesect[0]), MAXSECTORS+1 },
|
|
|
|
{ 0, &prevspritesect[0], sizeof(prevspritesect[0]), MAXSPRITES },
|
|
|
|
{ 0, &nextspritesect[0], sizeof(nextspritesect[0]), MAXSPRITES },
|
|
|
|
{ 0, &headspritestat[0], sizeof(headspritestat[0]), MAXSTATUS+1 },
|
|
|
|
{ 0, &prevspritestat[0], sizeof(prevspritestat[0]), MAXSPRITES },
|
|
|
|
{ 0, &nextspritestat[0], sizeof(nextspritestat[0]), MAXSPRITES },
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_SAVEFN, (void *)&sv_prespriteextsave, 0, 1 },
|
|
|
|
#endif
|
Inreased debugging level for catching oob accesses to 'main' arrays.
If enabled, this makes the following arrays be allocated statically:
spriteext, spritesmooth, sector, wall, sprite, tsprite, while
necessarily disabling the clipshape feature (because it relies on
setting sector/wall to different malloc'd block temporarily).
To compile, pass DEBUGANYWAY=1 in addition to RELEASE=0 to 'make',
and it's really only useful with CC=clang, of course.
git-svn-id: https://svn.eduke32.com/eduke32@2270 1a8010ca-5511-0410-912e-c29ae57300e0
2012-01-19 23:17:34 +00:00
|
|
|
{ DS_MAINAR, &spriteext, sizeof(spriteext_t), MAXSPRITES },
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_SAVEFN|DS_LOADFN, (void *)&sv_postspriteext, 0, 1 },
|
|
|
|
#endif
|
|
|
|
{ 0, &DynamicTileMap[0], sizeof(DynamicTileMap[0]), MAXTILES }, // NOCHK?
|
2013-06-01 06:55:30 +00:00
|
|
|
{ 0, &DynamicSoundMap[0], sizeof(DynamicSoundMap[0]), MAXSOUNDS }, // NOCHK?
|
2016-08-27 01:42:01 +00:00
|
|
|
{ DS_NOCHK, &g_cyclerCnt, sizeof(g_cyclerCnt), 1 },
|
|
|
|
{ DS_CNT(g_cyclerCnt), &g_cyclers[0][0], sizeof(g_cyclers[0]), (intptr_t)&g_cyclerCnt },
|
|
|
|
{ DS_NOCHK, &g_animWallCnt, sizeof(g_animWallCnt), 1 },
|
|
|
|
{ DS_CNT(g_animWallCnt), &animwall, sizeof(animwall[0]), (intptr_t)&g_animWallCnt },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_NOCHK, &g_mirrorCount, sizeof(g_mirrorCount), 1 },
|
2014-03-22 09:25:15 +00:00
|
|
|
{ DS_NOCHK, &g_mirrorWall[0], sizeof(g_mirrorWall[0]), ARRAY_SIZE(g_mirrorWall) },
|
|
|
|
{ DS_NOCHK, &g_mirrorSector[0], sizeof(g_mirrorSector[0]), ARRAY_SIZE(g_mirrorSector) },
|
2010-01-25 01:11:34 +00:00
|
|
|
// projectiles
|
|
|
|
{ 0, &SpriteProjectile[0], sizeof(projectile_t), MAXSPRITES },
|
|
|
|
{ 0, &everyothertime, sizeof(everyothertime), 1 },
|
|
|
|
{ DS_END, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2016-01-11 05:05:38 +00:00
|
|
|
static char svgm_script_string [] = "blK:scri";
|
2010-01-25 01:11:34 +00:00
|
|
|
static const dataspec_t svgm_script[] =
|
|
|
|
{
|
2016-01-11 05:05:38 +00:00
|
|
|
{ DS_STRING, (void *)svgm_script_string, 0, 1 },
|
2013-02-03 12:48:17 +00:00
|
|
|
#if !defined LUNATIC
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_NOCHK, &g_scriptSize, sizeof(g_scriptSize), 1 },
|
|
|
|
{ DS_SAVEFN|DS_LOADFN|DS_NOCHK, (void *)&sv_calcbitptrsize, 0, 1 },
|
|
|
|
{ DS_DYNAMIC|DS_CNT(savegame_bitptrsize)|DS_NOCHK, &bitptr, sizeof(bitptr[0]), (intptr_t)&savegame_bitptrsize },
|
|
|
|
|
|
|
|
{ DS_SAVEFN|DS_NOCHK, (void *)&sv_prescriptsave_once, 0, 1 },
|
2013-02-03 12:48:17 +00:00
|
|
|
#endif
|
2015-03-24 00:40:55 +00:00
|
|
|
{ DS_SAVEFN, (void *) &sv_preprojectilesave, 0, 1 },
|
|
|
|
{ DS_LOADFN, (void *) &sv_preprojectileload, 0, 1 },
|
2015-05-16 11:56:49 +00:00
|
|
|
{ DS_NOCHK, &g_tile[0], sizeof(tiledata_t), MAXTILES },
|
2015-03-24 00:40:55 +00:00
|
|
|
{ DS_DYNAMIC|DS_CNT(g_numProjectiles), &ProjectileData, sizeof(projectile_t), (intptr_t)&g_numProjectiles },
|
|
|
|
{ DS_SAVEFN, (void *) &sv_postprojectilesave, 0, 1 },
|
|
|
|
{ DS_LOADFN, (void *) &sv_postprojectileload, 0, 1 },
|
2013-02-03 12:48:17 +00:00
|
|
|
#if !defined LUNATIC
|
2010-02-13 21:46:42 +00:00
|
|
|
{ DS_LOADFN|DS_NOCHK, (void *)&sv_prescriptload_once, 0, 1 },
|
2016-08-27 01:40:35 +00:00
|
|
|
{ DS_DYNAMIC|DS_CNT(g_scriptSize)|DS_NOCHK, &apScript, sizeof(apScript[0]), (intptr_t)&g_scriptSize },
|
2010-01-25 01:11:34 +00:00
|
|
|
// { DS_NOCHK, &apScriptGameEvent[0], sizeof(apScriptGameEvent[0]), MAXGAMEEVENTS },
|
|
|
|
{ DS_SAVEFN|DS_LOADFN|DS_NOCHK, (void *)&sv_postscript_once, 0, 1 },
|
2013-02-03 12:48:17 +00:00
|
|
|
#endif
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_SAVEFN, (void *)&sv_preactordatasave, 0, 1 },
|
2010-08-02 08:13:51 +00:00
|
|
|
{ 0, &actor[0], sizeof(actor_t), MAXSPRITES },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_SAVEFN|DS_LOADFN, (void *)&sv_postactordata, 0, 1 },
|
2013-06-07 10:18:17 +00:00
|
|
|
#if defined LUNATIC
|
|
|
|
{ DS_LOADFN|DS_NOCHK, (void *)&sv_create_lua_state, 0, 1 },
|
|
|
|
#endif
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_END, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2016-01-11 05:05:38 +00:00
|
|
|
static char svgm_anmisc_string [] = "blK:anms";
|
|
|
|
static char svgm_end_string [] = "savegame_end";
|
|
|
|
|
2010-01-25 01:11:34 +00:00
|
|
|
static const dataspec_t svgm_anmisc[] =
|
|
|
|
{
|
2016-01-11 05:05:38 +00:00
|
|
|
{ DS_STRING, (void *)svgm_anmisc_string, 0, 1 },
|
2016-08-27 01:42:01 +00:00
|
|
|
{ 0, &g_animateCnt, sizeof(g_animateCnt), 1 },
|
|
|
|
{ 0, &g_animateSect[0], sizeof(g_animateSect[0]), MAXANIMATES },
|
|
|
|
{ 0, &g_animateGoal[0], sizeof(g_animateGoal[0]), MAXANIMATES },
|
|
|
|
{ 0, &g_animateVel[0], sizeof(g_animateVel[0]), MAXANIMATES },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_SAVEFN, (void *)&sv_preanimateptrsave, 0, 1 },
|
2016-08-27 01:42:01 +00:00
|
|
|
{ 0, &g_animatePtr[0], sizeof(g_animatePtr[0]), MAXANIMATES },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_SAVEFN|DS_LOADFN , (void *)&sv_postanimateptr, 0, 1 },
|
2013-12-26 19:45:12 +00:00
|
|
|
{ 0, &g_curViewscreen, sizeof(g_curViewscreen), 1 },
|
2016-01-21 19:35:30 +00:00
|
|
|
{ 0, &g_origins[0], sizeof(g_origins[0]), ARRAY_SIZE(g_origins) },
|
2010-02-13 21:46:42 +00:00
|
|
|
{ 0, &g_spriteDeleteQueuePos, sizeof(g_spriteDeleteQueuePos), 1 },
|
2016-08-27 01:40:35 +00:00
|
|
|
{ DS_NOCHK, &g_deleteQueueSize, sizeof(g_deleteQueueSize), 1 },
|
|
|
|
{ DS_CNT(g_deleteQueueSize), &SpriteDeletionQueue[0], sizeof(int16_t), (intptr_t)&g_deleteQueueSize },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ 0, &show2dsector[0], sizeof(uint8_t), MAXSECTORS>>3 },
|
2016-08-27 01:42:01 +00:00
|
|
|
{ DS_NOCHK, &g_cloudCnt, sizeof(g_cloudCnt), 1 },
|
|
|
|
{ 0, &g_cloudSect[0], sizeof(g_cloudSect), 1 },
|
|
|
|
{ 0, &g_cloudX, sizeof(g_cloudX), 1 },
|
|
|
|
{ 0, &g_cloudY, sizeof(g_cloudY), 1 },
|
Clean up parallaxed sky functionality, part 2.
- Rename sky_t members: yscale -> horizfrac, bits -> lognumtiles.
- Add default sky (8 tiles, horizfrac=32768 (i.e. 1/2 the scene horiz), offsets
all zero) and CLOUDYOCEAN sky (8 tiles, horizfrac=65536, offsets all zero)
to multipsky[].
- Get rid of "psky_t g_psky", merely maintaining a g_pskyidx instead. Set it up
at map load time so as to keep the behavior of the legacy per-map psky:
the last sector index with a matching psky ceiling wins.
- In mapstate_t, save g_pskyidx too, not (former) pskybits and pskyoffs[].
- Make on-map-load global psky setup consistent for the game and editor by
factoring it out into common.c: G_SetupGlobalPsky().
- Remove a couple of useless initializations, add some static assertions.
This commit is more likely to introduce subtle differences in behavior.
Specifically, getpsky() now always returns the default sky properties instead of
the global sky ones (but with all-zero offsets) when no match for a suiting
multi-psky is found. This is only likely to affect the yscale/horizfrac of
non-multi-pskies when a global non-default multi-psky has been set up.
Bump BYTEVERSION again.
git-svn-id: https://svn.eduke32.com/eduke32@3976 1a8010ca-5511-0410-912e-c29ae57300e0
2013-08-04 20:37:48 +00:00
|
|
|
{ 0, &g_pskyidx, sizeof(g_pskyidx), 1 }, // DS_NOCHK?
|
2010-01-25 01:11:34 +00:00
|
|
|
{ 0, &g_earthquakeTime, sizeof(g_earthquakeTime), 1 },
|
|
|
|
|
|
|
|
{ DS_SAVEFN|DS_LOADFN|DS_NOCHK, (void *)sv_prequote, 0, 1 },
|
|
|
|
{ DS_SAVEFN, (void *)&sv_quotesave, 0, 1 },
|
|
|
|
{ DS_NOCHK, &savegame_quotedef, sizeof(savegame_quotedef), 1 }, // quotes can change during runtime, but new quote numbers cannot be allocated
|
|
|
|
{ DS_DYNAMIC, &savegame_quotes, MAXQUOTELEN, MAXQUOTES },
|
|
|
|
{ DS_LOADFN, (void *)&sv_quoteload, 0, 1 },
|
|
|
|
|
2016-08-27 01:40:35 +00:00
|
|
|
{ DS_NOCHK, &g_numXStrings, sizeof(g_numXStrings), 1 },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_NOCHK|DS_SAVEFN|DS_LOADFN, (void *)&sv_prequoteredef, 0, 1 },
|
|
|
|
{ DS_NOCHK|DS_SAVEFN, (void *)&sv_quoteredefsave, 0, 1 }, // quote redefinitions replace quotes at runtime, but cannot be changed after CON compilation
|
2016-08-27 01:40:35 +00:00
|
|
|
{ DS_NOCHK|DS_DYNAMIC|DS_CNT(g_numXStrings), &savegame_quoteredefs, MAXQUOTELEN, (intptr_t)&g_numXStrings },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_NOCHK|DS_LOADFN, (void *)&sv_quoteredefload, 0, 1 },
|
|
|
|
{ DS_NOCHK|DS_SAVEFN|DS_LOADFN, (void *)&sv_postquoteredef, 0, 1 },
|
2013-06-13 17:11:09 +00:00
|
|
|
#ifdef LUNATIC
|
|
|
|
{ 0, g_playerWeapon, sizeof(weapondata_t), MAXPLAYERS*MAX_WEAPONS },
|
|
|
|
#endif
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_SAVEFN, (void *)&sv_restsave, 0, 1 },
|
|
|
|
{ 0, savegame_restdata, 1, sizeof(savegame_restdata) }, // sz/cnt swapped for kdfread
|
|
|
|
{ DS_LOADFN, (void *)&sv_restload, 0, 1 },
|
|
|
|
|
2016-01-11 05:05:38 +00:00
|
|
|
{ DS_STRING, (void *)svgm_end_string, 0, 1 },
|
2010-01-25 01:11:34 +00:00
|
|
|
{ DS_END, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-05-19 19:29:18 +00:00
|
|
|
#if !defined LUNATIC
|
2016-01-11 05:05:38 +00:00
|
|
|
static dataspec_gv_t *svgm_vars=NULL;
|
2013-05-19 19:29:18 +00:00
|
|
|
#endif
|
2011-12-25 15:34:06 +00:00
|
|
|
static uint8_t *dosaveplayer2(FILE *fil, uint8_t *mem);
|
|
|
|
static int32_t doloadplayer2(int32_t fil, uint8_t **memptr);
|
|
|
|
static void postloadplayer(int32_t savegamep);
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
// SVGM snapshot system
|
|
|
|
static uint32_t svsnapsiz;
|
|
|
|
static uint8_t *svsnapshot, *svinitsnap;
|
|
|
|
static uint32_t svdiffsiz;
|
|
|
|
static uint8_t *svdiff;
|
|
|
|
|
|
|
|
#include "gamedef.h"
|
|
|
|
|
2013-05-19 19:29:18 +00:00
|
|
|
#if !defined LUNATIC
|
|
|
|
# define SV_SKIPMASK (/*GAMEVAR_SYSTEM|*/GAMEVAR_READONLY|GAMEVAR_INTPTR| \
|
|
|
|
GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR /*|GAMEVAR_NORESET*/ |GAMEVAR_SPECIAL)
|
2016-01-11 05:06:10 +00:00
|
|
|
|
|
|
|
static char svgm_vars_string [] = "blK:vars";
|
2010-01-24 23:33:17 +00:00
|
|
|
// setup gamevar data spec for snapshotting and diffing... gamevars must be loaded when called
|
|
|
|
static void sv_makevarspec()
|
|
|
|
{
|
2016-01-11 05:06:10 +00:00
|
|
|
static char *magic = svgm_vars_string;
|
2013-12-06 18:56:39 +00:00
|
|
|
int32_t i, j, numsavedvars=0, numsavedarrays=0, per;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
for (i=0; i<g_gameVarCount; i++)
|
2016-08-27 01:40:35 +00:00
|
|
|
numsavedvars += (aGameVars[i].flags&SV_SKIPMASK) ? 0 : 1;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2013-12-06 18:56:39 +00:00
|
|
|
for (i=0; i<g_gameArrayCount; i++)
|
2016-08-27 01:40:35 +00:00
|
|
|
numsavedarrays += !(aGameArrays[i].flags & GAMEARRAY_READONLY); // SYSTEM_GAMEARRAY
|
2013-12-06 18:56:39 +00:00
|
|
|
|
2013-05-24 13:54:32 +00:00
|
|
|
Bfree(svgm_vars);
|
2016-01-11 05:05:38 +00:00
|
|
|
svgm_vars = (dataspec_gv_t *)Xmalloc((numsavedvars+numsavedarrays+2)*sizeof(dataspec_gv_t));
|
2013-05-24 13:54:32 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
svgm_vars[0].flags = DS_STRING;
|
|
|
|
svgm_vars[0].ptr = magic;
|
|
|
|
svgm_vars[0].cnt = 1;
|
|
|
|
|
|
|
|
j=1;
|
|
|
|
for (i=0; i<g_gameVarCount; i++)
|
|
|
|
{
|
2016-08-27 01:40:35 +00:00
|
|
|
if (aGameVars[i].flags&SV_SKIPMASK)
|
2010-01-24 23:33:17 +00:00
|
|
|
continue;
|
|
|
|
|
2016-08-27 01:40:35 +00:00
|
|
|
per = aGameVars[i].flags&GAMEVAR_USER_MASK;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
svgm_vars[j].flags = 0;
|
2016-08-27 01:40:35 +00:00
|
|
|
svgm_vars[j].ptr = (per==0) ? &aGameVars[i].global : aGameVars[i].pValues;
|
2010-01-24 23:33:17 +00:00
|
|
|
svgm_vars[j].size = sizeof(intptr_t);
|
|
|
|
svgm_vars[j].cnt = (per==0) ? 1 : (per==GAMEVAR_PERPLAYER ? MAXPLAYERS : MAXSPRITES);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<g_gameArrayCount; i++)
|
|
|
|
{
|
2013-12-06 18:56:39 +00:00
|
|
|
// We must not update read-only SYSTEM_GAMEARRAY gamearrays: besides
|
|
|
|
// being questionable by itself, sizeof(...) may be e.g. 4 whereas the
|
|
|
|
// actual element type is int16_t (such as tilesizx[]/tilesizy[]).
|
2016-08-27 01:40:35 +00:00
|
|
|
if (aGameArrays[i].flags & GAMEARRAY_READONLY)
|
2013-12-06 18:56:39 +00:00
|
|
|
continue;
|
|
|
|
|
2016-08-27 01:40:06 +00:00
|
|
|
intptr_t * const plValues = aGameArrays[i].pValues;
|
2010-01-24 23:33:17 +00:00
|
|
|
svgm_vars[j].flags = 0;
|
2015-09-24 06:31:55 +00:00
|
|
|
svgm_vars[j].ptr = plValues;
|
2016-08-27 01:40:06 +00:00
|
|
|
svgm_vars[j].size = plValues == NULL ? 0 : sizeof(aGameArrays[0].pValues[0]);
|
2010-01-24 23:33:17 +00:00
|
|
|
svgm_vars[j].cnt = aGameArrays[i].size; // assumed constant throughout demo, i.e. no RESIZEARRAY
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
svgm_vars[j].flags = DS_END;
|
2013-12-06 18:56:39 +00:00
|
|
|
svgm_vars[j].ptr = NULL;
|
|
|
|
svgm_vars[j].size = svgm_vars[j].cnt = 0;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
2013-05-19 19:29:18 +00:00
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
void sv_freemem()
|
|
|
|
{
|
2015-02-11 05:22:23 +00:00
|
|
|
DO_FREE_AND_NULL(svsnapshot);
|
|
|
|
DO_FREE_AND_NULL(svinitsnap);
|
|
|
|
DO_FREE_AND_NULL(svdiff);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
static void SV_AllocSnap(int32_t allocinit)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
|
|
|
sv_freemem();
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
svsnapshot = (uint8_t *)Xmalloc(svsnapsiz);
|
2010-01-24 23:33:17 +00:00
|
|
|
if (allocinit)
|
2014-05-30 00:02:19 +00:00
|
|
|
svinitsnap = (uint8_t *)Xmalloc(svsnapsiz);
|
2010-01-24 23:33:17 +00:00
|
|
|
svdiffsiz = svsnapsiz; // theoretically it's less than could be needed in the worst case, but practically it's overkill
|
2014-05-30 00:02:19 +00:00
|
|
|
svdiff = (uint8_t *)Xmalloc(svdiffsiz);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
2015-02-11 05:22:23 +00:00
|
|
|
EDUKE32_STATIC_ASSERT(sizeof(savehead_t) == SAVEHEAD_SIZE);
|
2013-04-05 17:53:14 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
// make snapshot only if spot < 0 (demo)
|
|
|
|
int32_t sv_saveandmakesnapshot(FILE *fil, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress)
|
|
|
|
{
|
|
|
|
savehead_t h;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
// set a few savegame system globals
|
2010-01-24 23:33:17 +00:00
|
|
|
savegame_comprthres = SV_DEFAULTCOMPRTHRES;
|
2011-12-25 15:34:06 +00:00
|
|
|
savegame_diffcompress = diffcompress;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
// calculate total snapshot size
|
2013-05-19 19:29:18 +00:00
|
|
|
#if !defined LUNATIC
|
2010-01-24 23:33:17 +00:00
|
|
|
sv_makevarspec();
|
2016-01-11 05:05:38 +00:00
|
|
|
svsnapsiz = calcsz((const dataspec_t *)svgm_vars);
|
2013-05-19 19:29:18 +00:00
|
|
|
#else
|
|
|
|
svsnapsiz = 0;
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
svsnapsiz += calcsz(svgm_udnetw) + calcsz(svgm_secwsp) + calcsz(svgm_script) + calcsz(svgm_anmisc);
|
|
|
|
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
// create header
|
|
|
|
Bmemcpy(h.headerstr, "EDuke32SAVE", 11);
|
|
|
|
h.majorver = SV_MAJOR_VER;
|
|
|
|
h.minorver = SV_MINOR_VER;
|
|
|
|
h.ptrsize = sizeof(intptr_t);
|
|
|
|
h.bytever = BYTEVERSION;
|
|
|
|
|
|
|
|
h.comprthres = savegame_comprthres;
|
|
|
|
h.recdiffsp = recdiffsp;
|
|
|
|
h.diffcompress = savegame_diffcompress;
|
|
|
|
h.synccompress = synccompress;
|
|
|
|
|
|
|
|
h.reccnt = 0;
|
|
|
|
h.snapsiz = svsnapsiz;
|
|
|
|
|
|
|
|
// the following is kinda redundant, but we save it here to be able to quickly fetch
|
|
|
|
// it in a savegame header read
|
|
|
|
h.numplayers = ud.multimode;
|
|
|
|
h.volnum = ud.volume_number;
|
|
|
|
h.levnum = ud.level_number;
|
|
|
|
h.skill = ud.player_skill;
|
2014-09-07 18:10:15 +00:00
|
|
|
|
2015-04-20 20:46:42 +00:00
|
|
|
const uint32_t BSZ = sizeof(h.boardfn);
|
|
|
|
EDUKE32_STATIC_ASSERT(BSZ == sizeof(currentboardfilename));
|
|
|
|
Bstrncpy(h.boardfn, currentboardfilename, BSZ);
|
|
|
|
|
2014-09-07 18:10:15 +00:00
|
|
|
if (currentboardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0)
|
|
|
|
{
|
|
|
|
// Shoehorn currently playing music into last bytes of board name buffer.
|
|
|
|
// SAVEGAME_MUSIC.
|
|
|
|
if (g_musicIndex != (0*MAXLEVELS+7) && Bstrlen(h.boardfn) < BSZ-2)
|
|
|
|
{
|
|
|
|
h.boardfn[BSZ-2] = g_musicIndex / MAXLEVELS;
|
|
|
|
h.boardfn[BSZ-1] = g_musicIndex % MAXLEVELS;
|
|
|
|
}
|
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
|
2014-05-17 12:36:40 +00:00
|
|
|
if ((unsigned)spot < MAXSAVEGAMES)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
// savegame
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(h.savename, ud.savegame[spot], sizeof(h.savename));
|
2015-02-11 05:22:23 +00:00
|
|
|
#ifdef __ANDROID__
|
2016-08-27 01:42:01 +00:00
|
|
|
Bstrncpyz(h.volname, g_volumeNames[ud.volume_number], sizeof(h.volname));
|
|
|
|
Bstrncpyz(h.skillname, g_skillNames[ud.player_skill], sizeof(h.skillname));
|
2015-02-11 05:22:23 +00:00
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// demo
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
const time_t t=time(NULL);
|
|
|
|
struct tm *st;
|
|
|
|
|
2013-11-04 18:21:09 +00:00
|
|
|
Bstrncpyz(h.savename, "EDuke32 demo", sizeof(h.savename));
|
2011-12-25 15:34:06 +00:00
|
|
|
if (t>=0 && (st = localtime(&t)))
|
2013-11-04 18:21:09 +00:00
|
|
|
Bsnprintf(h.savename, sizeof(h.savename), "Demo %04d%02d%02d %s",
|
|
|
|
st->tm_year+1900, st->tm_mon+1, st->tm_mday, s_buildRev);
|
2011-12-25 15:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// write header
|
|
|
|
fwrite(&h, sizeof(savehead_t), 1, fil);
|
|
|
|
|
|
|
|
// for savegames, the file offset after the screenshot goes here;
|
|
|
|
// for demos, we keep it 0 to signify that we didn't save one
|
|
|
|
fwrite("\0\0\0\0", 4, 1, fil);
|
|
|
|
if (spot >= 0 && waloff[TILE_SAVESHOT])
|
|
|
|
{
|
|
|
|
int32_t ofs;
|
|
|
|
|
|
|
|
// write the screenshot compressed
|
|
|
|
dfwrite((char *)waloff[TILE_SAVESHOT], 320, 200, fil);
|
|
|
|
|
|
|
|
// write the current file offset right after the header
|
|
|
|
ofs = ftell(fil);
|
|
|
|
fseek(fil, sizeof(savehead_t), SEEK_SET);
|
|
|
|
fwrite(&ofs, 4, 1, fil);
|
|
|
|
fseek(fil, ofs, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
OSD_Printf("sv_saveandmakesnapshot: snapshot size: %d bytes.\n", svsnapsiz);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (spot >= 0)
|
|
|
|
{
|
|
|
|
// savegame
|
|
|
|
dosaveplayer2(fil, NULL);
|
2013-05-20 19:31:42 +00:00
|
|
|
#ifdef LUNATIC
|
|
|
|
if (!g_savedOK)
|
|
|
|
{
|
2013-06-30 20:38:35 +00:00
|
|
|
OSD_Printf("sv_saveandmakesnapshot: failed serializing Lunatic gamevar \"%s\".\n",
|
2013-05-20 19:31:42 +00:00
|
|
|
g_failedVarname);
|
|
|
|
g_failedVarname = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
2011-12-25 15:34:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint8_t *p;
|
|
|
|
|
|
|
|
// demo
|
2014-05-30 00:02:19 +00:00
|
|
|
SV_AllocSnap(0);
|
2011-12-25 15:34:06 +00:00
|
|
|
|
|
|
|
p = dosaveplayer2(fil, svsnapshot);
|
|
|
|
if (p != svsnapshot+svsnapsiz)
|
|
|
|
{
|
|
|
|
OSD_Printf("sv_saveandmakesnapshot: ptr-(snapshot end)=%d!\n", (int32_t)(p-(svsnapshot+svsnapsiz)));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2012-11-13 10:50:06 +00:00
|
|
|
g_oldverSavegame[spot] = 0;
|
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-11 05:22:23 +00:00
|
|
|
EDUKE32_STATIC_ASSERT(sizeof(savehead_t) == SAVEHEAD_SIZE);
|
2013-04-05 17:53:14 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
// if file is not an EDuke32 savegame/demo, h->headerstr will be all zeros
|
|
|
|
int32_t sv_loadheader(int32_t fil, int32_t spot, savehead_t *h)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
int32_t havedemo = (spot < 0);
|
|
|
|
|
|
|
|
if (kread(fil, h, sizeof(savehead_t)) != sizeof(savehead_t))
|
|
|
|
{
|
|
|
|
OSD_Printf("%s %d header corrupt.\n", havedemo ? "Demo":"Savegame", havedemo ? -spot : spot);
|
|
|
|
Bmemset(h->headerstr, 0, sizeof(h->headerstr));
|
|
|
|
return -1;
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
if (Bmemcmp(h->headerstr, "EDuke32SAVE", 11))
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
h->headerstr[sizeof(h->headerstr)-1] = 0;
|
|
|
|
OSD_Printf("%s %d header reads \"%s\", expected \"EDuke32SAVE\".\n",
|
|
|
|
havedemo ? "Demo":"Savegame", havedemo ? -spot : spot, h->headerstr);
|
|
|
|
Bmemset(h->headerstr, 0, sizeof(h->headerstr));
|
2010-01-24 23:33:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
if (h->majorver != SV_MAJOR_VER || h->minorver != SV_MINOR_VER || h->bytever != BYTEVERSION)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
if (havedemo)
|
|
|
|
OSD_Printf("Incompatible demo version. Expected %d.%d.%d, found %d.%d.%d\n",
|
|
|
|
SV_MAJOR_VER, SV_MINOR_VER, BYTEVERSION,
|
|
|
|
h->majorver, h->minorver, h->bytever);
|
2010-01-24 23:33:17 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
|
|
|
|
if (h->ptrsize != sizeof(intptr_t))
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
if (havedemo)
|
|
|
|
OSD_Printf("Demo incompatible. Expected pointer size %d, found %d\n",
|
|
|
|
(int32_t)sizeof(intptr_t), h->ptrsize);
|
2010-01-24 23:33:17 +00:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
int32_t sv_loadsnapshot(int32_t fil, int32_t spot, savehead_t *h)
|
|
|
|
{
|
|
|
|
uint8_t *p;
|
|
|
|
int32_t i;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
if (spot < 0)
|
|
|
|
{
|
|
|
|
// demo
|
|
|
|
i = sv_loadheader(fil, spot, h);
|
|
|
|
if (i)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
// Used to be in doloadplayer2(), now redundant for savegames since
|
|
|
|
// we checked before. Multiplayer demos need still to be taken care of.
|
|
|
|
if (h->numplayers != numplayers)
|
|
|
|
return 9;
|
|
|
|
}
|
|
|
|
// else (if savegame), we just read the header and are now at offset sizeof(savehead_t)
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
OSD_Printf("sv_loadsnapshot: snapshot size: %d bytes.\n", h->snapsiz);
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
if (kread(fil, &i, 4) != 4)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
OSD_Printf("sv_snapshot: couldn't read 4 bytes after header.\n");
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
if (klseek(fil, i, SEEK_SET) != i)
|
|
|
|
{
|
|
|
|
OSD_Printf("sv_snapshot: failed skipping over the screenshot.\n");
|
|
|
|
return 8;
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 14:37:34 +00:00
|
|
|
savegame_comprthres = h->comprthres;
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
if (spot >= 0)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
// savegame
|
|
|
|
i = doloadplayer2(fil, NULL);
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
OSD_Printf("sv_loadsnapshot: doloadplayer2() returned %d.\n", i);
|
|
|
|
return 5;
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// demo
|
|
|
|
savegame_diffcompress = h->diffcompress;
|
|
|
|
|
|
|
|
svsnapsiz = h->snapsiz;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
SV_AllocSnap(1);
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
p = svsnapshot;
|
|
|
|
i = doloadplayer2(fil, &p);
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
OSD_Printf("sv_loadsnapshot: doloadplayer2() returned %d.\n", i);
|
|
|
|
sv_freemem();
|
|
|
|
return 5;
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
if (p != svsnapshot+svsnapsiz)
|
|
|
|
{
|
|
|
|
OSD_Printf("sv_loadsnapshot: internal error: p-(snapshot end)=%d!\n",
|
|
|
|
(int32_t)(p-(svsnapshot+svsnapsiz)));
|
|
|
|
sv_freemem();
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bmemcpy(svinitsnap, svsnapshot, svsnapsiz);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
postloadplayer((spot >= 0));
|
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
uint32_t sv_writediff(FILE *fil)
|
|
|
|
{
|
|
|
|
uint8_t *p=svsnapshot, *d=svdiff;
|
|
|
|
uint32_t diffsiz;
|
|
|
|
|
|
|
|
cmpspecdata(svgm_udnetw, &p, &d);
|
|
|
|
cmpspecdata(svgm_secwsp, &p, &d);
|
|
|
|
cmpspecdata(svgm_script, &p, &d);
|
|
|
|
cmpspecdata(svgm_anmisc, &p, &d);
|
2013-05-19 19:29:18 +00:00
|
|
|
#if !defined LUNATIC
|
2016-01-11 05:05:38 +00:00
|
|
|
cmpspecdata((const dataspec_t *)svgm_vars, &p, &d);
|
2013-05-19 19:29:18 +00:00
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
if (p != svsnapshot+svsnapsiz)
|
|
|
|
OSD_Printf("sv_writediff: dump+siz=%p, p=%p!\n", svsnapshot+svsnapsiz, p);
|
|
|
|
|
|
|
|
diffsiz = d-svdiff;
|
|
|
|
|
|
|
|
fwrite("dIfF",4,1,fil);
|
|
|
|
fwrite(&diffsiz, sizeof(diffsiz), 1, fil);
|
|
|
|
if (savegame_diffcompress)
|
|
|
|
dfwrite(svdiff, 1, diffsiz, fil); // cnt and sz swapped
|
|
|
|
else
|
|
|
|
fwrite(svdiff, 1, diffsiz, fil);
|
|
|
|
|
|
|
|
return diffsiz;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t sv_readdiff(int32_t fil)
|
|
|
|
{
|
|
|
|
uint8_t *p=svsnapshot, *d=svdiff, i=0; //, tbuf[4];
|
2010-02-23 18:13:46 +00:00
|
|
|
int32_t diffsiz;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
#if 0 // handled by the caller
|
2010-02-23 18:13:46 +00:00
|
|
|
if (kread(fil, tbuf, 4)!=4)
|
|
|
|
return -1;
|
|
|
|
if (Bmemcmp(tbuf, "dIfF", 4))
|
|
|
|
return 4;
|
2010-01-24 23:33:17 +00:00
|
|
|
#endif
|
2010-02-23 18:13:46 +00:00
|
|
|
if (kread(fil, &diffsiz, sizeof(uint32_t))!=sizeof(uint32_t))
|
|
|
|
return -1;
|
2010-01-24 23:33:17 +00:00
|
|
|
if (savegame_diffcompress)
|
|
|
|
{
|
|
|
|
if (kdfread(svdiff, 1, diffsiz, fil) != diffsiz) // cnt and sz swapped
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (kread(fil, svdiff, diffsiz) != diffsiz)
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
if (applydiff(svgm_udnetw, &p, &d)) return -3;
|
|
|
|
if (applydiff(svgm_secwsp, &p, &d)) return -4;
|
|
|
|
if (applydiff(svgm_script, &p, &d)) return -5;
|
|
|
|
if (applydiff(svgm_anmisc, &p, &d)) return -6;
|
2013-05-19 19:29:18 +00:00
|
|
|
#if !defined LUNATIC
|
2016-01-11 05:05:38 +00:00
|
|
|
if (applydiff((const dataspec_t *)svgm_vars, &p, &d)) return -7;
|
2013-05-19 19:29:18 +00:00
|
|
|
#endif
|
2010-02-23 18:13:46 +00:00
|
|
|
|
|
|
|
if (p!=svsnapshot+svsnapsiz)
|
|
|
|
i|=1;
|
|
|
|
if (d!=svdiff+diffsiz)
|
|
|
|
i|=2;
|
|
|
|
if (i)
|
|
|
|
OSD_Printf("sv_readdiff: p=%p, svsnapshot+svsnapsiz=%p; d=%p, svdiff+diffsiz=%p",
|
|
|
|
p, svsnapshot+svsnapsiz, d, svdiff+diffsiz);
|
|
|
|
return i;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SVGM data description
|
|
|
|
static void sv_postudload()
|
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
// Bmemcpy(&boardfilename[0], ¤tboardfilename[0], BMAX_PATH); // DON'T do this in demos!
|
|
|
|
#if 1
|
2010-01-24 23:33:17 +00:00
|
|
|
ud.m_level_number = ud.level_number;
|
|
|
|
ud.m_volume_number = ud.volume_number;
|
|
|
|
ud.m_player_skill = ud.player_skill;
|
|
|
|
ud.m_respawn_monsters = ud.respawn_monsters;
|
|
|
|
ud.m_respawn_items = ud.respawn_items;
|
|
|
|
ud.m_respawn_inventory = ud.respawn_inventory;
|
|
|
|
ud.m_monsters_off = ud.monsters_off;
|
|
|
|
ud.m_coop = ud.coop;
|
|
|
|
ud.m_marker = ud.marker;
|
|
|
|
ud.m_ffire = ud.ffire;
|
|
|
|
ud.m_noexits = ud.noexits;
|
2010-02-13 21:46:42 +00:00
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
//static int32_t lockclock_dummy;
|
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2010-01-24 23:33:17 +00:00
|
|
|
static void sv_prespriteextsave()
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
for (i=0; i<MAXSPRITES; i++)
|
|
|
|
if (spriteext[i].mdanimtims)
|
|
|
|
{
|
|
|
|
spriteext[i].mdanimtims -= mdtims;
|
|
|
|
if (spriteext[i].mdanimtims==0)
|
|
|
|
spriteext[i].mdanimtims++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void sv_postspriteext()
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
for (i=0; i<MAXSPRITES; i++)
|
|
|
|
if (spriteext[i].mdanimtims)
|
|
|
|
spriteext[i].mdanimtims += mdtims;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-05-12 23:31:13 +00:00
|
|
|
#ifdef YAX_ENABLE
|
2012-03-11 17:37:08 +00:00
|
|
|
void sv_postyaxload(void)
|
2011-05-12 23:31:13 +00:00
|
|
|
{
|
|
|
|
yax_update(numyaxbunches>0 ? 2 : 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-03 12:48:17 +00:00
|
|
|
#if !defined LUNATIC
|
2010-01-24 23:33:17 +00:00
|
|
|
static void sv_calcbitptrsize()
|
|
|
|
{
|
|
|
|
savegame_bitptrsize = (g_scriptSize+7)>>3;
|
|
|
|
}
|
|
|
|
static void sv_prescriptsave_once()
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
for (i=0; i<g_scriptSize; i++)
|
|
|
|
if (bitptr[i>>3]&(BITPTR_POINTER<<(i&7)))
|
2016-08-27 01:40:35 +00:00
|
|
|
apScript[i] = (intptr_t *)apScript[i] - apScript;
|
2011-07-29 22:07:49 +00:00
|
|
|
|
2016-08-27 01:40:35 +00:00
|
|
|
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);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
2010-02-13 21:46:42 +00:00
|
|
|
static void sv_prescriptload_once()
|
|
|
|
{
|
2016-08-27 01:40:35 +00:00
|
|
|
Bfree(apScript);
|
|
|
|
apScript = (intptr_t *)Xmalloc(g_scriptSize * sizeof(apScript[0]));
|
2010-02-13 21:46:42 +00:00
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
static void sv_postscript_once()
|
|
|
|
{
|
|
|
|
int32_t i;
|
2011-07-29 22:07:49 +00:00
|
|
|
|
2016-08-27 01:40:35 +00:00
|
|
|
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);
|
2011-07-29 22:07:49 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
for (i=0; i<g_scriptSize; i++)
|
|
|
|
if (bitptr[i>>3]&(BITPTR_POINTER<<(i&7)))
|
2016-08-27 01:40:35 +00:00
|
|
|
apScript[i] = (intptr_t)(apScript + apScript[i]);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
2013-02-03 12:48:17 +00:00
|
|
|
#endif
|
2011-12-21 18:40:47 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
static void sv_preactordatasave()
|
|
|
|
{
|
|
|
|
int32_t i;
|
2012-03-11 17:37:50 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
for (i=0; i<MAXSPRITES; i++)
|
|
|
|
{
|
2011-06-19 18:30:32 +00:00
|
|
|
actor[i].lightptr = NULL;
|
|
|
|
actor[i].lightId = -1;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-21 18:40:47 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
static void sv_postactordata()
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i=0; i<MAXSPRITES; i++)
|
|
|
|
{
|
2011-06-19 18:30:32 +00:00
|
|
|
actor[i].lightptr = NULL;
|
|
|
|
actor[i].lightId = -1;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sv_preanimateptrsave()
|
|
|
|
{
|
2016-08-27 01:42:01 +00:00
|
|
|
G_Util_PtrToIdx(g_animatePtr, g_animateCnt, sector, P2I_FWD);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
static void sv_postanimateptr()
|
|
|
|
{
|
2016-08-27 01:42:01 +00:00
|
|
|
G_Util_PtrToIdx(g_animatePtr, g_animateCnt, sector, P2I_BACK);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
static void sv_prequote()
|
|
|
|
{
|
|
|
|
if (!savegame_quotes)
|
2014-07-06 00:10:46 +00:00
|
|
|
{
|
|
|
|
void *ptr = Xcalloc(MAXQUOTES, MAXQUOTELEN);
|
|
|
|
savegame_quotes = (char(*)[MAXQUOTELEN])ptr;
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
static void sv_quotesave()
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
Bmemset(savegame_quotedef, 0, sizeof(savegame_quotedef));
|
|
|
|
for (i=0; i<MAXQUOTES; i++)
|
2016-08-27 01:40:35 +00:00
|
|
|
if (apStrings[i])
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
|
|
|
savegame_quotedef[i>>3] |= 1<<(i&7);
|
2016-08-27 01:40:35 +00:00
|
|
|
Bmemcpy(savegame_quotes[i], apStrings[i], MAXQUOTELEN);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void sv_quoteload()
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
for (i=0; i<MAXQUOTES; i++)
|
|
|
|
{
|
|
|
|
if (savegame_quotedef[i>>3]&(1<<(i&7)))
|
|
|
|
{
|
2013-01-01 15:24:25 +00:00
|
|
|
C_AllocQuote(i);
|
2016-08-27 01:40:35 +00:00
|
|
|
Bmemcpy(apStrings[i], savegame_quotes[i], MAXQUOTELEN);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-24 00:40:55 +00:00
|
|
|
|
|
|
|
static void sv_preprojectilesave()
|
|
|
|
{
|
2015-03-29 02:40:15 +00:00
|
|
|
if (ProjectileData != NULL || g_numProjectiles > 0)
|
|
|
|
ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles);
|
2015-03-24 03:33:57 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2015-03-24 00:40:55 +00:00
|
|
|
int onumprojectiles = g_numProjectiles;
|
2015-03-24 03:33:57 +00:00
|
|
|
#endif
|
2015-03-24 00:40:55 +00:00
|
|
|
g_numProjectiles = 0;
|
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=0; i<MAXTILES; i++)
|
2015-03-24 00:40:55 +00:00
|
|
|
{
|
|
|
|
if (g_tile[i].proj)
|
|
|
|
{
|
|
|
|
Bmemcpy(&ProjectileData[g_numProjectiles], g_tile[i].proj, sizeof(projectile_t));
|
|
|
|
Bmemcpy(&ProjectileData[g_numProjectiles+1], g_tile[i].defproj, sizeof(projectile_t));
|
|
|
|
g_numProjectiles += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 03:33:57 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2015-03-24 00:40:55 +00:00
|
|
|
Bassert(g_numProjectiles == onumprojectiles);
|
2015-03-24 03:33:57 +00:00
|
|
|
#endif
|
2015-03-24 00:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sv_postprojectilesave()
|
|
|
|
{
|
|
|
|
// DO_FREE_AND_NULL(ProjectileData);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sv_preprojectileload()
|
|
|
|
{
|
2015-03-29 02:40:15 +00:00
|
|
|
if (ProjectileData != NULL || g_numProjectiles > 0)
|
|
|
|
ProjectileData = (projectile_t *) Xrealloc(ProjectileData, sizeof(projectile_t) * g_numProjectiles);
|
2015-05-16 11:56:49 +00:00
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=0; i<MAXTILES; i++)
|
2015-05-16 11:56:49 +00:00
|
|
|
C_FreeProjectile(i);
|
2015-03-24 00:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sv_postprojectileload()
|
|
|
|
{
|
2015-03-24 03:33:57 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2015-03-24 00:40:55 +00:00
|
|
|
int onumprojectiles = g_numProjectiles;
|
2015-03-24 03:33:57 +00:00
|
|
|
#endif
|
2015-03-24 00:40:55 +00:00
|
|
|
g_numProjectiles = 0;
|
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=0; i<MAXTILES; i++)
|
2015-03-24 00:40:55 +00:00
|
|
|
{
|
|
|
|
if (g_tile[i].proj)
|
|
|
|
{
|
2015-05-16 11:56:49 +00:00
|
|
|
C_AllocProjectile(i);
|
2015-03-24 00:40:55 +00:00
|
|
|
Bmemcpy(g_tile[i].proj, &ProjectileData[g_numProjectiles], sizeof(projectile_t));
|
|
|
|
Bmemcpy(g_tile[i].defproj, &ProjectileData[g_numProjectiles+1], sizeof(projectile_t));
|
|
|
|
g_numProjectiles += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 03:33:57 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2015-03-24 00:40:55 +00:00
|
|
|
Bassert(g_numProjectiles == onumprojectiles);
|
2015-03-24 03:33:57 +00:00
|
|
|
#endif
|
2015-03-24 00:40:55 +00:00
|
|
|
|
|
|
|
// DO_FREE_AND_NULL(ProjectileData);
|
|
|
|
}
|
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
static void sv_prequoteredef()
|
|
|
|
{
|
|
|
|
// "+1" needed for dfwrite which doesn't handle the src==NULL && cnt==0 case
|
2016-08-27 01:40:35 +00:00
|
|
|
void *ptr = Xcalloc(g_numXStrings+1, MAXQUOTELEN);
|
2014-07-06 00:10:46 +00:00
|
|
|
savegame_quoteredefs = (char(*)[MAXQUOTELEN])ptr;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
static void sv_quoteredefsave()
|
|
|
|
{
|
|
|
|
int32_t i;
|
2016-08-27 01:40:35 +00:00
|
|
|
for (i=0; i<g_numXStrings; i++)
|
|
|
|
if (apXStrings[i])
|
|
|
|
Bmemcpy(savegame_quoteredefs[i], apXStrings[i], MAXQUOTELEN);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
static void sv_quoteredefload()
|
|
|
|
{
|
|
|
|
int32_t i;
|
2016-08-27 01:40:35 +00:00
|
|
|
for (i=0; i<g_numXStrings; i++)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2016-08-27 01:40:35 +00:00
|
|
|
if (!apXStrings[i])
|
|
|
|
apXStrings[i] = (char *)Xcalloc(1,MAXQUOTELEN);
|
|
|
|
Bmemcpy(apXStrings[i], savegame_quoteredefs[i], MAXQUOTELEN);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void sv_postquoteredef()
|
|
|
|
{
|
|
|
|
Bfree(savegame_quoteredefs), savegame_quoteredefs=NULL;
|
|
|
|
}
|
|
|
|
static void sv_restsave()
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
uint8_t *mem = savegame_restdata;
|
|
|
|
DukePlayer_t dummy_ps;
|
|
|
|
|
|
|
|
Bmemset(&dummy_ps, 0, sizeof(DukePlayer_t));
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
#define CPDAT(ptr,sz) Bmemcpy(mem, ptr, sz), mem+=sz
|
2010-01-24 23:33:17 +00:00
|
|
|
for (i=0; i<MAXPLAYERS; i++)
|
|
|
|
{
|
|
|
|
CPDAT(g_player[i].user_name, 32);
|
|
|
|
CPDAT(&g_player[i].pcolor, sizeof(g_player[0].pcolor));
|
|
|
|
CPDAT(&g_player[i].pteam, sizeof(g_player[0].pteam));
|
|
|
|
CPDAT(&g_player[i].frags[0], sizeof(g_player[0].frags));
|
|
|
|
if (g_player[i].ps)
|
|
|
|
CPDAT(g_player[i].ps, sizeof(DukePlayer_t));
|
|
|
|
else
|
|
|
|
CPDAT(&dummy_ps, sizeof(DukePlayer_t));
|
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
|
2012-12-09 13:24:32 +00:00
|
|
|
Bassert((savegame_restdata+SVARDATALEN)-mem == 0);
|
2010-02-23 18:13:46 +00:00
|
|
|
#undef CPDAT
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
static void sv_restload()
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
uint8_t *mem = savegame_restdata;
|
|
|
|
DukePlayer_t dummy_ps;
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
#define CPDAT(ptr,sz) Bmemcpy(ptr, mem, sz), mem+=sz
|
2010-01-24 23:33:17 +00:00
|
|
|
for (i=0; i<MAXPLAYERS; i++)
|
|
|
|
{
|
|
|
|
CPDAT(g_player[i].user_name, 32);
|
|
|
|
CPDAT(&g_player[i].pcolor, sizeof(g_player[0].pcolor));
|
|
|
|
CPDAT(&g_player[i].pteam, sizeof(g_player[0].pteam));
|
|
|
|
CPDAT(&g_player[i].frags[0], sizeof(g_player[0].frags));
|
|
|
|
if (g_player[i].ps)
|
|
|
|
CPDAT(g_player[i].ps, sizeof(DukePlayer_t));
|
|
|
|
else
|
|
|
|
CPDAT(&dummy_ps, sizeof(DukePlayer_t));
|
|
|
|
}
|
2010-02-23 18:13:46 +00:00
|
|
|
#undef CPDAT
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
2011-12-25 15:32:00 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2011-12-28 20:33:54 +00:00
|
|
|
# define PRINTSIZE(name) do { if (mem) OSD_Printf(name ": %d\n", (int32_t)(mem-tmem)); \
|
|
|
|
OSD_Printf(name ": %d ms\n", getticks()-t); t=getticks(); tmem=mem; } while (0)
|
2011-12-25 15:32:00 +00:00
|
|
|
#else
|
2011-12-28 20:33:54 +00:00
|
|
|
# define PRINTSIZE(name) do { } while (0)
|
2011-12-25 15:32:00 +00:00
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2013-05-20 19:31:42 +00:00
|
|
|
#ifdef LUNATIC
|
2013-10-27 21:12:22 +00:00
|
|
|
// <levelnum>: if we're not serializing for a mapstate, -1
|
|
|
|
// otherwise, the linearized level number
|
|
|
|
LUNATIC_CB const char *(*El_SerializeGamevars)(int32_t *slenptr, int32_t levelnum);
|
2013-05-20 19:31:42 +00:00
|
|
|
#endif
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
static uint8_t *dosaveplayer2(FILE *fil, uint8_t *mem)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-28 20:33:54 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2010-01-24 23:33:17 +00:00
|
|
|
uint8_t *tmem = mem;
|
2011-12-28 20:33:54 +00:00
|
|
|
int32_t t=getticks();
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
mem=writespecdata(svgm_udnetw, fil, mem); // user settings, players & net
|
2011-12-25 15:32:00 +00:00
|
|
|
PRINTSIZE("ud");
|
2010-01-24 23:33:17 +00:00
|
|
|
mem=writespecdata(svgm_secwsp, fil, mem); // sector, wall, sprite
|
2011-12-25 15:32:00 +00:00
|
|
|
PRINTSIZE("sws");
|
2013-06-20 18:31:47 +00:00
|
|
|
#ifdef LUNATIC
|
2013-05-20 19:31:42 +00:00
|
|
|
{
|
2013-06-20 18:31:47 +00:00
|
|
|
// Serialize Lunatic gamevars. When loading, the restoration code must
|
|
|
|
// be present before Lua state creation in svgm_script, so save it
|
|
|
|
// right before, too.
|
2013-05-20 19:31:42 +00:00
|
|
|
int32_t slen, slen_ext;
|
2013-10-27 21:12:22 +00:00
|
|
|
const char *svcode = El_SerializeGamevars(&slen, -1);
|
2013-05-20 19:31:42 +00:00
|
|
|
|
|
|
|
if (slen < 0)
|
|
|
|
{
|
|
|
|
// Serialization failed.
|
|
|
|
g_savedOK = 0;
|
|
|
|
g_failedVarname = svcode;
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
fwrite("\0\1LunaGVAR\3\4", 12, 1, fil);
|
|
|
|
slen_ext = B_LITTLE32(slen);
|
|
|
|
fwrite(&slen_ext, sizeof(slen_ext), 1, fil);
|
2013-06-20 18:31:47 +00:00
|
|
|
dfwrite(svcode, 1, slen, fil); // cnt and sz swapped
|
2013-05-20 19:31:42 +00:00
|
|
|
|
|
|
|
g_savedOK = 1;
|
|
|
|
}
|
2013-05-19 19:29:18 +00:00
|
|
|
#endif
|
2013-06-20 18:31:47 +00:00
|
|
|
mem=writespecdata(svgm_script, fil, mem); // script
|
|
|
|
PRINTSIZE("script");
|
|
|
|
mem=writespecdata(svgm_anmisc, fil, mem); // animates, quotes & misc.
|
|
|
|
PRINTSIZE("animisc");
|
|
|
|
|
|
|
|
#if !defined LUNATIC
|
2016-08-27 01:40:35 +00:00
|
|
|
Gv_WriteSave(fil); // gamevars
|
2016-01-11 05:05:38 +00:00
|
|
|
mem=writespecdata((const dataspec_t *)svgm_vars, 0, mem);
|
2013-06-20 18:31:47 +00:00
|
|
|
PRINTSIZE("vars");
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:31:47 +00:00
|
|
|
#ifdef LUNATIC
|
|
|
|
char *g_elSavecode = NULL;
|
|
|
|
|
|
|
|
static int32_t El_ReadSaveCode(int32_t fil)
|
|
|
|
{
|
|
|
|
// Read Lua code to restore gamevar values from the savegame.
|
|
|
|
// It will be run from Lua with its state creation later on.
|
|
|
|
|
|
|
|
char header[12];
|
|
|
|
int32_t slen;
|
|
|
|
|
|
|
|
if (kread(fil, header, 12) != 12)
|
|
|
|
{
|
|
|
|
OSD_Printf("doloadplayer2: failed reading Lunatic gamevar header.\n");
|
|
|
|
return -100;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Bmemcmp(header, "\0\1LunaGVAR\3\4", 12))
|
|
|
|
{
|
|
|
|
OSD_Printf("doloadplayer2: Lunatic gamevar header doesn't match.\n");
|
|
|
|
return -101;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kread(fil, &slen, sizeof(slen)) != sizeof(slen))
|
|
|
|
{
|
|
|
|
OSD_Printf("doloadplayer2: failed reading Lunatic gamevar string size.\n");
|
|
|
|
return -102;
|
|
|
|
}
|
|
|
|
|
|
|
|
slen = B_LITTLE32(slen);
|
|
|
|
if (slen < 0)
|
|
|
|
{
|
|
|
|
OSD_Printf("doloadplayer2: invalid Lunatic gamevar string size %d.\n", slen);
|
|
|
|
return -103;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slen > 0)
|
|
|
|
{
|
2014-05-30 00:02:19 +00:00
|
|
|
char *svcode = (char *)Xmalloc(slen+1);
|
2013-06-20 18:31:47 +00:00
|
|
|
|
|
|
|
if (kdfread(svcode, 1, slen, fil) != slen) // cnt and sz swapped
|
|
|
|
{
|
|
|
|
OSD_Printf("doloadplayer2: failed reading Lunatic gamevar restoration code.\n");
|
|
|
|
Bfree(svcode);
|
|
|
|
return -104;
|
|
|
|
}
|
|
|
|
|
|
|
|
svcode[slen] = 0;
|
|
|
|
g_elSavecode = svcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void El_FreeSaveCode(void)
|
|
|
|
{
|
|
|
|
// Free Lunatic gamevar savegame restoration Lua code.
|
|
|
|
Bfree(g_elSavecode);
|
|
|
|
g_elSavecode = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
static int32_t doloadplayer2(int32_t fil, uint8_t **memptr)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2011-12-28 20:33:54 +00:00
|
|
|
uint8_t *mem = memptr ? *memptr : NULL;
|
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
uint8_t *tmem=mem;
|
|
|
|
int32_t t=getticks();
|
|
|
|
#endif
|
2011-12-25 15:34:06 +00:00
|
|
|
if (readspecdata(svgm_udnetw, fil, &mem)) return -2;
|
2011-12-25 15:32:00 +00:00
|
|
|
PRINTSIZE("ud");
|
2010-01-24 23:33:17 +00:00
|
|
|
if (readspecdata(svgm_secwsp, fil, &mem)) return -4;
|
2011-12-25 15:32:00 +00:00
|
|
|
PRINTSIZE("sws");
|
2013-06-20 18:31:47 +00:00
|
|
|
#ifdef LUNATIC
|
|
|
|
{
|
|
|
|
int32_t ret = El_ReadSaveCode(fil);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
if (readspecdata(svgm_script, fil, &mem)) return -5;
|
2011-12-25 15:32:00 +00:00
|
|
|
PRINTSIZE("script");
|
2010-01-24 23:33:17 +00:00
|
|
|
if (readspecdata(svgm_anmisc, fil, &mem)) return -6;
|
2011-12-25 15:32:00 +00:00
|
|
|
PRINTSIZE("animisc");
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2013-05-19 19:29:18 +00:00
|
|
|
#if !defined LUNATIC
|
2016-08-27 01:40:35 +00:00
|
|
|
if (Gv_ReadSave(fil)) return -7;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-21 18:42:12 +00:00
|
|
|
if (mem)
|
2011-12-25 15:32:00 +00:00
|
|
|
{
|
2011-12-25 15:34:06 +00:00
|
|
|
int32_t i;
|
|
|
|
|
2011-12-25 15:32:00 +00:00
|
|
|
sv_makevarspec();
|
2011-12-21 18:42:12 +00:00
|
|
|
for (i=1; svgm_vars[i].flags!=DS_END; i++)
|
|
|
|
{
|
|
|
|
Bmemcpy(mem, svgm_vars[i].ptr, svgm_vars[i].size*svgm_vars[i].cnt); // careful! works because there are no DS_DYNAMIC's!
|
|
|
|
mem += svgm_vars[i].size*svgm_vars[i].cnt;
|
|
|
|
}
|
2011-12-25 15:32:00 +00:00
|
|
|
}
|
2011-12-28 20:33:54 +00:00
|
|
|
PRINTSIZE("vars");
|
2013-05-19 19:29:18 +00:00
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
if (memptr)
|
|
|
|
*memptr = mem;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t sv_updatestate(int32_t frominit)
|
|
|
|
{
|
|
|
|
uint8_t *p = svsnapshot, *pbeg=p;
|
|
|
|
|
|
|
|
if (frominit)
|
|
|
|
Bmemcpy(svsnapshot, svinitsnap, svsnapsiz);
|
|
|
|
|
|
|
|
if (readspecdata(svgm_udnetw, -1, &p)) return -2;
|
|
|
|
if (readspecdata(svgm_secwsp, -1, &p)) return -4;
|
|
|
|
if (readspecdata(svgm_script, -1, &p)) return -5;
|
|
|
|
if (readspecdata(svgm_anmisc, -1, &p)) return -6;
|
|
|
|
|
2013-05-19 19:29:18 +00:00
|
|
|
#if !defined LUNATIC
|
2016-01-11 05:05:38 +00:00
|
|
|
if (readspecdata((const dataspec_t *)svgm_vars, -1, &p)) return -8;
|
2013-05-19 19:29:18 +00:00
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
if (p != pbeg+svsnapsiz)
|
2011-12-25 15:32:00 +00:00
|
|
|
{
|
2010-01-24 23:33:17 +00:00
|
|
|
OSD_Printf("sv_updatestate: ptr-(snapshot end)=%d\n", (int32_t)(p-(pbeg+svsnapsiz)));
|
2011-12-25 15:32:00 +00:00
|
|
|
return -9;
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
if (frominit)
|
2011-12-25 15:34:06 +00:00
|
|
|
postloadplayer(0);
|
|
|
|
#ifdef POLYMER
|
2012-12-30 20:34:34 +00:00
|
|
|
if (getrendermode() == REND_POLYMER)
|
2011-12-25 15:34:06 +00:00
|
|
|
polymer_resetlights(); // must do it after polymer_loadboard() !!!
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
static void postloadplayer(int32_t savegamep)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
|
|
|
int32_t i;
|
2011-12-25 15:34:06 +00:00
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
//1
|
|
|
|
if (g_player[myconnectindex].ps->over_shoulder_on != 0)
|
|
|
|
{
|
2013-01-19 18:28:32 +00:00
|
|
|
CAMERADIST = 0;
|
|
|
|
CAMERACLOCK = 0;
|
2010-01-24 23:33:17 +00:00
|
|
|
g_player[myconnectindex].ps->over_shoulder_on = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//2
|
2011-12-25 15:34:06 +00:00
|
|
|
screenpeek = myconnectindex;
|
|
|
|
|
|
|
|
//2.5
|
|
|
|
if (savegamep)
|
|
|
|
{
|
2014-09-07 18:10:15 +00:00
|
|
|
int32_t musicIdx = (ud.volume_number*MAXLEVELS) + ud.level_number;
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
Bmemset(gotpic, 0, sizeof(gotpic));
|
|
|
|
S_ClearSoundLocks();
|
|
|
|
G_CacheMapData();
|
|
|
|
|
|
|
|
if (boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0)
|
|
|
|
{
|
2014-09-07 18:10:15 +00:00
|
|
|
const uint32_t BSZ = sizeof(boardfilename);
|
2011-12-25 15:34:06 +00:00
|
|
|
char levname[BMAX_PATH];
|
|
|
|
|
|
|
|
G_SetupFilenameBasedMusic(levname, boardfilename, ud.level_number);
|
2014-09-07 18:10:15 +00:00
|
|
|
|
|
|
|
// Potentially extract the custom music volume/level from
|
|
|
|
// boardfilename[] stored with SAVEGAME_MUSIC.
|
|
|
|
if (Bstrlen(boardfilename) < BSZ-2)
|
|
|
|
{
|
|
|
|
int32_t mi = MAXLEVELS*boardfilename[BSZ-2] + boardfilename[BSZ-1];
|
|
|
|
|
|
|
|
if (mi != 0 && (unsigned)mi < MUS_FIRST_SPECIAL)
|
|
|
|
musicIdx = mi;
|
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ud.config.MusicToggle)
|
|
|
|
{
|
2016-08-27 01:42:01 +00:00
|
|
|
if (g_mapInfo[musicIdx].musicfn != NULL &&
|
2014-09-07 18:10:15 +00:00
|
|
|
(musicIdx != g_musicIndex /* || MapInfo[MUS_LOADING].musicfn */))
|
2011-12-25 15:34:06 +00:00
|
|
|
{
|
|
|
|
S_StopMusic();
|
2014-09-07 18:10:15 +00:00
|
|
|
|
|
|
|
g_musicIndex = musicIdx;
|
2016-08-27 01:42:01 +00:00
|
|
|
S_PlayMusic(g_mapInfo[g_musicIndex].musicfn);
|
2011-12-25 15:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
S_PauseMusic(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_player[myconnectindex].ps->gm = MODE_GAME;
|
|
|
|
ud.recstat = 0;
|
|
|
|
|
|
|
|
if (g_player[myconnectindex].ps->jetpack_on)
|
|
|
|
A_PlaySound(DUKE_JETPACK_IDLE, g_player[myconnectindex].ps->i);
|
|
|
|
}
|
|
|
|
|
2010-01-24 23:33:17 +00:00
|
|
|
//3
|
|
|
|
P_UpdateScreenPal(g_player[myconnectindex].ps);
|
2012-02-02 17:34:16 +00:00
|
|
|
g_restorePalette = -1;
|
2011-12-25 15:34:06 +00:00
|
|
|
|
|
|
|
//3.5
|
|
|
|
if (savegamep)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2012-11-13 10:50:06 +00:00
|
|
|
for (SPRITES_OF(STAT_FX, i))
|
2012-10-14 22:13:49 +00:00
|
|
|
if (sprite[i].picnum == MUSICANDSFX)
|
|
|
|
{
|
2016-08-27 01:40:35 +00:00
|
|
|
T2(i) = ud.config.SoundToggle;
|
|
|
|
T1(i) = 0;
|
2012-10-14 22:13:49 +00:00
|
|
|
}
|
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
G_UpdateScreenArea();
|
|
|
|
FX_SetReverb(0);
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
2011-12-25 15:34:06 +00:00
|
|
|
|
|
|
|
//4
|
|
|
|
if (savegamep)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2012-01-05 20:48:37 +00:00
|
|
|
if (ud.lockout)
|
2011-12-25 15:34:06 +00:00
|
|
|
{
|
2016-08-27 01:42:01 +00:00
|
|
|
for (i=0; i<g_animWallCnt; i++)
|
2012-01-28 14:38:23 +00:00
|
|
|
switch (DYNAMICTILEMAP(wall[animwall[i].wallnum].picnum))
|
2011-12-25 15:34:06 +00:00
|
|
|
{
|
|
|
|
case FEMPIC1__STATIC:
|
|
|
|
wall[animwall[i].wallnum].picnum = BLANKSCREEN;
|
|
|
|
break;
|
|
|
|
case FEMPIC2__STATIC:
|
|
|
|
case FEMPIC3__STATIC:
|
|
|
|
wall[animwall[i].wallnum].picnum = SCREENBREAK6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 20:48:37 +00:00
|
|
|
#if 0
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i=0; i<g_numAnimWalls; i++)
|
|
|
|
if (wall[animwall[i].wallnum].extra >= 0)
|
|
|
|
wall[animwall[i].wallnum].picnum = wall[animwall[i].wallnum].extra;
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//5
|
2011-07-29 22:07:28 +00:00
|
|
|
G_ResetInterpolations();
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
//6
|
|
|
|
g_showShareware = 0;
|
2011-12-25 15:34:06 +00:00
|
|
|
if (savegamep)
|
|
|
|
everyothertime = 0;
|
2011-12-21 18:42:12 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
//7
|
2010-01-24 23:33:17 +00:00
|
|
|
for (i=0; i<MAXPLAYERS; i++)
|
2011-12-21 18:42:12 +00:00
|
|
|
g_player[i].playerquitflag = 1;
|
2010-01-24 23:33:17 +00:00
|
|
|
|
2011-12-25 15:34:06 +00:00
|
|
|
// ----------
|
|
|
|
|
|
|
|
//7.5
|
|
|
|
if (savegamep)
|
|
|
|
{
|
|
|
|
ready2send = 1;
|
|
|
|
G_ClearFIFO();
|
|
|
|
Net_WaitForServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
//8
|
|
|
|
// if (savegamep) ?
|
2013-07-04 19:38:46 +00:00
|
|
|
#ifdef LUNATIC
|
|
|
|
G_ResetTimers(1);
|
|
|
|
#else
|
|
|
|
G_ResetTimers(0);
|
|
|
|
#endif
|
2010-01-24 23:33:17 +00:00
|
|
|
|
|
|
|
#ifdef POLYMER
|
2011-12-25 15:34:06 +00:00
|
|
|
//9
|
2012-12-30 20:34:34 +00:00
|
|
|
if (getrendermode() == REND_POLYMER)
|
2010-01-25 01:11:34 +00:00
|
|
|
polymer_loadboard();
|
2010-01-24 23:33:17 +00:00
|
|
|
#elif 0
|
2012-12-30 20:34:34 +00:00
|
|
|
if (getrendermode() == REND_POLYMER)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
|
|
|
int32_t i = 0;
|
|
|
|
|
|
|
|
polymer_loadboard();
|
|
|
|
while (i < MAXSPRITES)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (actor[i].lightptr)
|
2010-01-24 23:33:17 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
polymer_deletelight(actor[i].lightId);
|
|
|
|
actor[i].lightptr = NULL;
|
|
|
|
actor[i].lightId = -1;
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-12-25 15:34:06 +00:00
|
|
|
// this light pointer nulling needs to be outside the getrendermode check
|
|
|
|
// because we might be loading the savegame using another renderer but
|
|
|
|
// change to Polymer later
|
|
|
|
for (i=0; i<MAXSPRITES; i++)
|
|
|
|
{
|
|
|
|
actor[i].lightptr = NULL;
|
|
|
|
actor[i].lightId = -1;
|
|
|
|
}
|
2010-01-24 23:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////// END GENERIC SAVING/LOADING SYSTEM //////////
|
2015-02-11 05:22:23 +00:00
|
|
|
|