- use sector pointers in actors_lava.cpp

This commit is contained in:
Christoph Oelckers 2021-11-18 19:44:26 +01:00
parent 9b6d6eb7f9
commit 3970c9a757
4 changed files with 30 additions and 36 deletions

View file

@ -5116,7 +5116,7 @@ int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, int* dax, int* day
d = abs(hx - ts->x) + abs(hy - ts->y); d = abs(hx - ts->x) + abs(hy - ts->y);
da = abs(hx - s->x) + abs(hy - s->y); da = abs(hx - s->x) + abs(hy - s->y);
if (d < da) if (d < da && hitsect)
if (cansee(hx, hy, hz, sectnum(hitsect), s->x, s->y, s->z - (16 << 8), s->sectnum)) if (cansee(hx, hy, hz, sectnum(hitsect), s->x, s->y, s->z - (16 << 8), s->sectnum))
{ {
*dax = hx; *dax = hx;

View file

@ -29,6 +29,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
#include "global.h" #include "global.h"
#include "names_r.h" #include "names_r.h"
#include "serializer.h" #include "serializer.h"
#include "savegamehelp.h"
#include "dukeactor.h" #include "dukeactor.h"
BEGIN_DUKE_NS BEGIN_DUKE_NS
@ -38,7 +39,7 @@ static int jaildoorcnt;
static int minecartcnt; static int minecartcnt;
static int lightnincnt; static int lightnincnt;
static int torchsector[64]; static sectortype* torchsector[64];
static short torchsectorshade[64]; static short torchsectorshade[64];
static short torchtype[64]; static short torchtype[64];
@ -49,18 +50,18 @@ static short jaildoorsecthtag[32];
static int jaildoordist[32]; static int jaildoordist[32];
static short jaildoordir[32]; static short jaildoordir[32];
static short jaildooropen[32]; static short jaildooropen[32];
static int jaildoorsect[32]; static sectortype* jaildoorsect[32];
static short minecartdir[16]; static short minecartdir[16];
static int minecartspeed[16]; static int minecartspeed[16];
static int minecartchildsect[16]; static sectortype* minecartchildsect[16];
static short minecartsound[16]; static short minecartsound[16];
static int minecartdist[16]; static int minecartdist[16];
static int minecartdrag[16]; static int minecartdrag[16];
static short minecartopen[16]; static short minecartopen[16];
static int minecartsect[16]; static sectortype* minecartsect[16];
static int lightninsector[64]; static sectortype* lightninsector[64];
static short lightninsectorshade[64]; static short lightninsectorshade[64];
static uint8_t brightness; static uint8_t brightness;
@ -127,7 +128,7 @@ void addtorch(spritetype* s)
if (torchcnt >= 64) if (torchcnt >= 64)
I_Error("Too many torch effects"); I_Error("Too many torch effects");
torchsector[torchcnt] = s->sectnum; torchsector[torchcnt] = s->sector();
torchsectorshade[torchcnt] = s->sector()->floorshade; torchsectorshade[torchcnt] = s->sector()->floorshade;
torchtype[torchcnt] = s->lotag; torchtype[torchcnt] = s->lotag;
torchcnt++; torchcnt++;
@ -138,12 +139,12 @@ void addlightning(spritetype* s)
if (lightnincnt >= 64) if (lightnincnt >= 64)
I_Error("Too many lightnin effects"); I_Error("Too many lightnin effects");
lightninsector[lightnincnt] = s->sectnum; lightninsector[lightnincnt] = s->sector();
lightninsectorshade[lightnincnt] = s->sector()->floorshade; lightninsectorshade[lightnincnt] = s->sector()->floorshade;
lightnincnt++; lightnincnt++;
} }
void addjaildoor(int p1, int p2, int iht, int jlt, int p3, int j) void addjaildoor(int p1, int p2, int iht, int jlt, int p3, sectortype* j)
{ {
if (jaildoorcnt >= 32) if (jaildoorcnt >= 32)
I_Error("Too many jaildoor sectors"); I_Error("Too many jaildoor sectors");
@ -165,14 +166,14 @@ void addjaildoor(int p1, int p2, int iht, int jlt, int p3, int j)
jaildoorcnt++; jaildoorcnt++;
} }
void addminecart(int p1, int p2, int i, int iht, int p3, int childsectnum) void addminecart(int p1, int p2, sectortype* i, int iht, int p3, sectortype* childsectnum)
{ {
if (minecartcnt >= 16) if (minecartcnt >= 16)
I_Error("Too many minecart sectors"); I_Error("Too many minecart sectors");
minecartdist[minecartcnt] = p1; minecartdist[minecartcnt] = p1;
minecartspeed[minecartcnt] = p2; minecartspeed[minecartcnt] = p2;
minecartsect[minecartcnt] = i; minecartsect[minecartcnt] = i;
minecartdir[minecartcnt] = sector[i].hitag; minecartdir[minecartcnt] = i->hitag;
minecartdrag[minecartcnt] = p1; minecartdrag[minecartcnt] = p1;
minecartopen[minecartcnt] = 1; minecartopen[minecartcnt] = 1;
minecartsound[minecartcnt] = p3; minecartsound[minecartcnt] = p3;
@ -193,7 +194,7 @@ void dotorch(void)
ds = krand()&8; ds = krand()&8;
for (int i = 0; i < torchcnt; i++) for (int i = 0; i < torchcnt; i++)
{ {
auto sect = &sector[torchsector[i]]; auto sect = torchsector[i];
shade = torchsectorshade[i] - ds; shade = torchsectorshade[i] - ds;
switch (torchtype[i]) switch (torchtype[i])
{ {
@ -249,7 +250,7 @@ void dojaildoor(void)
for (int i = 0; i < jaildoorcnt; i++) for (int i = 0; i < jaildoorcnt; i++)
{ {
int speed; int speed;
auto sectp = &sector[jaildoorsect[i]]; auto sectp = jaildoorsect[i];
if (numplayers > 2) if (numplayers > 2)
speed = jaildoorspeed[i]; speed = jaildoorspeed[i];
else else
@ -371,7 +372,6 @@ void dojaildoor(void)
void moveminecart(void) void moveminecart(void)
{ {
int i; int i;
int csect;
int speed; int speed;
int y; int y;
int x; int x;
@ -383,7 +383,7 @@ void moveminecart(void)
int min_x; int min_x;
for (i = 0; i < minecartcnt; i++) for (i = 0; i < minecartcnt; i++)
{ {
auto sectp = &sector[minecartsect[i]]; auto sectp = minecartsect[i];
speed = minecartspeed[i]; speed = minecartspeed[i];
if (speed < 2) if (speed < 2)
speed = 2; speed = 2;
@ -496,7 +496,7 @@ void moveminecart(void)
} }
} }
} }
csect = minecartchildsect[i]; auto csect = minecartchildsect[i];
max_x = max_y = -0x20000; max_x = max_y = -0x20000;
min_x = min_y = 0x20000; min_x = min_y = 0x20000;
for (auto& wal : wallsofsector(csect)) for (auto& wal : wallsofsector(csect))
@ -606,7 +606,7 @@ void thunder(void)
winderflash = 0; winderflash = 0;
for (i = 0; i < lightnincnt; i++) for (i = 0; i < lightnincnt; i++)
{ {
auto sectp = &sector[lightninsector[i]]; auto sectp = lightninsector[i];
sectp->floorshade = (int8_t)lightninsectorshade[i]; sectp->floorshade = (int8_t)lightninsectorshade[i];
sectp->ceilingshade = (int8_t)lightninsectorshade[i]; sectp->ceilingshade = (int8_t)lightninsectorshade[i];
for (auto& wal : wallsofsector(sectp)) for (auto& wal : wallsofsector(sectp))
@ -646,7 +646,7 @@ void thunder(void)
shade = torchsectorshade[i] + r2; shade = torchsectorshade[i] + r2;
for (i = 0; i < lightnincnt; i++) for (i = 0; i < lightnincnt; i++)
{ {
auto sectp = &sector[lightninsector[i]]; auto sectp = lightninsector[i];
sectp->floorshade = lightninsectorshade[i] - shade; sectp->floorshade = lightninsectorshade[i] - shade;
sectp->ceilingshade = lightninsectorshade[i] - shade; sectp->ceilingshade = lightninsectorshade[i] - shade;
for (auto& wal : wallsofsector(sectp)) for (auto& wal : wallsofsector(sectp))

View file

@ -15,8 +15,8 @@ BEGIN_DUKE_NS
// This list is not sorted in any way. // This list is not sorted in any way.
void lava_cleararrays(); void lava_cleararrays();
void addjaildoor(int p1, int p2, int iht, int jlt, int p3, int h); void addjaildoor(int p1, int p2, int iht, int jlt, int p3, sectortype* h);
void addminecart(int p1, int p2, int i, int iht, int p3, int childsectnum); void addminecart(int p1, int p2, sectortype* i, int iht, int p3, sectortype* childsectnum);
void addtorch(spritetype* i); void addtorch(spritetype* i);
void addlightning(spritetype* i); void addlightning(spritetype* i);

View file

@ -35,12 +35,6 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
BEGIN_DUKE_NS BEGIN_DUKE_NS
void addjaildoor(int p1, int p2, int iht, int jlt, int p3, int h);
void addminecart(int p1, int p2, int i, int iht, int p3, int childsectnum);
void addtorch(int i);
void addlightning(int i);
static inline void tloadtile(int tilenum, int palnum = 0) static inline void tloadtile(int tilenum, int palnum = 0)
{ {
markTileForPrecache(tilenum, palnum); markTileForPrecache(tilenum, palnum);
@ -454,9 +448,9 @@ void prelevel_r(int g)
} }
} }
for (i = 0; i < numsectors; i++) for (auto&sect : sectors())
{ {
auto sectp = &sector[i]; auto sectp = &sect;
if (sectp->ceilingpicnum == RRTILE2577) if (sectp->ceilingpicnum == RRTILE2577)
thunderon = 1; thunderon = 1;
@ -464,7 +458,7 @@ void prelevel_r(int g)
{ {
case 41: case 41:
{ {
DukeSectIterator it(i); DukeSectIterator it(sectp);
dist = 0; dist = 0;
while (auto act = it.Next()) while (auto act = it.Next())
{ {
@ -481,13 +475,13 @@ void prelevel_r(int g)
deletesprite(act); deletesprite(act);
} }
} }
for (j = 0; j < numsectors; j++) for(auto& osect : sectors())
{ {
if (sectp->hitag == sector[j].hitag && j != i) if (sectp->hitag == osect.hitag && &osect != sectp)
{ {
// & 32767 to avoid some ordering issues here. // & 32767 to avoid some ordering issues here.
// Other code assumes that the lotag is always a sector effector type and can mask the high bit in. // Other code assumes that the lotag is always a sector effector type and can mask the high bit in.
addjaildoor(dist, speed, sectp->hitag, sector[j].lotag & 32767, sound, j); addjaildoor(dist, speed, sectp->hitag, osect.lotag & 32767, sound, &osect);
} }
} }
break; break;
@ -495,10 +489,10 @@ void prelevel_r(int g)
case 42: case 42:
{ {
int ii; int ii;
int childsectnum = -1; sectortype* childsectnum = nullptr;
dist = 0; dist = 0;
speed = 0; speed = 0;
DukeSectIterator it(i); DukeSectIterator it(sectp);
while (auto act = it.Next()) while (auto act = it.Next())
{ {
auto sj = act->s; auto sj = act->s;
@ -512,7 +506,7 @@ void prelevel_r(int g)
if (spr->picnum == RRTILE66) if (spr->picnum == RRTILE66)
if (spr->lotag == sj->sectnum) if (spr->lotag == sj->sectnum)
{ {
childsectnum = spr->sectnum; childsectnum = spr->sector();
deletesprite(ii); deletesprite(ii);
} }
} }
@ -524,7 +518,7 @@ void prelevel_r(int g)
deletesprite(act); deletesprite(act);
} }
} }
addminecart(dist, speed, i, sectp->hitag, sound, childsectnum); addminecart(dist, speed, sectp, sectp->hitag, sound, childsectnum);
break; break;
} }
} }