Skip to content

Commit

Permalink
- Duke: use sector pointer in movement code
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Nov 21, 2021
1 parent dc0d934 commit 8f3c1b8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
28 changes: 15 additions & 13 deletions source/games/duke/src/player_d.cpp
Expand Up @@ -1748,7 +1748,7 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, int fz,
//
//---------------------------------------------------------------------------

static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int shrunk, int truefdist, int psectlotag)
static void movement(int snum, ESyncBits actions, sectortype* psect, int fz, int cz, int shrunk, int truefdist, int psectlotag)
{
int j;
auto p = &ps[snum];
Expand Down Expand Up @@ -1796,7 +1796,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int
{

// not jumping or crouching
if ((actions & (SB_JUMP|SB_CROUCH)) == 0 && p->on_ground && (sector[psect].floorstat & 2) && p->pos.z >= (fz - (i << 8) - (16 << 8)))
if ((actions & (SB_JUMP|SB_CROUCH)) == 0 && p->on_ground && (psect->floorstat & 2) && p->pos.z >= (fz - (i << 8) - (16 << 8)))
p->pos.z = fz - (i << 8);
else
{
Expand Down Expand Up @@ -1934,7 +1934,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int
//
//---------------------------------------------------------------------------

static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz)
static void underwater(int snum, ESyncBits actions, int fz, int cz)
{
auto p = &ps[snum];
auto pact = p->GetActor();
Expand Down Expand Up @@ -2747,7 +2747,8 @@ void processinput_d(int snum)
psect = 0;
}

psectlotag = sector[psect].lotag;
auto psectp = &sector[psect];
psectlotag = psectp->lotag;
p->spritebridge = 0;

shrunk = (s->yrepeat < 32);
Expand Down Expand Up @@ -2866,7 +2867,7 @@ void processinput_d(int snum)

if (psectlotag == ST_2_UNDERWATER)
{
underwater(snum, actions, psect, fz, cz);
underwater(snum, actions, fz, cz);
}

else if (p->jetpack_on)
Expand All @@ -2875,7 +2876,7 @@ void processinput_d(int snum)
}
else if (psectlotag != ST_2_UNDERWATER)
{
movement(snum, actions, psect, fz, cz, shrunk, truefdist, psectlotag);
movement(snum, actions, psectp, fz, cz, shrunk, truefdist, psectlotag);
}

p->psectlotag = psectlotag;
Expand Down Expand Up @@ -2954,7 +2955,7 @@ void processinput_d(int snum)
if (clz.type == kHitSprite)
j = clz.actor->s->picnum;
else
j = sector[psect].floorpicnum;
j = psectp->floorpicnum;

switch (j)
{
Expand Down Expand Up @@ -3063,9 +3064,9 @@ void processinput_d(int snum)
if (psectlotag < 3)
{
psect = s->sectnum;
if (ud.clipping == 0 && sector[psect].lotag == 31)
if (ud.clipping == 0 && psectp->lotag == 31)
{
auto secact = ScriptIndexToActor(sector[psect].hitag);
auto secact = ScriptIndexToActor(psectp->hitag);
if (secact && secact->s->xvel && secact->temp_data[0] == 0)
{
quickkill(p);
Expand Down Expand Up @@ -3098,7 +3099,7 @@ void processinput_d(int snum)
return;
}
}
else if (abs(fz - cz) < (32 << 8) && isanunderoperator(sector[psect].lotag))
else if (abs(fz - cz) < (32 << 8) && isanunderoperator(psectp->lotag))
fi.activatebysector(psect, pact);
}

Expand Down Expand Up @@ -3173,11 +3174,12 @@ void processinput_d(int snum)

void processmove_d(int snum, ESyncBits actions, int psect, int fz, int cz, int shrunk, int truefdist)
{
int psectlotag = sector[psect].lotag;
auto psectp = &sector[psect];
int psectlotag = psectp->lotag;
auto p = &ps[snum];
if (psectlotag == 2)
{
underwater(snum, actions, psect, fz, cz);
underwater(snum, actions, fz, cz);
}

else if (p->jetpack_on)
Expand All @@ -3186,7 +3188,7 @@ void processmove_d(int snum, ESyncBits actions, int psect, int fz, int cz, int s
}
else if (psectlotag != 2)
{
movement(snum, actions, psect, fz, cz, shrunk, truefdist, psectlotag);
movement(snum, actions, psectp, fz, cz, shrunk, truefdist, psectlotag);
}
}
END_DUKE_NS
47 changes: 24 additions & 23 deletions source/games/duke/src/player_r.cpp
Expand Up @@ -2049,7 +2049,7 @@ static void onBoat(int snum, ESyncBits &actions)
//
//---------------------------------------------------------------------------

static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int shrunk, int truefdist, int psectlotag)
static void movement(int snum, ESyncBits actions, sectortype* psect, int fz, int cz, int shrunk, int truefdist, int psectlotag)
{
auto p = &ps[snum];
auto pact = p->GetActor();
Expand Down Expand Up @@ -2106,7 +2106,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int

if (p->pos.z < (fz - (i << 8))) //falling
{
if ((actions & (SB_JUMP|SB_CROUCH)) == 0 && p->on_ground && (sector[psect].floorstat & 2) && p->pos.z >= (fz - (i << 8) - (16 << 8)))
if ((actions & (SB_JUMP|SB_CROUCH)) == 0 && p->on_ground && (psect->floorstat & 2) && p->pos.z >= (fz - (i << 8) - (16 << 8)))
p->pos.z = fz - (i << 8);
else
{
Expand Down Expand Up @@ -2278,7 +2278,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int
//
//---------------------------------------------------------------------------

static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz)
static void underwater(int snum, ESyncBits actions, int fz, int cz)
{
auto p = &ps[snum];
auto pact = p->GetActor();
Expand Down Expand Up @@ -2352,7 +2352,7 @@ static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz)
//
//---------------------------------------------------------------------------

void onMotorcycleMove(int snum, int psect, walltype* wal)
void onMotorcycleMove(int snum, walltype* wal)
{
auto p = &ps[snum];
auto pact = p->GetActor();
Expand Down Expand Up @@ -2408,11 +2408,10 @@ void onMotorcycleMove(int snum, int psect, walltype* wal)
//
//---------------------------------------------------------------------------

void onBoatMove(int snum, int psect, walltype* wal)
void onBoatMove(int snum, int psectlotag, walltype* wal)
{
auto p = &ps[snum];
auto pact = p->GetActor();
int psectlotag = sector[psect].lotag;
auto delta = wal->delta();
int angleDelta = abs(p->angle.ang.asbuild() - getangle(delta.x, delta.y));

Expand Down Expand Up @@ -3361,8 +3360,8 @@ void processinput_r(int snum)
}
psect = 0;
}

psectlotag = sector[psect].lotag;
auto psectp = &sector[psect];
psectlotag = psectp->lotag;

if (psectlotag == 867)
{
Expand All @@ -3377,7 +3376,7 @@ void processinput_r(int snum)
else if (psectlotag == 7777 && (currentLevel->gameflags & LEVEL_RR_HULKSPAWN))
lastlevel = 1;

if (psectlotag == 848 && sector[psect].floorpicnum == WATERTILE2)
if (psectlotag == 848 && psectp->floorpicnum == WATERTILE2)
psectlotag = 1;

if (psectlotag == 857)
Expand Down Expand Up @@ -3588,11 +3587,11 @@ void processinput_r(int snum)

if (psectlotag == ST_2_UNDERWATER)
{
underwater(snum, actions, psect, fz, cz);
underwater(snum, actions, fz, cz);
}
else
{
movement(snum, actions, psect, fz, cz, shrunk, truefdist, psectlotag);
movement(snum, actions, psectp, fz, cz, shrunk, truefdist, psectlotag);
}

p->psectlotag = psectlotag;
Expand Down Expand Up @@ -3668,7 +3667,7 @@ void processinput_r(int snum)

if (clz.type == kHitSprite)
j = clz.actor->s->picnum;
else j = sector[psect].floorpicnum;
else j = psectp->floorpicnum;
break;
case 1:
if ((krand() & 1) == 0)
Expand Down Expand Up @@ -3707,13 +3706,13 @@ void processinput_r(int snum)
}
}

if (isRRRA() && sector[psect].floorpicnum == RRTILE7888)
if (isRRRA() && psectp->floorpicnum == RRTILE7888)
{
if (p->OnMotorcycle)
if (p->on_ground)
p->moto_on_oil = 1;
}
else if (isRRRA() && sector[psect].floorpicnum == RRTILE7889)
else if (isRRRA() && psectp->floorpicnum == RRTILE7889)
{
if (p->OnMotorcycle)
{
Expand All @@ -3730,7 +3729,7 @@ void processinput_r(int snum)
}
else

if (sector[psect].floorpicnum == RRTILE3073 || sector[psect].floorpicnum == RRTILE2702)
if (psectp->floorpicnum == RRTILE3073 || psectp->floorpicnum == RRTILE2702)
{
if (p->OnMotorcycle)
{
Expand Down Expand Up @@ -3795,11 +3794,11 @@ void processinput_r(int snum)
auto wal = clip.wall();
if (p->OnMotorcycle)
{
onMotorcycleMove(snum, psect, wal);
onMotorcycleMove(snum, wal);
}
else if (p->OnBoat)
{
onBoatMove(snum, psect, wal);
onBoatMove(snum, psectlotag, wal);
}
else
{
Expand Down Expand Up @@ -3888,9 +3887,10 @@ void processinput_r(int snum)
if (psectlotag < 3)
{
psect = s->sectnum;
if (ud.clipping == 0 && sector[psect].lotag == ST_31_TWO_WAY_TRAIN)
psectp = &sector[psect];
if (ud.clipping == 0 && psectp->lotag == ST_31_TWO_WAY_TRAIN)
{
auto act = ScriptIndexToActor(sector[psect].hitag);
auto act = ScriptIndexToActor(psectp->hitag);
if (act && act->s->xvel && act->temp_data[0] == 0)
{
quickkill(p);
Expand Down Expand Up @@ -3930,7 +3930,7 @@ void processinput_r(int snum)
return;
}
}
else if (abs(fz - cz) < (32 << 8) && isanunderoperator(sector[psect].lotag))
else if (abs(fz - cz) < (32 << 8) && isanunderoperator(psectp->lotag))
fi.activatebysector(psect, pact);
}

Expand Down Expand Up @@ -4018,14 +4018,15 @@ void processinput_r(int snum)

void processmove_r(int snum, ESyncBits actions, int psect, int fz, int cz, int shrunk, int truefdist)
{
int psectlotag = sector[psect].lotag;
auto psectp = &sector[psect];
int psectlotag = psectp->lotag;
if (psectlotag == ST_2_UNDERWATER)
{
underwater(snum, actions, psect, fz, cz);
underwater(snum, actions, fz, cz);
}
else
{
movement(snum, actions, psect, fz, cz, shrunk, truefdist, psectlotag);
movement(snum, actions, psectp, fz, cz, shrunk, truefdist, psectlotag);
}
}

Expand Down

0 comments on commit 8f3c1b8

Please sign in to comment.