From 52d9451cbc55bacd26cf75c046035a09e9458777 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 24 Nov 2021 23:07:02 +0100 Subject: [PATCH] - SOP::op_main_sector --- source/games/sw/src/game.h | 2 +- source/games/sw/src/morph.cpp | 14 +++++++------- source/games/sw/src/player.cpp | 6 +++--- source/games/sw/src/sector.cpp | 1 + source/games/sw/src/track.cpp | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 33156722f..28d30d3ee 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1652,6 +1652,7 @@ struct SECTOR_OBJECTstruct sectortype* sectp[MAX_SO_SECTOR], *scratch, // Just a filler to account for shitty loop tests. + *op_main_sector, // main sector operational SO moves in - for speed purposes *mid_sector; // middle sector @@ -1680,7 +1681,6 @@ struct SECTOR_OBJECTstruct drive_speed, drive_slide, crush_z, - op_main_sector, // main sector operational SO moves in - for speed purposes flags; int16_t xorig[MAX_SO_POINTS], // save the original x & y location of each wall so it can be diff --git a/source/games/sw/src/morph.cpp b/source/games/sw/src/morph.cpp index c68e9a2a4..d25e8cda8 100644 --- a/source/games/sw/src/morph.cpp +++ b/source/games/sw/src/morph.cpp @@ -307,7 +307,7 @@ MorphTornado(SECTOR_OBJECTp sop) int x,y,sx,sy; // z direction - ASSERT(sop->op_main_sector >= 0); + ASSERT(sop->op_main_sector != nullptr); sop->morph_z += Z(sop->morph_z_speed); // move vector @@ -352,8 +352,8 @@ MorphTornado(SECTOR_OBJECTp sop) dragpoint(sop->morph_wall_point, mx, my); // bound the Z - ceilingz = sector[sop->op_main_sector].ceilingz; - floorz = sector[sop->op_main_sector].floorz; + ceilingz = sop->op_main_sector->ceilingz; + floorz = sop->op_main_sector->floorz; for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++) { @@ -388,7 +388,7 @@ MorphFloor(SECTOR_OBJECTp sop) int x,y; // z direction - ASSERT(sop->op_main_sector >= 0); + ASSERT(sop->op_main_sector != nullptr); sop->morph_z -= Z(sop->morph_z_speed); // move vector @@ -431,7 +431,7 @@ MorphFloor(SECTOR_OBJECTp sop) dragpoint(sop->morph_wall_point, mx, my); // bound the Z - floorz = sector[sop->op_main_sector].floorz; + floorz = sop->op_main_sector->floorz; #define MORPH_FLOOR_ZRANGE Z(300) @@ -516,7 +516,7 @@ SpikeFloor(SECTOR_OBJECTp sop) int x,y; // z direction - ASSERT(sop->op_main_sector >= 0); + ASSERT(sop->op_main_sector != nullptr); sop->morph_z -= Z(sop->morph_z_speed); // move vector @@ -532,7 +532,7 @@ SpikeFloor(SECTOR_OBJECTp sop) my = y; // bound the Z - floorz = sector[sop->op_main_sector].floorz; + floorz = sop->op_main_sector->floorz; #define MORPH_FLOOR_ZRANGE Z(300) diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 21822ef30..3baa21996 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -2647,7 +2647,7 @@ void DoPlayerMoveVehicle(PLAYERp pp) save_sectnum = pp->cursectnum; OperateSectorObject(pp->sop, pp->angle.ang.asbuild(), MAXSO, MAXSO); - pp->cursectnum = pp->sop->op_main_sector; // for speed + pp->setcursector(pp->sop->op_main_sector); // for speed floor_dist = labs(z - pp->sop->floor_loz); @@ -4917,7 +4917,7 @@ void DoPlayerBeginOperateTurret(PLAYERp pp) void FindMainSector(SECTOR_OBJECTp sop) { // find the main sector - only do this once for each sector object - if (sop->op_main_sector < 0) + if (sop->op_main_sector == nullptr) { int sx = sop->xmid; int sy = sop->ymid; @@ -4925,7 +4925,7 @@ void FindMainSector(SECTOR_OBJECTp sop) PlaceSectorObject(sop, MAXSO, MAXSO); // set it to something valid - sop->op_main_sector = 0; + sop->op_main_sector = §or[0]; updatesectorz(sx, sy, sop->zmid, &sop->op_main_sector); diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index a1b831536..ea6889f7c 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -384,6 +384,7 @@ void SectorSetup(void) SectorObject[ndx].controller = nullptr; SectorObject[ndx].sp_child = nullptr; SectorObject[ndx].mid_sector = nullptr; + SectorObject[ndx].op_main_sector = nullptr; SectorObject[ndx].xmid = INT32_MAX; } diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index 0f2c10983..d0b0d83fc 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -1033,6 +1033,7 @@ void SetupSectorObject(sectortype* sectp, short tag) memset(sop->sectp, 0, sizeof(sop->sectp)); memset(sop->so_actors, 0, sizeof(sop->so_actors)); + sop->scratch = nullptr; // this is a guard field for sectp, because several loops do not test the end properly. sop->match_event_actor = nullptr; sop->crush_z = 0; sop->drive_angspeed = 0; @@ -1058,7 +1059,7 @@ void SetupSectorObject(sectortype* sectp, short tag) sop->floor_hiz = 9999999; sop->player_xoff = sop->player_yoff = 0; sop->ang_tgt = sop->ang = sop->ang_moving = 0; - sop->op_main_sector = -1; + sop->op_main_sector = nullptr; sop->ram_damage = 0; sop->max_damage = -9999; @@ -2816,7 +2817,6 @@ void TornadoSpin(SECTOR_OBJECTp sop) void DoTornadoObject(SECTOR_OBJECTp sop) { int xvect,yvect; - int cursect; // this made them move together more or less - cool! //static short ang = 1024; int floor_dist; @@ -2827,8 +2827,8 @@ void DoTornadoObject(SECTOR_OBJECTp sop) xvect = sop->vel * bcos(*ang); yvect = sop->vel * bcos(*ang); - cursect = sop->op_main_sector; // for sop->vel - floor_dist = (labs(sector[cursect].ceilingz - sector[cursect].floorz)) >> 2; + auto cursect = sop->op_main_sector; // for sop->vel + floor_dist = (abs(cursect->ceilingz - cursect->floorz)) >> 2; pos.x = sop->xmid; pos.y = sop->ymid; pos.z = floor_dist;