From 2e1ff313b0f21099a4e1eb2e9750d33a93604581 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 7 Nov 2021 18:46:28 +0100 Subject: [PATCH] =?UTF-8?q?-=20Duke:=20only=20use=20the=20main=20clipmove?= =?UTF-8?q?=20function=20and=20match=20clipmove=5Fex=E2=80=99s=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/build/include/clip.h | 2 +- source/games/duke/src/actors.cpp | 2 +- source/games/duke/src/actors_d.cpp | 25 ++++++++++--------------- source/games/duke/src/actors_r.cpp | 25 ++++++++++--------------- source/games/duke/src/dukeactor.h | 6 ++---- source/games/duke/src/player.cpp | 2 +- source/games/duke/src/player_d.cpp | 4 +--- source/games/duke/src/player_r.cpp | 4 +--- 8 files changed, 27 insertions(+), 43 deletions(-) diff --git a/source/build/include/clip.h b/source/build/include/clip.h index 2448b4157..6ff33583a 100644 --- a/source/build/include/clip.h +++ b/source/build/include/clip.h @@ -35,7 +35,7 @@ int32_t clipmove(vec3_t *const pos, int *const sectnum, int32_t xvect, int32_t y int32_t const flordist, uint32_t const cliptype) ATTRIBUTE((nonnull(1, 2))); [[deprecated]] -int32_t clipmove(vec3_t *const pos, int16_t *const sectnum, int32_t xvect, int32_t yvect, int32_t const walldist, int32_t const ceildist, +inline int32_t clipmove(vec3_t *const pos, int16_t *const sectnum, int32_t xvect, int32_t yvect, int32_t const walldist, int32_t const ceildist, int32_t const flordist, uint32_t const cliptype) { int sect32 = *sectnum; diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 6608545e0..1028896b3 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -1506,7 +1506,7 @@ bool queball(DDukeActor *actor, int pocket, int queball, int stripeball) Collision coll; static_assert(sizeof(s->sectnum) != sizeof(int)); // this will error out when sectnum gets expanded. int sect = s->sectnum; - int j = clipmove_ex(&s->x, &s->y, &s->z, §, + int j = clipmove_ex(&s->pos, §, (MulScale(s->xvel, bcos(s->ang), 14) * TICSPERFRAME) << 11, (MulScale(s->xvel, bsin(s->ang), 14) * TICSPERFRAME) << 11, 24L, (4 << 8), (4 << 8), CLIPMASK1, coll); diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 3c9360241..08fd5d928 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -540,7 +540,6 @@ SKIPWALLCHECK: int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision &result) { - int daz, h, oldx, oldy; int clipdist; int dasectnum; @@ -560,17 +559,13 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un dasectnum = spri->sectnum; auto dasectp = spri->sector(); - daz = spri->z; - h = ((tileHeight(spri->picnum) * spri->yrepeat) << 1); - daz -= h; + vec3_t pos = spri->pos; + pos.z -= ((tileHeight(spri->picnum) * spri->yrepeat) << 1); if (bg) { - oldx = spri->x; - oldy = spri->y; - if (spri->xrepeat > 60) - clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024L, (4 << 8), (4 << 8), cliptype, result); + clipmove_ex(&pos, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024, (4 << 8), (4 << 8), cliptype, result); else { if (spri->picnum == LIZMAN) @@ -580,7 +575,7 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un else clipdist = 192; - clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), clipdist, (4 << 8), (4 << 8), cliptype, result); + clipmove_ex(&pos, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), clipdist, (4 << 8), (4 << 8), cliptype, result); } // conditional code from hell... @@ -592,13 +587,11 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un )) ) { - spri->x = oldx; - spri->y = oldy; if (dasectp->lotag == ST_1_ABOVE_WATER && spri->picnum == LIZMAN) spri->ang = (krand()&2047); else if ((actor->temp_data[0]&3) == 1 && spri->picnum != COMMANDER) spri->ang = (krand()&2047); - setsprite(actor,oldx,oldy,spri->z); + setsprite(actor,spri->pos); if (dasectnum < 0) dasectnum = 0; return result.setSector(dasectnum); } @@ -607,15 +600,17 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un else { if (spri->statnum == STAT_PROJECTILE) - clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8L, (4 << 8), (4 << 8), cliptype, result); + clipmove_ex(&pos, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8, (4 << 8), (4 << 8), cliptype, result); else - clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), (int)(spri->clipdist << 2), (4 << 8), (4 << 8), cliptype, result); + clipmove_ex(&pos, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), (int)(spri->clipdist << 2), (4 << 8), (4 << 8), cliptype, result); } + spri->x = pos.x; + spri->y = pos.y; if (dasectnum >= 0) if ((dasectnum != spri->sectnum)) changeactorsect(actor, dasectnum); - daz = spri->z + ((zchange * TICSPERFRAME) >> 3); + int daz = spri->z + ((zchange * TICSPERFRAME) >> 3); if ((daz > actor->ceilingz) && (daz <= actor->floorz)) spri->z = daz; else if (result.type == kHitNone) diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 85ba569bd..3d6b20ca5 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -385,7 +385,6 @@ SKIPWALLCHECK: int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision &result) { - int daz, h, oldx, oldy; int dasectnum; int clipdist; auto spri = actor->s; @@ -404,32 +403,26 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un dasectnum = spri->sectnum; auto dasectp = spri->sector(); - daz = spri->z; - h = ((tileHeight(spri->picnum) * spri->yrepeat) << 1); - daz -= h; + vec3_t pos = spri->pos; + pos.z -= ((tileHeight(spri->picnum) * spri->yrepeat) << 1); if (bg) { - oldx = spri->x; - oldy = spri->y; - if (spri->xrepeat > 60) - clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024L, (4 << 8), (4 << 8), cliptype, result); + clipmove_ex(&pos, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 1024, (4 << 8), (4 << 8), cliptype, result); else { clipdist = 192; - clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), clipdist, (4 << 8), (4 << 8), cliptype, result); + clipmove_ex(&pos, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), clipdist, (4 << 8), (4 << 8), cliptype, result); } if (dasectnum < 0 || (dasectnum >= 0 && actor->actorstayput >= 0 && actor->actorstayput != dasectnum)) { - spri->x = oldx; - spri->y = oldy; if (dasectp->lotag == ST_1_ABOVE_WATER) spri->ang = (krand() & 2047); else if ((actor->temp_data[0] & 3) == 1) spri->ang = (krand() & 2047); - setsprite(actor, oldx, oldy, spri->z); + setsprite(actor, spri->pos); if (dasectnum < 0) dasectnum = 0; return result.setSector(dasectnum); } @@ -438,15 +431,17 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un else { if (spri->statnum == STAT_PROJECTILE) - clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8L, (4 << 8), (4 << 8), cliptype, result); + clipmove_ex(&pos, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8, (4 << 8), (4 << 8), cliptype, result); else - clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 128, (4 << 8), (4 << 8), cliptype, result); + clipmove_ex(&pos, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 128, (4 << 8), (4 << 8), cliptype, result); } + spri->x = pos.x; + spri->y = pos.y; if (dasectnum >= 0) if ((dasectnum != spri->sectnum)) changeactorsect(actor, dasectnum); - daz = spri->z + ((zchange * TICSPERFRAME) >> 3); + int daz = spri->z + ((zchange * TICSPERFRAME) >> 3); if ((daz > actor->ceilingz) && (daz <= actor->floorz)) spri->z = daz; else if (result.type == kHitNone) diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index e338a5f5c..7eef940b7 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -179,11 +179,9 @@ inline int movesprite_ex(DDukeActor* actor, int xchange, int ychange, int zchang return f(actor, xchange, ychange, zchange, cliptype, result); } -inline int clipmove_ex(int* x, int* y, int* z, int* sect, int xv, int yv, int wal, int ceil, int flor, int ct, Collision& result) +inline int clipmove_ex(vec3_t* pos, int* sect, int xv, int yv, int wal, int ceil, int flor, int ct, Collision& result) { - short sect16 = *sect; - int res = clipmove(x, y, z, §16, xv, yv, wal, ceil, flor, ct); - *sect = sect16; + int res = clipmove(pos, sect, xv, yv, wal, ceil, flor, ct); return result.setFromEngine(res); } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index cc24a655e..67294bc0f 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -619,7 +619,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz) } Collision coll; - clipmove_ex(&p->pos.x, &p->pos.y, &p->pos.z, &p->cursectnum, 0, 0, 164, (4 << 8), (4 << 8), CLIPMASK0, coll); + clipmove_ex(&p->pos, &p->cursectnum, 0, 0, 164, (4 << 8), (4 << 8), CLIPMASK0, coll); } backupplayer(p); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index c33c4fe36..ecd62ed89 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -3019,9 +3019,7 @@ HORIZONLY: changeactorsect(pact, p->cursectnum); } else - clipmove_ex(&p->pos.x, &p->pos.y, - &p->pos.z, &p->cursectnum, - p->posxv, p->posyv, 164L, (4L << 8), ii, CLIPMASK0, clip); + clipmove_ex(&p->pos, &p->cursectnum, p->posxv, p->posyv, 164, (4 << 8), ii, CLIPMASK0, clip); if (p->jetpack_on == 0 && psectlotag != 2 && psectlotag != 1 && shrunk) p->pos.z += 32 << 8; diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index cb827ad1b..2f5fa6755 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3782,9 +3782,7 @@ HORIZONLY: changeactorsect(pact, p->cursectnum); } else - clipmove_ex(&p->pos.x, &p->pos.y, - &p->pos.z, &p->cursectnum, - p->posxv, p->posyv, 164L, (4L << 8), i, CLIPMASK0, clip); + clipmove_ex(&p->pos, &p->cursectnum, p->posxv, p->posyv, 164, (4 << 8), i, CLIPMASK0, clip); if (p->jetpack_on == 0 && psectlotag != 2 && psectlotag != 1 && shrunk) p->pos.z += 32 << 8;