Preliminary commoning of actor[].t_data[10] to an array of int32's on both

32- and 64-bit platforms. Also, make struct type actor_t also have a common
size of 128 bytes. New code currently disabled and #ifdef'd for comparison.

This requires certain t_data[] entries ([1]: move ptr, [4]: action ptr and
[5]: ai ptr with actors) to be converted to script offsets instead of pointers,
breaking savegame and net packet compatibility (we could in theory try hard not
to, but it would be too much trouble).

git-svn-id: https://svn.eduke32.com/eduke32@2185 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-12-21 18:40:47 +00:00
parent 9b0ea0366e
commit 8e54a3febf
12 changed files with 252 additions and 67 deletions

View file

@ -8323,6 +8323,7 @@ void drawmasks(void)
xs = tspriteptr[i]->x-globalposx; ys = tspriteptr[i]->y-globalposy;
yp = dmulscale6(xs,cosviewingrangeglobalang,ys,sinviewingrangeglobalang);
#ifdef USE_OPENGL
// WGR2 SVN sanguis regalis (vae victis) ->picnum == -3 or -4 (hard to reproduce)
modelp = (usemodels && tile2model[tspriteptr[i]->picnum].modelid >= 0);
#endif
if (yp > (4<<8))

View file

@ -704,9 +704,15 @@ static void A_MoveSector(int32_t i)
}
}
#ifdef SAMESIZE_ACTOR_T
# define LIGHTRAD_PICOFS (T5 ? *(script+T5) + (*(script+T5+2))*T4 : 0)
#else
# define LIGHTRAD_PICOFS (T5 ? (*(intptr_t *)T5) + *(((intptr_t *)T5)+2) * T4 : 0)
#endif
// this is the same crap as in game.c's tspr manipulation. puke.
#define LIGHTRAD (s->yrepeat * tilesizy[s->picnum+(T5?(*(intptr_t *)T5) + *(((intptr_t *)T5)+2) * T4:0)])
#define LIGHTRAD2 (((s->yrepeat) + (rand()%(s->yrepeat>>2))) * tilesizy[s->picnum+(T5?(*(intptr_t *)T5) + *(((intptr_t *)T5)+2) * T4:0)])
#define LIGHTRAD (s->yrepeat * tilesizy[s->picnum+LIGHTRAD_PICOFS])
#define LIGHTRAD2 (((s->yrepeat) + (rand()%(s->yrepeat>>2))) * tilesizy[s->picnum+LIGHTRAD_PICOFS])
void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, int32_t range, int32_t color, int32_t priority)
{
@ -1409,7 +1415,11 @@ ACTOR_STATIC void G_MoveStandables(void)
{
int32_t i = headspritestat[STAT_STANDABLE], j, k, nexti, nextj, p=0, sect, switchpicnum;
int32_t l=0, x;
#ifdef SAMESIZE_ACTOR_T
int32_t *t;
#else
intptr_t *t;
#endif
spritetype *s;
int16_t m;
@ -3520,7 +3530,11 @@ static int16_t A_FindLocator(int32_t n,int32_t sn)
ACTOR_STATIC void G_MoveActors(void)
{
int32_t x, m, l;
#ifdef SAMESIZE_ACTOR_T
int32_t *t;
#else
intptr_t *t;
#endif
int32_t a, j, nexti, nextj, sect, p, switchpicnum, k;
spritetype *s;
int32_t i = headspritestat[STAT_ACTOR];
@ -4872,7 +4886,11 @@ ACTOR_STATIC void G_MoveMisc(void) // STATNUM 5
{
int16_t i, j, nexti, sect, p;
int32_t l, x;
#ifdef SAMESIZE_ACTOR_T
int32_t *t;
#else
intptr_t *t;
#endif
spritetype *s;
int32_t switchpicnum;
@ -5433,8 +5451,12 @@ BOLT:
ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
{
int32_t q=0, m, x, st, j;
intptr_t *t,l;
int32_t q=0, m, x, st, j, l;
#ifdef SAMESIZE_ACTOR_T
int32_t *t;
#else
intptr_t *t;
#endif
int32_t i = headspritestat[STAT_EFFECTOR], nexti, nextk, p, sh, nextj;
int16_t k;
spritetype *s;
@ -7091,33 +7113,35 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
break;
case 21: // Cascading effect
{
int32_t *zptr;
if (t[0] == 0) break;
if (s->ang == 1536)
l = (intptr_t) &sc->ceilingz;
zptr = &sc->ceilingz;
else
l = (intptr_t) &sc->floorz;
zptr = &sc->floorz;
if (t[0] == 1) //Decide if the s->sectnum should go up or down
{
s->zvel = ksgn(s->z-*(int32_t *)l) * (SP<<4);
s->zvel = ksgn(s->z-*zptr) * (SP<<4);
t[0]++;
}
if (sc->extra == 0)
{
*(int32_t *)l += s->zvel;
*zptr += s->zvel;
if (klabs(*(int32_t *)l-s->z) < 1024)
if (klabs(*zptr-s->z) < 1024)
{
*(int32_t *)l = s->z;
*zptr = s->z;
KILLIT(i); //All done
}
}
else sc->extra--;
break;
}
case 22:
if (t[1])

View file

@ -23,6 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __actors_h__
#define __actors_h__
// Uncomment to have the same sizeof(actor_t) and sizeof(netactor_t) across
// 32- and 64-bit builds; KEEPINSYNC with same #define in gamedef.h:
//#define SAMESIZE_ACTOR_T
#define MAXSLEEPDIST 16384
#define SLEEPTIME 1536
#define ZOFFSET (1<<8)
@ -81,9 +85,13 @@ typedef struct {
int8_t filler[6]; // 6b
} projectile_t;
// (+ 40 8 6 16 16 4 8 6 4 4 16)
typedef struct {
#ifdef SAMESIZE_ACTOR_T
int32_t t_data[10]; // 40b sometimes used to hold offsets to con code
#else
intptr_t t_data[10]; // 40b/80b sometimes used to hold pointers to con code
#endif
int16_t picnum,ang,extra,owner; //8b
int16_t movflag,tempang,timetosleep; //6b
@ -102,12 +110,22 @@ typedef struct {
projectile_t *projectile; //4b/8b
#if !defined SAMESIZE_ACTOR_T || UINTPTR_MAX == 0xffffffff
/* 32-bit or old, same-declaration version */
int8_t filler[16]; // pad struct to 128 bytes
#else
/* 64-bit, will break older savegames */
int8_t filler[8];
#endif
} actor_t;
// this struct needs to match the beginning of actor_t above
typedef struct {
#ifdef SAMESIZE_ACTOR_T
int32_t t_data[10]; // 40b sometimes used to hold offsets to con code
#else
intptr_t t_data[10]; // 40b/80b sometimes used to hold pointers to con code
#endif
int16_t picnum,ang,extra,owner; //8b
int16_t movflag,tempang,timetosleep; // 6b

View file

@ -66,10 +66,18 @@ extern "C" {
// increase by 3, because atomic GRP adds 1, and Shareware adds 2
#ifdef YAX_ENABLE
// we'll have to introduce a BYTEVERSION2 sooner or later anyway...:
# define BYTEVERSION_JF 228
# ifdef SAMESIZE_ACTOR_T
# define BYTEVERSION_JF 231
# else
# define BYTEVERSION_JF 228
# endif
// keep in sync? v^v
#else
# define BYTEVERSION_JF 198
# ifdef SAMESIZE_ACTOR_T
# define BYTEVERSION_JF 201
# else
# define BYTEVERSION_JF 198
# endif
#endif
#define BYTEVERSION_13 27
#define BYTEVERSION_14 116

View file

@ -6420,10 +6420,17 @@ PALONLY:
t->ang = sprpos[i].ang;
}
*/
if ((unsigned)((intptr_t *)t4-&script[0]) > (unsigned)(&script[g_scriptSize]-&script[0]))
#ifdef SAMESIZE_ACTOR_T
if ((unsigned)t4 + 2 >= (unsigned)g_scriptSize)
goto skip;
l = *(script + t4 + 2);
#else
if ((unsigned)((intptr_t *)t4 - script + 2) >= (unsigned)g_scriptSize)
goto skip;
l = *(((intptr_t *)t4)+2); //For TerminX: was *(int32_t *)(t4+8)
#endif
#ifdef USE_OPENGL
if (getrendermode() >= 3 && usemodels && md_tilehasmodel(s->picnum,t->pal) >= 0 && !(spriteext[i].flags&SPREXT_NOTMD))
@ -6478,9 +6485,11 @@ PALONLY:
k = 0;
break;
}
#ifdef SAMESIZE_ACTOR_T
t->picnum += k + *(script + t4) + l*t3;
#else
t->picnum += k + (*(intptr_t *)t4) + l * t3;
#endif
if (l > 0) while (tilesizx[t->picnum] == 0 && t->picnum > 0)
t->picnum -= l; //Hack, for actors

View file

@ -1580,9 +1580,9 @@ static void C_GetNextVarType(int32_t type)
if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
initprintf("%s:%d: debug: accepted defined label `%s' instead of gamevar.\n",g_szScriptFileName,g_lineNumber,label+(i<<6));
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
*g_scriptPtr++=MAXGAMEVARS;
*g_scriptPtr++ = MAXGAMEVARS;
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
*g_scriptPtr++=labelcode[i];
*g_scriptPtr++ = labelcode[i];
return;
}
}
@ -1669,17 +1669,21 @@ static int32_t C_GetNextValue(int32_t type)
bitptr[(g_scriptPtr-script)>>3] |= (BITPTR_POINTER<<((g_scriptPtr-script)&7));
else
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
#else
*(g_scriptPtr++) = labelcode[i];
#elif !defined SAMESIZE_ACTOR_T
if ((labeltype[i]&LABEL_DEFINE)==0)
bitptr[(g_scriptPtr-script)>>3] |= (BITPTR_POINTER<<((g_scriptPtr-script)&7));
else // the 'define' label type is the only one that doesn't reference the script
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
#endif
if ((labeltype[i]&LABEL_DEFINE)==0)
*(g_scriptPtr++) = (intptr_t)(script + labelcode[i]);
else
*(g_scriptPtr++) = labelcode[i];
#else
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
*(g_scriptPtr++) = labelcode[i];
#endif
textptr += l;
return labeltype[i];
}

View file

@ -23,6 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef _gamedef_h_
#define _gamedef_h_
// Uncomment to have the same sizeof(actor_t) and sizeof(netactor_t) across
// 32- and 64-bit builds; KEEPINSYNC with same #define in actors.h:
//#define SAMESIZE_ACTOR_T
#define MAXGAMEEVENTS 128
#define LABEL_HASPARM2 1
#define LABEL_ISSTRING 2
@ -119,7 +123,11 @@ enum vmflags_t {
typedef struct {
int32_t g_i, g_p, g_x;
#ifdef SAMESIZE_ACTOR_T
int32_t *g_t;
#else
intptr_t *g_t;
#endif
spritetype *g_sp;
int32_t g_flags;
} vmstate_t;

View file

@ -411,16 +411,25 @@ int32_t G_GetAngleDelta(int32_t a,int32_t na)
GAMEEXEC_STATIC GAMEEXEC_INLINE void VM_AlterAng(int32_t a)
{
intptr_t *moveptr = (intptr_t *)vm.g_t[1];
int32_t ticselapsed = (vm.g_t[0])&31;
if (moveptr < &script[0] || moveptr > &script[g_scriptSize])
#ifdef SAMESIZE_ACTOR_T
const intptr_t *moveptr;
if ((unsigned)vm.g_t[1] >= (unsigned)g_scriptSize)
#else
const intptr_t *moveptr = (intptr_t *)vm.g_t[1];
if (moveptr < &script[0] || moveptr >= &script[g_scriptSize])
#endif
{
vm.g_t[1] = 0;
OSD_Printf(OSD_ERROR "bad moveptr for actor %d (%d)!\n", vm.g_i, vm.g_sp->picnum);
return;
}
#ifdef SAMESIZE_ACTOR_T
moveptr = script + vm.g_t[1]; // RESEARCH: what's with move 0 and >>> 1 <<<?
#endif
vm.g_sp->xvel += (*moveptr-vm.g_sp->xvel)/5;
if (vm.g_sp->zvel < 648) vm.g_sp->zvel += ((*(moveptr+1)<<4)-vm.g_sp->zvel)/5;
@ -482,7 +491,7 @@ GAMEEXEC_STATIC GAMEEXEC_INLINE void VM_AlterAng(int32_t a)
GAMEEXEC_STATIC void VM_Move(void)
{
int32_t l;
intptr_t *moveptr;
const intptr_t *moveptr;
int32_t a = vm.g_sp->hitag, goalang, angdif;
int32_t daxvel;
int32_t deadflag = (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->extra <= 0);
@ -548,13 +557,21 @@ GAMEEXEC_STATIC void VM_Move(void)
}
dead:
if ((moveptr = (intptr_t *)vm.g_t[1]) < &script[0] || moveptr > &script[g_scriptSize])
#ifdef SAMESIZE_ACTOR_T
if ((unsigned)vm.g_t[1] >= (unsigned)g_scriptSize)
#else
if ((moveptr = (intptr_t *)vm.g_t[1]) < &script[0] || moveptr >= &script[g_scriptSize])
#endif
{
vm.g_t[1] = 0;
OSD_Printf(OSD_ERROR "clearing bad moveptr for actor %d (%d)\n", vm.g_i, vm.g_sp->picnum);
return;
}
#ifdef SAMESIZE_ACTOR_T
moveptr = script + vm.g_t[1]; // RESEARCH: what's with move 0 and >>> 1 <<<?
#endif
if (a&geth) vm.g_sp->xvel += ((*moveptr)-vm.g_sp->xvel)>>1;
if (a&getv) vm.g_sp->zvel += ((*(moveptr+1)<<4)-vm.g_sp->zvel)>>1;
@ -884,9 +901,15 @@ skip_check:
insptr++;
//Following changed to use pointersizes
vm.g_t[5] = *insptr++; // Ai
#ifdef SAMESIZE_ACTOR_T
vm.g_t[4] = *(script + vm.g_t[5]); // Action
if (vm.g_t[5]) vm.g_t[1] = *(script + vm.g_t[5] + 1); // move
vm.g_sp->hitag = *(script + vm.g_t[5] + 2); // move flags
#else
vm.g_t[4] = *(intptr_t *)(vm.g_t[5]); // Action
if (vm.g_t[5]) vm.g_t[1] = *(((intptr_t *)vm.g_t[5])+1); // move
vm.g_sp->hitag = *(((intptr_t *)vm.g_t[5])+2); // move flags
#endif
vm.g_t[0] = vm.g_t[2] = vm.g_t[3] = 0; // count, actioncount... vm.g_t[3] = ??
if (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->extra <= 0) // hack
continue;
@ -1209,16 +1232,25 @@ skip_check:
default:
// fix for flying/jumping monsters getting stuck in water
{
intptr_t *moveptr = (intptr_t *)vm.g_t[1];
#ifdef SAMESIZE_ACTOR_T
int32_t moveScriptOfs = vm.g_t[1];
#else
const intptr_t *moveptr = (intptr_t *)vm.g_t[1];
#endif
if (vm.g_sp->hitag & jumptoplayer ||
(actorscrptr[vm.g_sp->picnum] &&
(unsigned int)(moveptr - &script[0]) <= (unsigned int)(&script[g_scriptSize] - &script[0]) &&
*(moveptr+1)))
#ifdef SAMESIZE_ACTOR_T
(unsigned)moveScriptOfs < (unsigned)g_scriptSize - 1 && *(script + moveScriptOfs + 1)
#else
(unsigned)(moveptr - script) < (unsigned)g_scriptSize - 1 && *(moveptr+1)
#endif
))
{
// OSD_Printf("%d\n",*(moveptr+1));
break;
}
}
// OSD_Printf("hitag: %d\n",vm.g_sp->hitag);
vm.g_sp->z += (24<<8);
case OCTABRAIN__STATIC:
@ -1830,12 +1862,19 @@ nullquote:
actor[i].flags = 0;
sprite[i].hitag = 0;
// pointers
if (actorscrptr[sprite[i].picnum])
{
#ifdef SAMESIZE_ACTOR_T
// offsets
T5 = *(actorscrptr[sprite[i].picnum]+1); // action
T2 = *(actorscrptr[sprite[i].picnum]+2); // move
sprite[i].hitag = *(actorscrptr[sprite[i].picnum]+3); // ai bits
#else
// pointers
T5 = *(actorscrptr[sprite[i].picnum]+1);
T2 = *(actorscrptr[sprite[i].picnum]+2);
sprite[i].hitag = *(actorscrptr[sprite[i].picnum]+3);
#endif
}
}
changespritestat(i,j);
@ -4931,18 +4970,35 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist)
/* Qbix: Changed variables to be aware of the sizeof *insptr
* (whether it is int32_t vs intptr_t), Although it is specifically cast to intptr_t*
* which might be corrected if the code is converted to use offsets */
/* Helixhorned: let's do away with intptr_t's... */
#ifdef SAMESIZE_ACTOR_T
if ((unsigned)vm.g_t[4] + 4 < (unsigned)g_scriptSize)
#else
if ((unsigned)(vm.g_t[4]-(intptr_t)&script[0]) <= (unsigned)((intptr_t)&script[g_scriptSize]-(intptr_t)&script[0]))
#endif
{
vm.g_sp->lotag += TICSPERFRAME;
#ifdef SAMESIZE_ACTOR_T
if (vm.g_sp->lotag > *(script + vm.g_t[4] + 4))
#else
if (vm.g_sp->lotag > *(intptr_t *)(vm.g_t[4]+4*sizeof(*insptr)))
#endif
{
vm.g_t[2]++;
vm.g_sp->lotag = 0;
#ifdef SAMESIZE_ACTOR_T
vm.g_t[3] += *(script + vm.g_t[4] + 3);
#else
vm.g_t[3] += *(intptr_t *)(vm.g_t[4]+3*sizeof(*insptr));
#endif
}
#ifdef SAMESIZE_ACTOR_T
if (klabs(vm.g_t[3]) >= klabs(*(script + vm.g_t[4] + 1) * *(script + vm.g_t[4] + 3)))
#else
if (klabs(vm.g_t[3]) >= klabs(*(intptr_t *)(vm.g_t[4]+sizeof(*insptr)) * *(intptr_t *)(vm.g_t[4]+3*sizeof(*insptr))))
#endif
vm.g_t[3] = 0;
}
@ -5020,7 +5076,6 @@ void G_SaveMapState(mapstate_t *save)
if (save != NULL)
{
int32_t i;
intptr_t j;
Bmemcpy(&save->numwalls,&numwalls,sizeof(numwalls));
Bmemcpy(&save->wall[0],&wall[0],sizeof(walltype)*MAXWALLS);
@ -5040,9 +5095,11 @@ void G_SaveMapState(mapstate_t *save)
Bmemcpy(&save->headspritestat[0],&headspritestat[0],sizeof(headspritestat));
Bmemcpy(&save->prevspritestat[0],&prevspritestat[0],sizeof(prevspritestat));
Bmemcpy(&save->nextspritestat[0],&nextspritestat[0],sizeof(nextspritestat));
#if !defined SAMESIZE_ACTOR_T
for (i=MAXSPRITES-1; i>=0; i--)
{
intptr_t j;
save->scriptptrs[i] = 0;
if (actorscrptr[PN] == 0) continue;
@ -5065,11 +5122,15 @@ void G_SaveMapState(mapstate_t *save)
T6 -= j;
}
}
#endif
Bmemcpy(&save->actor[0],&actor[0],sizeof(actor_t)*MAXSPRITES);
#if !defined SAMESIZE_ACTOR_T
for (i=MAXSPRITES-1; i>=0; i--)
{
intptr_t j;
if (actorscrptr[PN] == 0) continue;
j = (intptr_t)&script[0];
@ -5080,7 +5141,7 @@ void G_SaveMapState(mapstate_t *save)
if (save->scriptptrs[i]&4)
T6 += j;
}
#endif
Bmemcpy(&save->g_numCyclers,&g_numCyclers,sizeof(g_numCyclers));
Bmemcpy(&save->cyclers[0][0],&cyclers[0][0],sizeof(cyclers));
Bmemcpy(&save->g_playerSpawnPoints[0],&g_playerSpawnPoints[0],sizeof(g_playerSpawnPoints));
@ -5144,7 +5205,6 @@ void G_RestoreMapState(mapstate_t *save)
if (save != NULL)
{
int32_t i, x;
intptr_t j;
char phealth[MAXPLAYERS];
for (i=0; i<playerswhenstarted; i++)
@ -5172,15 +5232,17 @@ void G_RestoreMapState(mapstate_t *save)
Bmemcpy(&prevspritestat[0],&save->prevspritestat[0],sizeof(prevspritestat));
Bmemcpy(&nextspritestat[0],&save->nextspritestat[0],sizeof(nextspritestat));
Bmemcpy(&actor[0],&save->actor[0],sizeof(actor_t)*MAXSPRITES);
#if !defined SAMESIZE_ACTOR_T
for (i=MAXSPRITES-1; i>=0; i--)
{
intptr_t j;
j = (intptr_t)(&script[0]);
if (save->scriptptrs[i]&1) T2 += j;
if (save->scriptptrs[i]&2) T5 += j;
if (save->scriptptrs[i]&4) T6 += j;
}
#endif
Bmemcpy(&g_numCyclers,&save->g_numCyclers,sizeof(g_numCyclers));
Bmemcpy(&cyclers[0][0],&save->cyclers[0][0],sizeof(cyclers));
Bmemcpy(&g_playerSpawnPoints[0],&save->g_playerSpawnPoints[0],sizeof(g_playerSpawnPoints));

View file

@ -104,7 +104,6 @@ static void Gv_Clear(void)
int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
{
int32_t i, j;
intptr_t l;
char savedstate[MAXVOLUMES*MAXLEVELS];
char tbuf[12];
@ -205,6 +204,8 @@ int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
if (!newbehav)
{
intptr_t l;
if (kdfread(&l,sizeof(l),1,fil) != 1) goto corrupt;
if (kdfread(g_szBuf,l,1,fil) != 1) goto corrupt;
g_szBuf[l]=0;
@ -237,7 +238,6 @@ corrupt:
void Gv_WriteSave(FILE *fil, int32_t newbehav)
{
int32_t i, j;
intptr_t l;
char savedstate[MAXVOLUMES*MAXLEVELS];
Bmemset(&savedstate,0,sizeof(savedstate));
@ -306,6 +306,8 @@ void Gv_WriteSave(FILE *fil, int32_t newbehav)
if (!newbehav)
{
intptr_t l;
Bsprintf(g_szBuf,"EOF: EDuke32");
l=Bstrlen(g_szBuf);
dfwrite(&l,sizeof(l),1,fil);

View file

@ -611,8 +611,10 @@ int32_t Net_UnpackSprite(int32_t i, uint8_t *pbuf)
if (flags & NET_ACTOR_T2)
{
actor[i].t_data[1] = *(int32_t *)&pbuf[j];
#if !defined SAMESIZE_ACTOR_T
if (flags & NET_ACTOR_PTR1)
actor[i].t_data[1] += (intptr_t)&script[0];
#endif
j += sizeof(int32_t);
}
@ -631,16 +633,20 @@ int32_t Net_UnpackSprite(int32_t i, uint8_t *pbuf)
if (flags & NET_ACTOR_T5)
{
actor[i].t_data[4] = *(int32_t *)&pbuf[j];
#if !defined SAMESIZE_ACTOR_T
if (flags & NET_ACTOR_PTR2)
actor[i].t_data[4] += (intptr_t)&script[0];
#endif
j += sizeof(int32_t);
}
if (flags & NET_ACTOR_T6)
{
actor[i].t_data[5] = *(int32_t *)&pbuf[j];
#if !defined SAMESIZE_ACTOR_T
if (flags & NET_ACTOR_PTR3)
actor[i].t_data[5] += (intptr_t)&script[0];
#endif
j += sizeof(int32_t);
}
@ -939,13 +945,15 @@ int32_t Net_PackSprite(int32_t i, uint8_t *pbuf)
if (!lastupdate[i] || actor[i].t_data[1] != netactor[i].t_data[1])
{
*flags |= NET_ACTOR_T2;
#if !defined SAMESIZE_ACTOR_T
if (T2 >= (intptr_t)&script[0] && T2 < (intptr_t)(&script[g_scriptSize]))
{
*flags |= NET_ACTOR_PTR1;
*(int32_t *)&pbuf[j] = (int32_t)(actor[i].t_data[1] - (intptr_t)&script[0]);
}
else *(int32_t *)&pbuf[j] = actor[i].t_data[1];
else
#endif
*(int32_t *)&pbuf[j] = actor[i].t_data[1];
j += sizeof(int32_t);
}
@ -966,25 +974,30 @@ int32_t Net_PackSprite(int32_t i, uint8_t *pbuf)
if (!lastupdate[i] || actor[i].t_data[4] != netactor[i].t_data[4])
{
*flags |= NET_ACTOR_T5;
#if !defined SAMESIZE_ACTOR_T
if (T5 >= (intptr_t)&script[0] && T5 < (intptr_t)(&script[g_scriptSize]))
{
*flags |= NET_ACTOR_PTR2;
*(int32_t *)&pbuf[j] = (int32_t)(actor[i].t_data[4] - (intptr_t)&script[0]);
}
else *(int32_t *)&pbuf[j] = actor[i].t_data[4];
else
#endif
*(int32_t *)&pbuf[j] = actor[i].t_data[4];
j += sizeof(int32_t);
}
if (!lastupdate[i] || actor[i].t_data[5] != netactor[i].t_data[5])
{
*flags |= NET_ACTOR_T6;
#if !defined SAMESIZE_ACTOR_T
if (T6 >= (intptr_t)&script[0] && T6 < (intptr_t)(&script[g_scriptSize]))
{
*flags |= NET_ACTOR_PTR3;
*(int32_t *)&pbuf[j] = (int32_t)(actor[i].t_data[5] - (intptr_t)&script[0]);
}
else *(int32_t *)&pbuf[j] = actor[i].t_data[5];
else
#endif
*(int32_t *)&pbuf[j] = actor[i].t_data[5];
j += sizeof(int32_t);
}
@ -1810,6 +1823,10 @@ void Net_ParseServerPacket(ENetEvent *event)
i = g_player[l].ps->i;
{
#if defined SAMESIZE_ACTOR_T
j++;
Bmemcpy(&T5, &pbuf[j], sizeof(T5));
#else
int16_t jj = j++;
int32_t oa = (T5 >= (intptr_t)&script[0] && T5 < (intptr_t)&script[g_scriptSize]) ? T5-(intptr_t)&script[0] : T5;
@ -1818,6 +1835,7 @@ void Net_ParseServerPacket(ENetEvent *event)
if (oa != T5) T3 = T4 = 0;
if (pbuf[jj] & 2) T5 += (intptr_t)&script[0];
#endif
}
do
@ -2794,10 +2812,13 @@ void Net_UpdateClients(void)
i = g_player[l].ps->i;
{
int32_t jj, oa;
int32_t jj;
#if !defined SAMESIZE_ACTOR_T
int32_t oa;
#endif
packbuf[(jj = j++)] = 0;
#if !defined SAMESIZE_ACTOR_T
if (T5 >= (intptr_t)&script[0] && T5 < (intptr_t)(&script[g_scriptSize]))
{
packbuf[jj] |= 2;
@ -2805,13 +2826,15 @@ void Net_UpdateClients(void)
}
oa = T5;
#endif
Bmemcpy(&packbuf[j], &T5, sizeof(T5));
j += sizeof(T5);
#if !defined SAMESIZE_ACTOR_T
if (oa != T5) T3 = T4 = 0;
if (packbuf[jj] & 2) T5 += (intptr_t)&script[0];
#endif
}
{

View file

@ -206,7 +206,10 @@ int32_t G_LoadPlayer(int32_t spot)
{
char fn[13];
char mpfn[13];
char *fnptr, *scriptptrs;
char *fnptr;
#if !defined SAMESIZE_ACTOR_T
char *scriptptrs;
#endif
int32_t fil, bv, i, x;
intptr_t j;
int32_t nump;
@ -401,22 +404,27 @@ int32_t G_LoadPlayer(int32_t spot)
if (kdfread(&actorLoadEventScrptr[0],sizeof(&actorLoadEventScrptr[0]),MAXTILES,fil) != MAXTILES) goto corrupt;
G_Util_PtrToIdx(actorLoadEventScrptr, MAXTILES, script, P2I_BACK_NON0);
#if !defined SAMESIZE_ACTOR_T
scriptptrs = Bmalloc(MAXSPRITES * sizeof(scriptptrs));
if (kdfread(&scriptptrs[0],sizeof(scriptptrs),MAXSPRITES,fil) != MAXSPRITES) goto corrupt;
#endif
if (kdfread(&actor[0],sizeof(actor_t),MAXSPRITES,fil) != MAXSPRITES) goto corrupt;
for (i=0; i<MAXSPRITES; i++)
{
#if !defined SAMESIZE_ACTOR_T
j = (intptr_t)script;
if (scriptptrs[i]&1) T2 += j;
if (scriptptrs[i]&2) T5 += j;
if (scriptptrs[i]&4) T6 += j;
#endif
actor[i].projectile = &SpriteProjectile[i];
}
#if !defined SAMESIZE_ACTOR_T
Bfree(scriptptrs);
#endif
if (kdfread(&lockclock,sizeof(lockclock),1,fil) != 1) goto corrupt;
if (kdfread(&pskybits,sizeof(pskybits),1,fil) != 1) goto corrupt;
if (kdfread(&pskyoff[0],sizeof(pskyoff[0]),MAXPSKYTILES,fil) != MAXPSKYTILES) goto corrupt;
@ -667,7 +675,10 @@ int32_t G_SavePlayer(int32_t spot)
intptr_t j;
char fn[13];
char mpfn[13];
char *fnptr, *scriptptrs;
char *fnptr;
#if !defined SAMESIZE_ACTOR_T
char *scriptptrs;
#endif
FILE *fil;
int32_t bv = BYTEVERSION;
@ -778,19 +789,16 @@ int32_t G_SavePlayer(int32_t spot)
dfwrite(&cloudy[0],sizeof(int16_t)<<7,1,fil);
dfwrite(&g_scriptSize,sizeof(g_scriptSize),1,fil);
scriptptrs = Bcalloc(1, g_scriptSize * sizeof(scriptptrs));
for (i=0; i<g_scriptSize; i++)
{
if (bitptr[i>>3]&(BITPTR_POINTER<<(i&7)))
{
// scriptptrs[i] = 1;
j = (intptr_t)script[i] - (intptr_t)&script[0];
script[i] = j;
}
// else scriptptrs[i] = 0;
}
// dfwrite(&scriptptrs[0],sizeof(scriptptrs),g_scriptSize,fil);
dfwrite(&bitptr[0],sizeof(bitptr[0]),(g_scriptSize+7)>>3,fil);
dfwrite(&script[0],sizeof(script[0]),g_scriptSize,fil);
@ -809,7 +817,7 @@ int32_t G_SavePlayer(int32_t spot)
dfwrite(&actorLoadEventScrptr[0],sizeof(actorLoadEventScrptr[0]),MAXTILES,fil);
G_Util_PtrToIdx(actorLoadEventScrptr, MAXTILES, script, P2I_BACK_NON0);
Bfree(scriptptrs);
#if !defined SAMESIZE_ACTOR_T
scriptptrs = Bcalloc(1, MAXSPRITES * sizeof(scriptptrs));
for (i=0; i<MAXSPRITES; i++)
@ -838,8 +846,11 @@ int32_t G_SavePlayer(int32_t spot)
}
dfwrite(&scriptptrs[0],sizeof(scriptptrs),MAXSPRITES,fil);
#endif
dfwrite(&actor[0],sizeof(actor_t),MAXSPRITES,fil);
#if !defined SAMESIZE_ACTOR_T
for (i=0; i<MAXSPRITES; i++)
{
if (actorscrptr[PN] == 0) continue;
@ -854,6 +865,7 @@ int32_t G_SavePlayer(int32_t spot)
}
Bfree(scriptptrs);
#endif
dfwrite(&lockclock,sizeof(lockclock),1,fil);
dfwrite(&pskybits,sizeof(pskybits),1,fil);
@ -957,7 +969,13 @@ typedef struct dataspec_
#else
# define SV_MAJOR_VER 0
#endif
#define SV_MINOR_VER 3
#ifdef SAMESIZE_ACTOR_T
# define SV_MINOR_VER 4
#else
# define SV_MINOR_VER 3
#endif
#define SV_DEFAULTCOMPRTHRES 8
static uint8_t savegame_diffcompress; // 0:none, 1:Ken's LZW in cache1d.c
static uint8_t savegame_comprthres;
@ -1084,7 +1102,6 @@ static int32_t readspecdata(const dataspec_t *spec, int32_t fil, uint8_t **dumpv
OSD_Printf("kread returned %d, expected %d.\n", j, i);
else
OSD_Printf("sp->ptr and cmpstrbuf not identical!\n");
// *(int32_t *)0 = 1;
return -1;
}
continue;
@ -1116,7 +1133,6 @@ static int32_t readspecdata(const dataspec_t *spec, int32_t fil, uint8_t **dumpv
if (i==-1)
perror("read");
// *(int32_t *)0 = 1;
return -1;
}
}
@ -1268,10 +1284,8 @@ static int32_t applydiff(const dataspec_t *spec, uint8_t **dumpvar, uint8_t **di
int32_t cnt, eltnum=-1, nbytes=(getnumvar(spec)+7)>>3, l=Bstrlen(spec->ptr);
if (Bmemcmp(diffptr, spec->ptr, l)) // check STRING magic (sync check)
{
// *(int32_t *)0 = 1;
return 1;
}
diffptr += l+nbytes;
for (sp++; sp->flags!=DS_END; sp++)
@ -1409,7 +1423,9 @@ static void sv_restload();
((sizeof(g_player[0].user_name)+sizeof(g_player[0].pcolor)+sizeof(g_player[0].pteam) \
+sizeof(g_player[0].frags)+sizeof(DukePlayer_t))*MAXPLAYERS + sizeof(_prlight)*PR_MAXLIGHTS + sizeof(lightcount))
#if !defined SAMESIZE_ACTOR_T
static uint8_t savegame_bitmap[MAXSPRITES>>3][3];
#endif
static uint32_t savegame_bitptrsize;
static uint8_t savegame_quotedef[MAXQUOTES>>3];
static char(*savegame_quotes)[MAXQUOTELEN];
@ -1515,7 +1531,9 @@ static const dataspec_t svgm_script[] =
{ DS_SAVEFN|DS_LOADFN|DS_NOCHK, (void *)&sv_postscript_once, 0, 1 },
{ DS_SAVEFN, (void *)&sv_preactordatasave, 0, 1 },
#if !defined SAMESIZE_ACTOR_T
{ 0, &savegame_bitmap, sizeof(savegame_bitmap), 1 },
#endif
{ 0, &actor[0], sizeof(actor_t), MAXSPRITES },
{ DS_SAVEFN|DS_LOADFN, (void *)&sv_postactordata, 0, 1 },
@ -1926,27 +1944,31 @@ static void sv_postscript_once()
if (bitptr[i>>3]&(BITPTR_POINTER<<(i&7)))
script[i] = (intptr_t)(script[i] + &script[0]);
}
static void sv_preactordatasave()
{
int32_t i;
#if !defined SAMESIZE_ACTOR_T
intptr_t j=(intptr_t)&script[0], k=(intptr_t)&script[g_scriptSize];
Bmemset(savegame_bitmap, 0, sizeof(savegame_bitmap));
#endif
for (i=0; i<MAXSPRITES; i++)
{
actor[i].lightptr = NULL;
actor[i].lightId = -1;
#if !defined SAMESIZE_ACTOR_T
if (sprite[i].statnum==MAXSTATUS || actorscrptr[PN]==NULL) continue;
if (T2 >= j && T2 < k) savegame_bitmap[i>>3][0] |= 1<<(i&7), T2 -= j;
if (T5 >= j && T5 < k) savegame_bitmap[i>>3][1] |= 1<<(i&7), T5 -= j;
if (T6 >= j && T6 < k) savegame_bitmap[i>>3][2] |= 1<<(i&7), T6 -= j;
#endif
}
}
static void sv_postactordata()
{
int32_t i;
intptr_t j=(intptr_t)script;
#if POLYMER
if (getrendermode() == 4)
@ -1960,10 +1982,12 @@ static void sv_postactordata()
actor[i].projectile = &SpriteProjectile[i];
#if !defined SAMESIZE_ACTOR_T
if (sprite[i].statnum==MAXSTATUS || actorscrptr[PN]==NULL) continue;
if (savegame_bitmap[i>>3][0]&(1<<(i&7))) T2 += j;
if (savegame_bitmap[i>>3][1]&(1<<(i&7))) T5 += j;
if (savegame_bitmap[i>>3][2]&(1<<(i&7))) T6 += j;
if (savegame_bitmap[i>>3][0]&(1<<(i&7))) T2 += (intptr_t)script;
if (savegame_bitmap[i>>3][1]&(1<<(i&7))) T5 += (intptr_t)script;
if (savegame_bitmap[i>>3][2]&(1<<(i&7))) T6 += (intptr_t)script;
#endif
}
}

View file

@ -62,7 +62,9 @@ typedef struct {
uint8_t g_earthquakeTime;
uint8_t g_numPlayerSprites;
#if !defined SAMESIZE_ACTOR_T
uint8_t scriptptrs[MAXSPRITES];
#endif
uint8_t show2dsector[(MAXSECTORS+7)>>3];
actor_t actor[MAXSPRITES];