- Duke: Leverage new spritetype methods within Duke, removing bposx/bposy/bposz from hittype.

This commit is contained in:
Mitchell Richters 2021-01-06 06:20:55 +11:00
parent 07a43c572e
commit 97159c20c1
13 changed files with 62 additions and 123 deletions

View file

@ -415,16 +415,14 @@ void moveplayers(void)
auto p = &ps[pn];
auto spri = &act->s;
// Back up player's sprite angle, used in DrawAutomapPlayer() when input is synchronised.
act->tempang = spri->ang;
if (act->GetOwner())
{
if (p->newOwner != nullptr) //Looking thru the camera
{
spri->x = p->oposx;
spri->y = p->oposy;
act->bposz = spri->z = p->oposz + gs.playerheight;
spri->z = p->oposz + gs.playerheight;
spri->backupz();
spri->ang = p->angle.oang.asbuild();
setsprite(act, spri->pos);
}
@ -503,9 +501,7 @@ void moveplayers(void)
continue;
}
act->bposx = spri->x;
act->bposy = spri->y;
act->bposz = spri->z;
spri->backuppos();
spri->cstat = 0;
@ -811,9 +807,7 @@ void movecrane(DDukeActor *actor, int crane)
{
setsprite(Owner, spri->pos);
Owner->bposx = spri->x;
Owner->bposy = spri->y;
Owner->bposz = spri->z;
Owner->s.opos = spri->pos;
spri->zvel = 0;
}
@ -1081,7 +1075,8 @@ void movewaterdrip(DDukeActor *actor, int drip)
}
else
{
actor->bposz = s->z = t[0];
s->z = t[0];
s->backupz();
t[1] = 48 + (krand() & 31);
}
}
@ -2016,9 +2011,6 @@ void camera(DDukeActor *actor)
}
}
// backup current angle for interpolating camera angle.
actor->tempang = s->ang;
if (s->hitag > 0)
{
// alias our temp_data array indexes.
@ -2972,8 +2964,7 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6)
if (numplayers > 1)
{
a2->bposx = sj->x;
a2->bposy = sj->y;
sj->backupvec2();
}
}
}
@ -3083,8 +3074,7 @@ void handle_se30(DDukeActor *actor, int JIBS6)
{
if (a2->s.picnum != SECTOREFFECTOR && a2->s.picnum != LOCATORS)
{
a2->bposx = a2->s.x;
a2->bposy = a2->s.y;
a2->s.backupvec2();
}
}
@ -3150,8 +3140,7 @@ void handle_se30(DDukeActor *actor, int JIBS6)
{
if (numplayers < 2)
{
a2->bposx = spa2->x;
a2->bposy = spa2->y;
spa2->backupvec2();
}
spa2->x += l;
@ -3159,8 +3148,7 @@ void handle_se30(DDukeActor *actor, int JIBS6)
if (numplayers > 1)
{
a2->bposx = spa2->x;
a2->bposy = spa2->y;
spa2->backupvec2();
}
}
}
@ -3995,7 +3983,7 @@ void handle_se17(DDukeActor* actor)
}
if (act1->s.statnum != STAT_EFFECTOR)
{
act1->bposz = act1->s.z;
act1->s.backupz();
act1->s.z += q;
}
@ -4065,9 +4053,7 @@ void handle_se17(DDukeActor* actor)
spr3->y += spr2->y - s->y;
spr3->z = sector[spr2->sectnum].floorz - (sc->floorz - spr3->z);
act3->bposx = spr3->x;
act3->bposy = spr3->y;
act3->bposz = spr3->z;
spr3->backuppos();
changespritesect(act3, spr2->sectnum);
setsprite(act3, spr3->pos);
@ -4119,7 +4105,8 @@ void handle_se18(DDukeActor *actor, bool morecheck)
if (ps[a2->PlayerIndex()].on_ground == 1) ps[a2->PlayerIndex()].posz += sc->extra;
if (a2->s.zvel == 0 && a2->s.statnum != STAT_EFFECTOR && a2->s.statnum != STAT_PROJECTILE)
{
a2->bposz = a2->s.z += sc->extra;
a2->s.z += sc->extra;
a2->s.backupz();
a2->floorz = sc->floorz;
}
}
@ -4156,7 +4143,8 @@ void handle_se18(DDukeActor *actor, bool morecheck)
if (ps[a2->PlayerIndex()].on_ground == 1) ps[a2->PlayerIndex()].posz -= sc->extra;
if (a2->s.zvel == 0 && a2->s.statnum != STAT_EFFECTOR && a2->s.statnum != STAT_PROJECTILE)
{
a2->bposz = a2->s.z -= sc->extra;
a2->s.z -= sc->extra;
a2->s.backupz();
a2->floorz = sc->floorz;
}
}
@ -4442,8 +4430,7 @@ void handle_se26(DDukeActor* actor)
{
if (a2->s.statnum != 3 && a2->s.statnum != 10)
{
a2->bposx = a2->s.x;
a2->bposy = a2->s.y;
a2->s.backupvec2();
a2->s.x += l;
a2->s.y += x;
@ -4579,8 +4566,7 @@ void handle_se24(DDukeActor *actor, int16_t *list1, int16_t *list2, int TRIPBOMB
{
if (s2->z > (a2->floorz - (16 << 8)))
{
a2->bposx = s2->x;
a2->bposy = s2->y;
s2->backupvec2();
s2->x += x >> shift;
s2->y += l >> shift;
@ -5395,9 +5381,7 @@ void recordoldspritepos()
DukeStatIterator it(statNum);
while (auto ac = it.Next())
{
ac->bposx = ac->s.x;
ac->bposy = ac->s.y;
ac->bposz = ac->s.z;
ac->s.backuploc();
}
}
}

View file

@ -2075,9 +2075,7 @@ void movetransports_d(void)
ps[p].oposz = ps[p].posz;
auto pa = ps[p].GetActor();
pa->bposx = ps[p].posx;
pa->bposy = ps[p].posy;
pa->bposz = ps[p].posz;
pa->s.opos = ps[p].pos;
changespritesect(act2, Owner->s.sectnum);
ps[p].cursectnum = Owner->s.sectnum;
@ -2240,9 +2238,7 @@ void movetransports_d(void)
spr2->z -= spr->z - sector[Owner->s.sectnum].floorz;
spr2->ang = Owner->s.ang;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
if (spr->pal == 0)
{
@ -2268,9 +2264,7 @@ void movetransports_d(void)
spr2->y += (Owner->s.y - spr->y);
spr2->z = Owner->s.z + 4096;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
changespritesect(act2, Owner->s.sectnum);
}
@ -2280,9 +2274,7 @@ void movetransports_d(void)
spr2->y += (Owner->s.y - spr->y);
spr2->z = sector[Owner->s.sectnum].ceilingz + ll;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
changespritesect(act2, Owner->s.sectnum);
@ -2292,9 +2284,7 @@ void movetransports_d(void)
spr2->y += (Owner->s.y - spr->y);
spr2->z = sector[Owner->s.sectnum].floorz - ll;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
changespritesect(act2, Owner->s.sectnum);
@ -3849,10 +3839,9 @@ void move_d(DDukeActor *actor, int playernum, int xvel)
if (t[1] == 0 || a == 0)
{
if ((badguy(actor) && spr->extra <= 0) || (actor->bposx != spr->x) || (actor->bposy != spr->y))
if ((badguy(actor) && spr->extra <= 0) || (spr->ox != spr->x) || (spr->oy != spr->y))
{
actor->bposx = spr->x;
actor->bposy = spr->y;
spr->backupvec2();
setsprite(actor, spr->pos);
}
return;
@ -3957,7 +3946,7 @@ void move_d(DDukeActor *actor, int playernum, int xvel)
}
else if (spr->picnum != DRONE && spr->picnum != SHARK && spr->picnum != COMMANDER)
{
if (actor->bposz != spr->z || (ud.multimode < 2 && ud.player_skill < 2))
if (spr->oz != spr->z || (ud.multimode < 2 && ud.player_skill < 2))
{
if ((t[0] & 1) || ps[playernum].actorsqu == actor) return;
else daxvel <<= 1;

View file

@ -1846,9 +1846,7 @@ void movetransports_r(void)
spr2->z -= spr->z - sector[Owner->s.sectnum].floorz;
spr2->ang = Owner->s.ang;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
auto beam = spawn(act, TRANSPORTERBEAM);
S_PlayActorSound(TELEPORTER, beam);
@ -1871,9 +1869,7 @@ void movetransports_r(void)
spr2->y += (Owner->s.y - spr->y);
spr2->z = Owner->s.z + 4096;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
changespritesect(act2, Owner->s.sectnum);
}
@ -1883,9 +1879,7 @@ void movetransports_r(void)
spr2->y += (Owner->s.y - spr->y);
spr2->z = sector[Owner->s.sectnum].ceilingz + ll;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
changespritesect(act2, Owner->s.sectnum);
@ -1895,9 +1889,7 @@ void movetransports_r(void)
spr2->y += (Owner->s.y - spr->y);
spr2->z = sector[Owner->s.sectnum].floorz - ll;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
changespritesect(act2, Owner->s.sectnum);
@ -1909,9 +1901,7 @@ void movetransports_r(void)
spr2->y += (Owner->s.y - spr->y);
spr2->z = sector[Owner->s.sectnum].ceilingz + ll2;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
changespritesect(act2, Owner->s.sectnum);
@ -1925,9 +1915,7 @@ void movetransports_r(void)
spr2->y += (Owner->s.y - spr->y);
spr2->z = sector[Owner->s.sectnum].floorz - ll2;
act2->bposx = spr2->x;
act2->bposy = spr2->y;
act2->bposz = spr2->z;
spr2->backuppos();
changespritesect(act2, Owner->s.sectnum);
@ -3810,10 +3798,9 @@ void move_r(DDukeActor *actor, int pnum, int xvel)
if (t[1] == 0 || a == 0)
{
if ((badguy(actor) && spr->extra <= 0) || (actor->bposx != spr->x) || (actor->bposy != spr->y))
if ((badguy(actor) && spr->extra <= 0) || (spr->ox != spr->x) || (spr->oy != spr->y))
{
actor->bposx = spr->x;
actor->bposy = spr->y;
spr->backupvec2();
setsprite(actor, spr->pos);
}
if (badguy(actor) && spr->extra <= 0)
@ -3924,7 +3911,7 @@ void move_r(DDukeActor *actor, int pnum, int xvel)
(!isRRRA() && spr->picnum != DRONE && spr->picnum != SHARK && spr->picnum != UFO1_RR
&& spr->picnum != UFO2 && spr->picnum != UFO3 && spr->picnum != UFO4 && spr->picnum != UFO5))
{
if (actor->bposz != spr->z || (ud.multimode < 2 && ud.player_skill < 2))
if (spr->oz != spr->z || (ud.multimode < 2 && ud.player_skill < 2))
{
if ((t[0] & 1) || ps[pnum].actorsqu == actor) return;
else daxvel <<= 1;

View file

@ -182,9 +182,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio)
}
else if (s->picnum != CRANEPOLE)
{
t->x -= MulScale(MaxSmoothRatio - smoothratio, s->x - h->bposx, 16);
t->y -= MulScale(MaxSmoothRatio - smoothratio, s->y - h->bposy, 16);
t->z -= MulScale(MaxSmoothRatio - smoothratio, s->z - h->bposz, 16);
t->pos = s->interpolatedvec3(smoothratio);
}
sect = s->sectnum;

View file

@ -170,9 +170,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio)
}
else if (s->picnum != CRANEPOLE)
{
t->x -= MulScale(MaxSmoothRatio - smoothratio, s->x - h->bposx, 16);
t->y -= MulScale(MaxSmoothRatio - smoothratio, s->y - h->bposy, 16);
t->z -= MulScale(MaxSmoothRatio - smoothratio, s->z - h->bposz, 16);
t->pos = s->interpolatedvec3(smoothratio);
}
sect = s->sectnum;

View file

@ -559,9 +559,8 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang,
{
auto act = ps[p].GetActor();
auto pspr = &act->s;
x1 = act->bposx + MulScale(pspr->x - act->bposx, smoothratio, 16) - cposx;
y1 = act->bposy + MulScale(pspr->y - act->bposy, smoothratio, 16) - cposy;
daang = ((!SyncInput() ? pspr->ang : act->tempang + MulScale(((pspr->ang + 1024 - act->tempang) & 2047) - 1024, smoothratio, 16)) - cang) & 2047;
auto spos = pspr->interpolatedvec2(smoothratio);
daang = ((!SyncInput() ? pspr->ang : pspr->interpolatedang(smoothratio)) - cang) & 2047;
if (p == screenpeek || ud.coop == 1)
{
@ -577,7 +576,7 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang,
if (j < 22000) j = 22000;
else if (j > (65536 << 1)) j = (65536 << 1);
DrawTexture(twod, tileGetTexture(i), xdim / 2. + x1 / 4096., ydim / 2. + y1 / 4096., DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), pspr->pal), DTA_CenterOffset, true,
DrawTexture(twod, tileGetTexture(i), xdim / 2. + spos.x / 4096., ydim / 2. + spos.y / 4096., DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), pspr->pal), DTA_CenterOffset, true,
DTA_Rotate, daang * (-360./2048), DTA_Color, shadeToLight(pspr->shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE);
}
}

