Clean up A_InsertSprite() and the beginning of A_Spawn()

git-svn-id: https://svn.eduke32.com/eduke32@7234 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-11-18 18:14:33 +00:00
parent c4f76e55a6
commit c29ffec9cb

View file

@ -1265,16 +1265,12 @@ static int32_t G_InitActor(int32_t i, int32_t tilenum, int32_t set_movflag_uncon
return 0; return 0;
} }
static actor_t NullActor;
static spriteext_t NullSprExt;
static spritesmooth_t NullSprSmooth;
int32_t A_InsertSprite(int16_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int16_t s_pn,int8_t s_s, int32_t A_InsertSprite(int16_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int16_t s_pn,int8_t s_s,
uint8_t s_xr,uint8_t s_yr,int16_t s_a,int16_t s_ve,int16_t s_zv,int16_t s_ow,int16_t s_ss) uint8_t s_xr,uint8_t s_yr,int16_t s_a,int16_t s_ve,int16_t s_zv,int16_t s_ow,int16_t s_ss)
{ {
int32_t i = Net_IsRelevantStat(s_ss) ? Net_InsertSprite(whatsect, s_ss) : insertsprite(whatsect, s_ss); int const newSprite = Net_IsRelevantStat(s_ss) ? Net_InsertSprite(whatsect, s_ss) : insertsprite(whatsect, s_ss);
if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXSPRITES)) if (EDUKE32_PREDICT_FALSE((unsigned)newSprite >= MAXSPRITES))
{ {
G_DumpDebugInfo(); G_DumpDebugInfo();
OSD_Printf("Failed spawning pic %d spr from pic %d spr %d at x:%d,y:%d,z:%d,sect:%d\n", OSD_Printf("Failed spawning pic %d spr from pic %d spr %d at x:%d,y:%d,z:%d,sect:%d\n",
@ -1282,54 +1278,53 @@ int32_t A_InsertSprite(int16_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int1
G_GameExit("Too many sprites spawned."); G_GameExit("Too many sprites spawned.");
} }
uspritetype spr_temp = { s_x, s_y, s_z, 0, s_pn, s_s, 0, 0, 0, s_xr, s_yr, 0,
0, whatsect, s_ss, s_a, s_ow, s_ve, 0, s_zv, 0, 0, 0 };
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS
g_spriteStat.numins++; g_spriteStat.numins++;
#endif #endif
spritetype *s = &sprite[i]; sprite[newSprite] = { s_x, s_y, s_z, 0, s_pn, s_s, 0, 0, 0, s_xr, s_yr, 0, 0, whatsect, s_ss, s_a, s_ow, s_ve, 0, s_zv, 0, 0, 0 };
*s = *(spritetype *)&spr_temp;
actor[i] = NullActor; auto &a = actor[newSprite];
actor[i].bpos = *(vec3_t *)s; a = {};
a.bpos = { s_x, s_y, s_z };
if ((unsigned)s_ow < MAXSPRITES) if ((unsigned)s_ow < MAXSPRITES)
{ {
actor[i].picnum = sprite[s_ow].picnum; a.picnum = sprite[s_ow].picnum;
actor[i].floorz = actor[s_ow].floorz; a.floorz = actor[s_ow].floorz;
actor[i].ceilingz = actor[s_ow].ceilingz; a.ceilingz = actor[s_ow].ceilingz;
} }
actor[i].stayput = actor[i].extra = -1; a.stayput = -1;
a.extra = -1;
#ifdef POLYMER #ifdef POLYMER
actor[i].lightId = -1; a.lightId = -1;
#endif #endif
actor[i].owner = s_ow; a.owner = s_ow;
G_InitActor(i, s_pn, 1); G_InitActor(newSprite, s_pn, 1);
spriteext[i] = NullSprExt; spriteext[newSprite] = {};
spritesmooth[i] = NullSprSmooth; spritesmooth[newSprite] = {};
#if defined LUNATIC #if defined LUNATIC
if (!g_noResetVars) if (!g_noResetVars)
#endif #endif
A_ResetVars(i); A_ResetVars(newSprite);
#if defined LUNATIC #if defined LUNATIC
g_noResetVars = 0; g_noResetVars = 0;
#endif #endif
if (VM_HaveEvent(EVENT_EGS)) if (VM_HaveEvent(EVENT_EGS))
{ {
int32_t p, pl = A_FindPlayer(s, &p); int32_t p, pl = A_FindPlayer(&sprite[newSprite], &p);
block_deletesprite++; block_deletesprite++;
VM_OnEventWithDist__(EVENT_EGS, i, pl, p); VM_OnEventWithDist__(EVENT_EGS, newSprite, pl, p);
block_deletesprite--; block_deletesprite--;
} }
return i; return newSprite;
} }
#ifdef YAX_ENABLE #ifdef YAX_ENABLE
@ -1373,7 +1368,6 @@ int A_Spawn(int spriteNum, int tileNum)
actor_t * pActor; actor_t * pActor;
int sectNum; int sectNum;
if (spriteNum >= 0) if (spriteNum >= 0)
{ {
// spawn from parent sprite <j> // spawn from parent sprite <j>
@ -1385,79 +1379,73 @@ int A_Spawn(int spriteNum, int tileNum)
{ {
// spawn from already existing sprite <pn> // spawn from already existing sprite <pn>
newSprite = tileNum; newSprite = tileNum;
spritetype *const pSprite = &sprite[newSprite]; auto &s = sprite[newSprite];
actor_t *const pActor = &actor[newSprite]; auto &a = actor[newSprite];
Bmemset(&actor[newSprite], 0, sizeof(actor_t)); a = { };
Bmemcpy(&pActor->bpos, &sprite[newSprite], sizeof(vec3_t)); a.bpos = { s.x, s.y, s.z };
pActor->picnum = pSprite->picnum; a.picnum = s.picnum;
if (pSprite->picnum == SECTOREFFECTOR && pSprite->lotag == 50) if (s.picnum == SECTOREFFECTOR && s.lotag == 50)
pActor->picnum = pSprite->owner; a.picnum = s.owner;
pSprite->owner = pActor->owner = newSprite; s.owner = a.owner = newSprite;
pActor->floorz = sector[pSprite->sectnum].floorz; a.floorz = sector[s.sectnum].floorz;
pActor->ceilingz = sector[pSprite->sectnum].ceilingz; a.ceilingz = sector[s.sectnum].ceilingz;
pActor->stayput = pActor->extra = -1; a.stayput = a.extra = -1;
#ifdef POLYMER #ifdef POLYMER
pActor->lightId = -1; a.lightId = -1;
#endif #endif
if ((pSprite->cstat & 48) if ((s.cstat & 48)
#ifndef EDUKE32_STANDALONE #ifndef EDUKE32_STANDALONE
&& pSprite->picnum != SPEAKER && s.picnum != SPEAKER && s.picnum != LETTER && s.picnum != DUCK && s.picnum != TARGET && s.picnum != TRIPBOMB
&& pSprite->picnum != LETTER
&& pSprite->picnum != DUCK
&& pSprite->picnum != TARGET
&& pSprite->picnum != TRIPBOMB
#endif #endif
&& pSprite->picnum != VIEWSCREEN && s.picnum != VIEWSCREEN && s.picnum != VIEWSCREEN2 && (!(s.picnum >= CRACK1 && s.picnum <= CRACK4)))
&& pSprite->picnum != VIEWSCREEN2
&& (!(pSprite->picnum >= CRACK1 && pSprite->picnum <= CRACK4)))
{ {
if (pSprite->shade == 127) if (s.shade == 127)
goto SPAWN_END; goto SPAWN_END;
#ifndef EDUKE32_STANDALONE #ifndef EDUKE32_STANDALONE
if (A_CheckSwitchTile(newSprite) && (pSprite->cstat & 16)) if (A_CheckSwitchTile(newSprite) && (s.cstat & 16))
{ {
if (pSprite->pal && pSprite->picnum != ACCESSSWITCH && pSprite->picnum != ACCESSSWITCH2) if (s.pal && s.picnum != ACCESSSWITCH && s.picnum != ACCESSSWITCH2)
{ {
if (((!g_netServer && ud.multimode < 2)) || ((g_netServer || ud.multimode > 1) && !GTFLAGS(GAMETYPE_DMSWITCHES))) if (((!g_netServer && ud.multimode < 2)) || ((g_netServer || ud.multimode > 1) && !GTFLAGS(GAMETYPE_DMSWITCHES)))
{ {
pSprite->xrepeat = pSprite->yrepeat = 0; s.xrepeat = s.yrepeat = 0;
pSprite->lotag = pSprite->hitag = 0; s.lotag = s.hitag = 0;
pSprite->cstat = 32768; s.cstat = 32768;
goto SPAWN_END; goto SPAWN_END;
} }
} }
pSprite->cstat |= 257; s.cstat |= 257;
if (pSprite->pal && pSprite->picnum != ACCESSSWITCH && pSprite->picnum != ACCESSSWITCH2) if (s.pal && s.picnum != ACCESSSWITCH && s.picnum != ACCESSSWITCH2)
pSprite->pal = 0; s.pal = 0;
goto SPAWN_END; goto SPAWN_END;
} }
#endif #endif
if (pSprite->hitag) if (s.hitag)
{ {
changespritestat(newSprite, STAT_FALLER); changespritestat(newSprite, STAT_FALLER);
pSprite->cstat |= 257; s.cstat |= 257;
pSprite->extra = g_impactDamage; s.extra = g_impactDamage;
goto SPAWN_END; goto SPAWN_END;
} }
} }
if (pSprite->cstat & 1) if (s.cstat & 1)
pSprite->cstat |= 256; s.cstat |= 256;
if (!G_InitActor(newSprite, pSprite->picnum, 0)) if (!G_InitActor(newSprite, s.picnum, 0))
T2(newSprite) = T5(newSprite) = 0; // AC_MOVE_ID, AC_ACTION_ID T2(newSprite) = T5(newSprite) = 0; // AC_MOVE_ID, AC_ACTION_ID
} }
@ -5674,14 +5662,9 @@ static void G_CompileScripts(void)
if ((uint32_t)g_labelCnt > MAXSPRITES*sizeof(spritetype)/64) // see the arithmetic above for why if ((uint32_t)g_labelCnt > MAXSPRITES*sizeof(spritetype)/64) // see the arithmetic above for why
G_GameExit("Error: too many labels defined!"); G_GameExit("Error: too many labels defined!");
{ auto newlabel = (char *)Xmalloc(g_labelCnt << 6);
char *newlabel; auto newlabelcode = (int32_t *)Xmalloc(g_labelCnt * sizeof(int32_t));
int32_t *newlabelcode; auto newlabeltype = (int32_t *)Xmalloc(g_labelCnt * sizeof(int32_t));
int32_t *newlabeltype;
newlabel = (char *)Xmalloc(g_labelCnt << 6);
newlabelcode = (int32_t *)Xmalloc(g_labelCnt * sizeof(int32_t));
newlabeltype = (int32_t *)Xmalloc(g_labelCnt * sizeof(int32_t));
Bmemcpy(newlabel, label, g_labelCnt * 64); Bmemcpy(newlabel, label, g_labelCnt * 64);
Bmemcpy(newlabelcode, labelcode, g_labelCnt * sizeof(int32_t)); Bmemcpy(newlabelcode, labelcode, g_labelCnt * sizeof(int32_t));
@ -5690,7 +5673,6 @@ static void G_CompileScripts(void)
label = newlabel; label = newlabel;
labelcode = newlabelcode; labelcode = newlabelcode;
labeltype = newlabeltype; labeltype = newlabeltype;
}
Bmemset(sprite, 0, MAXSPRITES*sizeof(spritetype)); Bmemset(sprite, 0, MAXSPRITES*sizeof(spritetype));
Bmemset(sector, 0, MAXSECTORS*sizeof(sectortype)); Bmemset(sector, 0, MAXSECTORS*sizeof(sectortype));