From 312b1fd39f8b9600a1724d3b842fb647c4f48ae1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 21 Nov 2021 08:45:07 +0100 Subject: [PATCH] - cursectnum first half --- source/build/include/build.h | 5 ++++ source/games/duke/src/_polymost.cpp | 2 +- source/games/duke/src/actors.cpp | 46 ++++++++++++++--------------- source/games/duke/src/actors_d.cpp | 18 +++++------ source/games/duke/src/actors_r.cpp | 18 +++++------ source/games/duke/src/dukeactor.h | 11 +++++++ source/games/duke/src/gameexec.cpp | 5 ---- source/games/duke/src/input.cpp | 2 +- source/games/duke/src/player.cpp | 4 +-- source/games/duke/src/player_d.cpp | 2 +- source/games/duke/src/player_r.cpp | 2 +- source/games/duke/src/render.cpp | 2 +- source/games/duke/src/sectors_d.cpp | 5 ---- source/games/duke/src/sounds.cpp | 2 +- source/games/duke/src/types.h | 9 +++--- 15 files changed, 70 insertions(+), 63 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 4bd2f4e10..fc7855227 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -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" diff --git a/source/games/duke/src/_polymost.cpp b/source/games/duke/src/_polymost.cpp index 5c62811b9..00684ab10 100644 --- a/source/games/duke/src/_polymost.cpp +++ b/source/games/duke/src/_polymost.cpp @@ -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; } diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index af4893727..7ad3462bf 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -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)) { diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 1fecd9d41..bb69b7398 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -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)) { diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 1a7478625..171c49530 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -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) { diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index 9a5fb3d28..e4b50c648 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -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? §or[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) diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index da49b00a7..b5c325475 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -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); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 3de4e16b6..9073ba610 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -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)); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index e651b8908..721dc8cab 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -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)); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 723f350d9..d31835419 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -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 diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index b8e7eebff..f5ce3ac40 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -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 diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 57c11b523..3868613d9 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -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. diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index c64562586..5ae29d98e 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -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; diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index 68350e582..e9ebffd75 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -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) diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 79679126c..1e9873386 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -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