View file

@ -1314,16 +1314,16 @@ void DoActor(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
else SetGameVarID((int)lVar2, act->lastvy, sActor, sPlayer);
break;
case ACTOR_HTBPOSX:
if (bSet) act->bposx = lValue;
else SetGameVarID((int)lVar2, act->bposx, sActor, sPlayer);
if (bSet) spr->ox = lValue;
else SetGameVarID((int)lVar2, spr->ox, sActor, sPlayer);
break;
case ACTOR_HTBPOSY:
if (bSet) act->bposy = lValue;
else SetGameVarID((int)lVar2, act->bposy, sActor, sPlayer);
if (bSet) spr->oy = lValue;
else SetGameVarID((int)lVar2, spr->oy, sActor, sPlayer);
break;
case ACTOR_HTBPOSZ:
if (bSet) act->bposz = lValue;
else SetGameVarID((int)lVar2, act->bposz, sActor, sPlayer);
if (bSet) spr->oz = lValue;
else SetGameVarID((int)lVar2, spr->oz, sActor, sPlayer);
break;
case ACTOR_HTG_T0:
if (bSet) act->temp_data[0] = lValue;
@ -2229,9 +2229,10 @@ int ParseState::parse(void)
{
// I am not convinced this is even remotely smart to be executed from here..
pickrandomspot(g_p);
g_sp->x = g_ac->bposx = ps[g_p].bobposx = ps[g_p].oposx = ps[g_p].posx;
g_sp->y = g_ac->bposy = ps[g_p].bobposy = ps[g_p].oposy = ps[g_p].posy;
g_sp->z = g_ac->bposy = ps[g_p].oposz = ps[g_p].posz;
g_sp->x = ps[g_p].bobposx = ps[g_p].oposx = ps[g_p].posx;
g_sp->y = ps[g_p].bobposy = ps[g_p].oposy = ps[g_p].posy;
g_sp->z = ps[g_p].oposz = ps[g_p].posz;
g_sp->backuppos();
updatesector(ps[g_p].posx, ps[g_p].posy, &ps[g_p].cursectnum);
setsprite(ps[g_p].GetActor(), ps[g_p].posx, ps[g_p].posy, ps[g_p].posz + gs.playerheight);
g_sp->cstat = 257;

View file

@ -624,9 +624,10 @@ void resetpspritevars(int g)
ps[j].frag_ps = j;
act->SetOwner(act);
act->bposx = ps[j].bobposx = ps[j].oposx = ps[j].posx = s->x;
act->bposy = ps[j].bobposy = ps[j].oposy = ps[j].posy = s->y;
act->bposz = ps[j].oposz = ps[j].posz = s->z;
ps[j].bobposx = ps[j].oposx = ps[j].posx = s->x;
ps[j].bobposy = ps[j].oposy = ps[j].posy = s->y;
ps[j].oposz = ps[j].posz = s->z;
s->backuppos();
ps[j].angle.oang = ps[j].angle.ang = buildang(s->ang);
updatesector(s->x, s->y, &ps[j].cursectnum);

View file

@ -259,17 +259,6 @@ void renderMirror(int cposx, int cposy, int cposz, binangle cang, fixedhoriz cho
//
//---------------------------------------------------------------------------
static inline binangle getcamspriteang(DDukeActor* newOwner, double const smoothratio)
{
return buildfang(newOwner->tempang + MulScaleF(((newOwner->s.ang - newOwner->tempang + 1024) & 2047) - 1024, smoothratio, 16));
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void animatecamsprite(double smoothratio)
{
const int VIEWSCREEN_ACTIVE_DISTANCE = 8192;
@ -293,7 +282,7 @@ void animatecamsprite(double smoothratio)
screen->RenderTextureView(canvas, [=](IntRect& rect)
{
auto camera = &camsprite->GetOwner()->s;
auto ang = getcamspriteang(camsprite->GetOwner(), smoothratio);
auto ang = buildang(camera->interpolatedang(smoothratio));
// Note: no ROR or camera here for now - the current setup has no means to detect these things before rendering the scene itself.
renderDrawRoomsQ16(camera->x, camera->y, camera->z, ang.asq16(), IntToFixed(camera->shade), camera->sectnum); // why 'shade'...?
display_mirror = 1; // should really be 'display external view'.
@ -581,7 +570,7 @@ void displayrooms(int snum, double smoothratio)
if (p->newOwner != nullptr)
{
auto spr = &p->newOwner->s;
cang = getcamspriteang(p->newOwner, smoothratio);
cang = buildang(spr->interpolatedang(smoothratio));
choriz = buildhoriz(spr->shade);
cposx = spr->pos.x;
cposy = spr->pos.y;

View file

@ -287,9 +287,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, weaponhit& w, weap
("ceilingz", w.ceilingz, def->ceilingz)
("lastvx", w.lastvx, def->lastvx)
("lastvy", w.lastvy, def->lastvy)
("bposx", w.bposx, def->bposx)
("bposy", w.bposy, def->bposy)
("bposz", w.bposz, def->bposz)
("aflags", w.aflags, def->aflags)
("saved_ammo", w.saved_ammo, def->saved_ammo)
("temp_actor", w.temp_actor, def->temp_actor)

View file

@ -358,7 +358,7 @@ void doanimations(void)
{
if (act->s.statnum != STAT_EFFECTOR)
{
act->bposz = act->s.z;
act->s.backupz();
act->s.z += v;
act->floorz = sector[dasect].floorz + v;
}

View file

@ -58,9 +58,6 @@ DDukeActor* EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed ch
auto act = &hittype[i];
auto s = &act->s;
act->bposx = s_x;
act->bposy = s_y;
act->bposz = s_z;
s->x = s_x;
s->y = s_y;
@ -81,6 +78,7 @@ DDukeActor* EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed ch
s->clipdist = 0;
s->pal = 0;
s->lotag = 0;
s->backuploc();
act->lastvx = 0;
act->lastvy = 0;
@ -162,9 +160,7 @@ int initspriteforspawn(DDukeActor* actj, int pn, const std::initializer_list<int
act->timetosleep = 0;
act->extra = -1;
act->bposx = sp->x;
act->bposy = sp->y;
act->bposz = sp->z;
sp->backuppos();
act->SetOwner(act);
act->SetHitOwner(act);

View file

@ -28,7 +28,7 @@ struct weaponhit
short picnum, ang, extra, owner, movflag;
short tempang, actorstayput, dispicnum;
short timetosleep;
int floorz, ceilingz, lastvx, lastvy, bposx, bposy, bposz, aflags;
int floorz, ceilingz, lastvx, lastvy, aflags;
union
{
int saved_ammo;
@ -47,7 +47,7 @@ struct weaponhit
{
cgg = spriteextra = 0;
picnum = ang = extra = owner = movflag = tempang = actorstayput = dispicnum = timetosleep = 0;
floorz = ceilingz = lastvx = lastvy = bposx = bposy = bposz = aflags = saved_ammo = 0;
floorz = ceilingz = lastvx = lastvy = aflags = saved_ammo = 0;
memset(temp_data, 0, sizeof(temp_data));
}
int GetIndex() const { return this - array(); }