- cursectnum first half

This commit is contained in:
Christoph Oelckers 2021-11-21 08:45:07 +01:00
parent 265abf7fa6
commit 312b1fd39f
15 changed files with 70 additions and 63 deletions

View file

@ -747,6 +747,11 @@ inline walltype* sectortype::firstWall() const
return &wall[wallptr]; // cannot be -1 in a proper map
}
inline int cansee(int x1, int y1, int z1, sectortype* sect1, int x2, int y2, int z2, sectortype* sect2)
{
return cansee(x1, y1, z1, sector.IndexOf(sect1), x2, y2, z2, sector.IndexOf(sect2));
}
#include "iterators.h"

View file

@ -147,7 +147,7 @@ void se40code(int x, int y, int z, binangle a, fixedhoriz h, int smoothratio)
case 43:
case 44:
case 45:
if (ps[screenpeek].cursectnum == act->s->sectnum)
if (ps[screenpeek].cursector() == act->s->sector())
SE40_Draw(tag, act->s, x, y, z, a, h, smoothratio);
break;
}

View file

@ -619,7 +619,7 @@ void movefx(void)
{
if (act->temp_data[4] > 0) act->temp_data[4]--;
else for (p = connecthead; p >= 0; p = connectpoint2[p])
if (p == myconnectindex && ps[p].cursectnum == spri->sectnum)
if (p == myconnectindex && ps[p].cursector() == spri->sector())
{
S_PlaySound(spri->lotag + (unsigned)global_random % (spri->hitag + 1));
act->temp_data[4] = 26 * 40 + (global_random % (26 * 40));
@ -815,7 +815,7 @@ void movecrane(DDukeActor *actor, int crane)
ps[p].pos.y = spri->y - bsin(ang, -6);
ps[p].pos.z = spri->z + (2 << 8);
setsprite(ps[p].GetActor(), ps[p].pos.x, ps[p].pos.y, ps[p].pos.z);
ps[p].cursectnum = ps[p].GetActor()->s->sectnum;
ps[p].setCursector(ps[p].GetActor()->s->sector());
}
}
}
@ -1572,7 +1572,7 @@ bool queball(DDukeActor *actor, int pocket, int queball, int stripeball)
}
}
}
if (x < 512 && s->sectnum == ps[p].cursectnum)
if (x < 512 && s->sector() == ps[p].cursector())
{
s->ang = getangle(s->x - ps[p].pos.x, s->y - ps[p].pos.y);
s->xvel = 48;
@ -1724,7 +1724,7 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p
fi.shoot(actor, firelaser);
s->ang = a;
}
if (t[2] > (26 * 3) || !cansee(s->x, s->y, s->z - (16 << 8), s->sectnum, ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursectnum))
if (t[2] > (26 * 3) || !cansee(s->x, s->y, s->z - (16 << 8), s->sector(), ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursector()))
{
t[0] = 0;
t[2] = 0;
@ -1747,7 +1747,7 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p
else
{
t[2]++;
if (t[2] > (26 * 3) || !cansee(s->x, s->y, s->z - (16 << 8), s->sectnum, ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursectnum))
if (t[2] > (26 * 3) || !cansee(s->x, s->y, s->z - (16 << 8), s->sector(), ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursector()))
{
t[0] = 1;
t[2] = 0;
@ -2749,7 +2749,7 @@ void handle_se00(DDukeActor* actor, int LASERLINE)
int p;
for (p = connecthead; p >= 0; p = connectpoint2[p])
{
if (ps[p].cursectnum == s->sectnum && ps[p].on_ground == 1)
if (ps[p].cursector() == s->sector() && ps[p].on_ground == 1)
{
ps[p].angle.addadjustment(l * q);
@ -2905,13 +2905,13 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6)
auto psp = ps[p].GetActor();
if (psp->s->extra > 0)
{
int k = ps[p].cursectnum;
auto k = ps[p].cursector();
updatesector(ps[p].pos.x, ps[p].pos.y, &k);
if ((k == -1 && ud.clipping == 0) || (k == s->sectnum && ps[p].cursectnum != s->sectnum))
if ((k == nullptr && ud.clipping == 0) || (k == s->sector() && ps[p].cursector() != s->sector()))
{
ps[p].pos.x = s->x;
ps[p].pos.y = s->y;
ps[p].cursectnum = s->sectnum;
ps[p].setCursector(s->sector());
setsprite(ps[p].GetActor(), s->pos);
quickkill(&ps[p]);
@ -2989,13 +2989,13 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6)
{
if (ps[p].GetActor()->s->extra > 0)
{
int k = ps[p].cursectnum;
auto k = ps[p].cursector();
updatesector(ps[p].pos.x, ps[p].pos.y, &k);
if ((k == -1 && ud.clipping == 0) || (k == s->sectnum && ps[p].cursectnum != s->sectnum))
if ((k == nullptr && ud.clipping == 0) || (k == s->sector() && ps[p].cursector() != s->sector()))
{
ps[p].oposx = ps[p].pos.x = s->x;
ps[p].oposy = ps[p].pos.y = s->y;
ps[p].cursectnum = s->sectnum;
ps[p].setCursector(s->sector());
setsprite(ps[p].GetActor(), s->pos);
quickkill(&ps[p]);
@ -3092,13 +3092,13 @@ void handle_se30(DDukeActor *actor, int JIBS6)
auto psp = ps[p].GetActor();
if (psp->s->extra > 0)
{
int k = ps[p].cursectnum;
auto k = ps[p].cursector();
updatesector(ps[p].pos.x, ps[p].pos.y, &k);
if ((k == -1 && ud.clipping == 0) || (k == s->sectnum && ps[p].cursectnum != s->sectnum))
if ((k == nullptr && ud.clipping == 0) || (k == s->sector() && ps[p].cursector() != s->sector()))
{
ps[p].pos.x = s->x;
ps[p].pos.y = s->y;
ps[p].cursectnum = s->sectnum;
ps[p].setCursector(s->sector());
setsprite(ps[p].GetActor(), s->pos);
quickkill(&ps[p]);
@ -3155,9 +3155,9 @@ void handle_se30(DDukeActor *actor, int JIBS6)
for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (ps[p].GetActor()->s->extra > 0)
{
int k = ps[p].cursectnum;
auto k = ps[p].cursector();
updatesector(ps[p].pos.x, ps[p].pos.y, &k);
if ((k == -1 && ud.clipping == 0) || (k == s->sectnum && ps[p].cursectnum != s->sectnum))
if ((k == nullptr && ud.clipping == 0) || (k == s->sector() && ps[p].cursector() != s->sector()))
{
ps[p].pos.x = s->x;
ps[p].pos.y = s->y;
@ -3165,7 +3165,7 @@ void handle_se30(DDukeActor *actor, int JIBS6)
ps[p].oposx = ps[p].pos.x;
ps[p].oposy = ps[p].pos.y;
ps[p].cursectnum = s->sectnum;
ps[p].setCursector(s->sector());
setsprite(ps[p].GetActor(), s->pos);
quickkill(&ps[p]);
@ -3248,7 +3248,7 @@ void handle_se02(DDukeActor* actor)
for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (ps[p].cursectnum == s->sectnum && ps[p].on_ground)
if (ps[p].cursector() == s->sector() && ps[p].on_ground)
{
ps[p].pos.x += m;
ps[p].pos.y += x;
@ -4014,7 +4014,7 @@ void handle_se17(DDukeActor* actor)
ps[p].bobcounter = 0;
changeactorsect(act3, spr2->sectnum);
ps[p].cursectnum = spr2->sectnum;
ps[p].setCursector(spr2->sector());
}
else if (spr3->statnum != STAT_EFFECTOR)
{
@ -4282,7 +4282,7 @@ void handle_se20(DDukeActor* actor)
dragpoint(wal[1], wal[1]->x + x, wal[1]->y + l);
for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (ps[p].cursectnum == s->sectnum && ps[p].on_ground)
if (ps[p].cursector() == s->sector() && ps[p].on_ground)
{
ps[p].pos.x += x;
ps[p].pos.y += l;
@ -4437,7 +4437,7 @@ void handle_se27(DDukeActor* actor)
}
else if (ud.recstat == 2 && ps[p].newOwner == nullptr)
{
if (cansee(s->x, s->y, s->z, s->sectnum, ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursectnum))
if (cansee(s->x, s->y, s->z, s->sector(), ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursector()))
{
if (x < sh)
{
@ -4539,7 +4539,7 @@ void handle_se24(DDukeActor *actor, const int16_t *list1, const int16_t *list2,
for (auto p = connecthead; p >= 0; p = connectpoint2[p])
{
if (ps[p].cursectnum == actor->s->sectnum && ps[p].on_ground)
if (ps[p].cursector() == actor->s->sector() && ps[p].on_ground)
{
if (abs(ps[p].pos.z - ps[p].truefz) < gs.playerheight + (9 << 8))
{

View file

@ -730,13 +730,13 @@ void movefta_d(void)
int r1 = krand();
int r2 = krand();
j = cansee(sx, sy, s->z - (r2 % (52 << 8)), s->sectnum, px, py, ps[p].oposz - (r1 % (32 << 8)), ps[p].cursectnum);
j = cansee(sx, sy, s->z - (r2 % (52 << 8)), s->sector(), px, py, ps[p].oposz - (r1 % (32 << 8)), ps[p].cursector());
}
else
{
int r1 = krand();
int r2 = krand();
j = cansee(s->x, s->y, s->z - ((r2 & 31) << 8), s->sectnum, ps[p].oposx, ps[p].oposy, ps[p].oposz - ((r1 & 31) << 8), ps[p].cursectnum);
j = cansee(s->x, s->y, s->z - ((r2 & 31) << 8), s->sector(), ps[p].oposx, ps[p].oposy, ps[p].oposz - ((r1 & 31) << 8), ps[p].cursector());
}
@ -2032,7 +2032,7 @@ void movetransports_d(void)
}
for (int k = connecthead; k >= 0; k = connectpoint2[k])
if (ps[k].cursectnum == Owner->s->sectnum)
if (ps[k].cursector() == Owner->sector())
{
ps[k].frag_ps = p;
ps[k].GetActor()->s->extra = 0;
@ -2052,7 +2052,7 @@ void movetransports_d(void)
ps[p].oposz = ps[p].pos.z = Owner->s->z - gs.playerheight;
changeactorsect(act2, Owner->sector());
ps[p].cursectnum = spr2->sectnum;
ps[p].setCursector(spr2->sector());
if (spr->pal == 0)
{
@ -2081,7 +2081,7 @@ void movetransports_d(void)
pa->s->opos = ps[p].pos;
changeactorsect(act2, Owner->sector());
ps[p].cursectnum = Owner->s->sectnum;
ps[p].setCursector(Owner->sector());
break;
}
@ -2130,8 +2130,8 @@ void movetransports_d(void)
if (!Owner || Owner->GetOwner() != Owner)
ps[p].transporter_hold = -2;
ps[p].cursectnum = Owner->s->sectnum;
ps[p].setCursector(Owner->sector());
changeactorsect(act2, Owner->sector());
setsprite(ps[p].GetActor(), ps[p].pos.x, ps[p].pos.y, ps[p].pos.z + gs.playerheight);
@ -2985,7 +2985,7 @@ DETONATEB:
}
}
else if (s->picnum == HEAVYHBOMB && x < 788 && t[0] > 7 && s->xvel == 0)
if (cansee(s->x, s->y, s->z - (8 << 8), s->sectnum, ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursectnum))
if (cansee(s->x, s->y, s->z - (8 << 8), s->sector(), ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursector()))
if (ps[p].ammo_amount[HANDBOMB_WEAPON] < gs.max_ammo_amount[HANDBOMB_WEAPON])
{
if (ud.coop >= 1 && Owner == actor)
@ -3543,7 +3543,7 @@ static void handle_se28(DDukeActor* actor)
}
else if (t[2] > (t[1] >> 3) && t[2] < (t[1] >> 2))
{
int j = !!cansee(s->x, s->y, s->z, s->sectnum, ps[screenpeek].pos.x, ps[screenpeek].pos.y, ps[screenpeek].pos.z, ps[screenpeek].cursectnum);
int j = !!cansee(s->x, s->y, s->z, s->sector(), ps[screenpeek].pos.x, ps[screenpeek].pos.y, ps[screenpeek].pos.z, ps[screenpeek].cursector());
if (rnd(192) && (t[2] & 1))
{

View file

@ -553,14 +553,14 @@ void movefta_r(void)
{
int r1 = krand();
int r2 = krand();
j = cansee(sx, sy, s->z - (r2 % (52 << 8)), s->sectnum, px, py, ps[p].oposz - (r1 % (32 << 8)), ps[p].cursectnum);
j = cansee(sx, sy, s->z - (r2 % (52 << 8)), s->sector(), px, py, ps[p].oposz - (r1 % (32 << 8)), ps[p].cursector());
}
}
else
{
int r1 = krand();
int r2 = krand();
j = cansee(s->x, s->y, s->z - ((r2 & 31) << 8), s->sectnum, ps[p].oposx, ps[p].oposy, ps[p].oposz - ((r1 & 31) << 8), ps[p].cursectnum);
j = cansee(s->x, s->y, s->z - ((r2 & 31) << 8), s->sector(), ps[p].oposx, ps[p].oposy, ps[p].oposz - ((r1 & 31) << 8), ps[p].cursector());
}
@ -1611,7 +1611,7 @@ void movetransports_r(void)
S_PlayActorSound(TELEPORTER, act);
for (k = connecthead; k >= 0; k = connectpoint2[k])
if (ps[k].cursectnum == Owner->s->sectnum)
if (ps[k].cursector() == Owner->sector())
{
ps[k].frag_ps = p;
ps[k].GetActor()->s->extra = 0;
@ -1631,7 +1631,7 @@ void movetransports_r(void)
ps[p].oposz = ps[p].pos.z = Owner->s->z - (gs.playerheight - (4 << 8));
changeactorsect(act2, Owner->sector());
ps[p].cursectnum = spr2->sectnum;
ps[p].setCursector(spr2->sector());
auto beam = spawn(Owner, TRANSPORTERBEAM);
if (beam) S_PlayActorSound(TELEPORTER, beam);
@ -1654,7 +1654,7 @@ void movetransports_r(void)
ps[p].oposz = ps[p].pos.z;
changeactorsect(act2, Owner->sector());
ps[p].cursectnum = Owner->s->sectnum;
ps[p].setCursector(Owner->sector());
break;
}
@ -1716,7 +1716,7 @@ void movetransports_r(void)
if (Owner->GetOwner() != Owner)
ps[p].transporter_hold = -2;
ps[p].cursectnum = Owner->s->sectnum;
ps[p].setCursector(Owner->sector());
changeactorsect(act2, Owner->sector());
@ -1730,7 +1730,7 @@ void movetransports_r(void)
if (Owner->GetOwner() != Owner)
ps[p].transporter_hold = -2;
ps[p].cursectnum = Owner->s->sectnum;
ps[p].setCursector(Owner->sector());
changeactorsect(act2, Owner->sector());
}
@ -2488,7 +2488,7 @@ void rr_specialstats()
ps[p].oposz = ps[p].pos.z = act2->s->z - (36 << 8);
auto pact = ps[p].GetActor();
changeactorsect(pact, act2->s->sectnum);
ps[p].cursectnum = pact->s->sectnum;
ps[p].setCursector(pact->sector());
S_PlayActorSound(70, act2);
deletesprite(act2);
}
@ -2691,7 +2691,7 @@ DETONATEB:
}
}
else if (s->picnum == HEAVYHBOMB && x < 788 && t[0] > 7 && s->xvel == 0)
if (cansee(s->x, s->y, s->z - (8 << 8), s->sectnum, ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursectnum))
if (cansee(s->x, s->y, s->z - (8 << 8), s->sector(), ps[p].pos.x, ps[p].pos.y, ps[p].pos.z, ps[p].cursector()))
if (ps[p].ammo_amount[DYNAMITE_WEAPON] < gs.max_ammo_amount[DYNAMITE_WEAPON])
if (s->pal == 0)
{

View file

@ -206,6 +206,17 @@ inline int hitscan(int x, int y, int z, int sectnum, int32_t vx, int32_t vy, int
return res;
}
inline int hitscan(int x, int y, int z, sectortype* sect, int32_t vx, int32_t vy, int32_t vz,
sectortype** hitsect, walltype** hitwall, DDukeActor** hitspr, int* hitx, int* hity, int* hitz, uint32_t cliptype)
{
short hitsprt, hitsct, hitwal;
int res = ::hitscan(x, y, z, sectnum(sect), vx, vy, vz, &hitsct, &hitwal, &hitsprt, hitx, hity, hitz, cliptype);
if (hitspr) *hitspr = hitsprt == -1 ? nullptr : &hittype[hitsprt];
if (hitsect) *hitsect = hitsct >= 0? &sector[hitsct] : nullptr;
if (hitwall) *hitwall = hitwal >= 0? &wall[hitwal] : nullptr;
return res;
}
inline void neartag(int32_t xs, int32_t ys, int32_t zs, int sectnum, int ange,
sectortype** neartagsector, walltype** neartagwall, DDukeActor** neartagsprite,
int32_t* neartaghitdist, int32_t neartagrange, uint8_t tagsearch)

View file

@ -465,11 +465,6 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
if (!bSet) SetGameVarID(lVar2, 0, sActor, sPlayer);
break;
case PLAYER_CURSECTNUM:
if (bSet) ps[iPlayer].cursectnum = lValue;
else SetGameVarID(lVar2, ps[iPlayer].cursectnum, sActor, sPlayer);
break;
case PLAYER_LOOK_ANG:
if (bSet) ps[iPlayer].angle.look_ang = buildang(lValue);
else SetGameVarID(lVar2, ps[iPlayer].angle.look_ang.asbuild(), sActor, sPlayer);

View file

@ -526,7 +526,7 @@ enum
static void processInputBits(player_struct *p, ControlInfo* const hidInput)
{
// Set-up crouch bools.
int const sectorLotag = p->cursectnum != -1 ? p->cursector()->lotag : 0;
int const sectorLotag = p->insector() ? p->cursector()->lotag : 0;
bool const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge);
bool const disableToggle = p->jetpack_on || (!crouchable && p->on_ground) || (isRRRA() && (p->OnMotorcycle || p->OnBoat));

View file

@ -83,7 +83,7 @@ int setpal(struct player_struct* p)
int palette;
if (p->DrugMode) palette = DRUGPAL;
else if (p->heat_on) palette = SLIMEPAL;
else if (p->cursectnum < 0) palette = BASEPAL; // don't crash if out of range.
else if (!p->insector()) palette = BASEPAL; // don't crash if out of range.
else if (p->cursector()->ceilingpicnum >= TILE_FLOORSLIME && p->cursector()->ceilingpicnum <= TILE_FLOORSLIME + 2) palette = SLIMEPAL;
else if (p->cursector()->lotag == ST_2_UNDERWATER) palette = WATERPAL;
else palette = BASEPAL;
@ -215,7 +215,7 @@ int hitawall(struct player_struct* p, walltype** hitw)
{
int sx, sy, sz;
hitscan(p->pos.x, p->pos.y, p->pos.z, p->cursectnum,
hitscan(p->pos.x, p->pos.y, p->pos.z, p->cursector(),
p->angle.ang.bcos(), p->angle.ang.bsin(), 0, nullptr, hitw, nullptr, &sx, &sy, &sz, CLIPMASK0);
return (FindDistance2D(sx - p->pos.x, sy - p->pos.y));

View file

@ -2900,7 +2900,7 @@ void processinput_d(int snum)
s->xvel = clamp(ksqrt((p->pos.x - p->bobposx) * (p->pos.x - p->bobposx) + (p->pos.y - p->bobposy) * (p->pos.y - p->bobposy)), 0, 512);
if (p->on_ground) p->bobcounter += p->GetActor()->s->xvel >> 1;
p->backuppos(ud.clipping == 0 && (p->cursector()->floorpicnum == MIRROR || !validSectorIndex(p->cursectnum)));
p->backuppos(ud.clipping == 0 && (p->cursector()->floorpicnum == MIRROR || !p->insector()));
// Shrinking code

View file

@ -3597,7 +3597,7 @@ void processinput_r(int snum)
s->xvel = clamp(ksqrt((p->pos.x - p->bobposx) * (p->pos.x - p->bobposx) + (p->pos.y - p->bobposy) * (p->pos.y - p->bobposy)), 0, 512);
if (p->on_ground) p->bobcounter += p->GetActor()->s->xvel >> 1;
p->backuppos(ud.clipping == 0 && (p->cursector()->floorpicnum == MIRROR || !validSectorIndex(p->cursectnum < 0)));
p->backuppos(ud.clipping == 0 && (p->cursector()->floorpicnum == MIRROR || !p->insector()));
// Shrinking code

View file

@ -259,7 +259,7 @@ void displayrooms(int snum, double smoothratio)
p = &ps[snum];
pm_smoothratio = (int)smoothratio;
if (automapMode == am_full || p->cursectnum == -1)
if (automapMode == am_full || !p->insector())
return;
// Do not light up the fog in RRRA's E2L1. Ideally this should apply to all foggy levels but all others use lookup table hacks for their fog.

View file

@ -1761,11 +1761,6 @@ void checksectors_d(int snum)
neartagsprite->s->yvel = 1;
camsprite = neartagsprite;
j = p->cursectnum;
p->cursectnum = spr->sectnum;
p->cursectnum = j;
// parallaxtype = 2;
p->newOwner = acti;
return;

View file

@ -488,7 +488,7 @@ int S_PlaySound3D(int sndnum, DDukeActor* actor, const vec3_t* pos, int channel,
bool explosion = ((userflags & (SF_GLOBAL | SF_DTAG)) == (SF_GLOBAL | SF_DTAG)) || ((sndnum == PIPEBOMB_EXPLODE || sndnum == LASERTRIP_EXPLODE || sndnum == RPG_EXPLODE));
bool underwater = ps[screenpeek].cursectnum > -1 && ps[screenpeek].cursector()->lotag == ST_2_UNDERWATER;
bool underwater = ps[screenpeek].insector() && ps[screenpeek].cursector()->lotag == ST_2_UNDERWATER;
if (explosion)
{
if (underwater)

View file

@ -318,11 +318,12 @@ struct player_struct
sectortype* cursector() const
{
#ifdef _DEBUG // this is an aid for detecting invalid sector access during development as it will cause the game to crash when sector -1 is being accessed.
return cursectnum < 0 ? nullptr : &::sector[cursectnum];
#else
return &::sector[cursectnum];
#endif
}
void setCursector(sectortype* sect)
{
cursectnum = ::sector.IndexOf(sect);
}
bool insector() const