diff --git a/source/duke3d/src/actors.cpp b/source/duke3d/src/actors.cpp index 4c6f4265b..3c30b52eb 100644 --- a/source/duke3d/src/actors.cpp +++ b/source/duke3d/src/actors.cpp @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "sounds.h" #include "v_text.h" #include "printf.h" +#include "sector.h" BEGIN_EDUKE_NS diff --git a/source/duke3d/src/duke3d.h b/source/duke3d/src/duke3d.h index 150464970..0e7423212 100644 --- a/source/duke3d/src/duke3d.h +++ b/source/duke3d/src/duke3d.h @@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gamecontrol.h" #include "menu.h" #include "memarena.h" +#include "sector.h" diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index c199fb84a..35366fe5b 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -3976,7 +3976,7 @@ badindex: VM_ASSERT((unsigned)in.x < MAXSPRITES && (unsigned)in.y < MAXSPRITES, "invalid sprite %d, %d\n", in.x, in.y); - Gv_SetVar(out, (VM_DECODE_INST(tw) == CON_LDIST ? ldist : dist)(&sprite[in.x], &sprite[in.y])); + Gv_SetVar(out, VM_DECODE_INST(tw) == CON_LDIST ? ldist(&sprite[in.x], &sprite[in.y]) : dist(&sprite[in.x], &sprite[in.y])); dispatch(); } @@ -5233,7 +5233,7 @@ badindex: // int const decodedInst = VM_DECODE_INST(tw); int const actorsOnly = (decodedInst == CON_FINDNEARACTOR || decodedInst == CON_FINDNEARACTOR3D); - auto const dist_funcptr = (decodedInst == CON_FINDNEARACTOR || decodedInst == CON_FINDNEARSPRITE) ? &ldist : &dist; + auto const dist_funcptr = (decodedInst == CON_FINDNEARACTOR || decodedInst == CON_FINDNEARSPRITE); int const findTile = *insptr++; int maxDist = Gv_GetVar(*insptr++); @@ -5250,7 +5250,7 @@ badindex: { if (sprite[spriteNum].picnum == findTile && spriteNum != vm.spriteNum) { - int const foundDist = dist_funcptr(vm.pSprite, &sprite[spriteNum]); + int const foundDist = dist_funcptr? ldist(vm.pSprite, &sprite[spriteNum]) : dist(vm.pSprite, &sprite[spriteNum]); if (foundDist < maxDist) { diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index d9eaebdfd..ecd4b92a1 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -350,7 +350,7 @@ static int CheckShootSwitchTile(int tileNum) static int32_t safeldist(int32_t spriteNum, const void *pSprite) { - int32_t distance = ldist(&sprite[spriteNum], pSprite); + int32_t distance = ldist(&sprite[spriteNum],(uspritetype*)pSprite); return distance ? distance : 1; } diff --git a/source/duke3d/src/sector.h b/source/duke3d/src/sector.h index 0ccbc6632..6e1975bde 100644 --- a/source/duke3d/src/sector.h +++ b/source/duke3d/src/sector.h @@ -176,6 +176,68 @@ EXTERN_INLINE int32_t G_GetPlayerInSector(int32_t const sect) #endif + +// These are from duke's sector.c +inline int ldist(const spritetype* s1, const spritetype* s2) +{ + int vx, vy; + vx = s1->x - s2->x; + vy = s1->y - s2->y; + return(FindDistance2D(vx, vy) + 1); +} + +inline int ldist(const uspritetype* s1, const spritetype* s2) +{ + int vx, vy; + vx = s1->x - s2->x; + vy = s1->y - s2->y; + return(FindDistance2D(vx, vy) + 1); +} + +inline int ldist(const spritetype* s1, const uspritetype* s2) +{ + int vx, vy; + vx = s1->x - s2->x; + vy = s1->y - s2->y; + return(FindDistance2D(vx, vy) + 1); +} + +inline int ldist(const uspritetype* s1, const uspritetype* s2) +{ + int vx, vy; + vx = s1->x - s2->x; + vy = s1->y - s2->y; + return(FindDistance2D(vx, vy) + 1); +} + + +inline int dist(const spritetype* s1, const spritetype* s2) +{ + int vx, vy, vz; + vx = s1->x - s2->x; + vy = s1->y - s2->y; + vz = s1->z - s2->z; + return(FindDistance3D(vx, vy, vz >> 4)); +} + +inline int dist(const uspritetype* s1, const uspritetype* s2) +{ + int vx, vy, vz; + vx = s1->x - s2->x; + vy = s1->y - s2->y; + vz = s1->z - s2->z; + return(FindDistance3D(vx, vy, vz >> 4)); +} + +inline int dist(const uspritetype* s1, const spritetype* s2) +{ + int vx, vy, vz; + vx = s1->x - s2->x; + vy = s1->y - s2->y; + vz = s1->z - s2->z; + return(FindDistance3D(vx, vy, vz >> 4)); +} + END_EDUKE_NS #endif diff --git a/source/games/duke/src/sector.h b/source/games/duke/src/sector.h index ba7f240c6..6457a1496 100644 --- a/source/games/duke/src/sector.h +++ b/source/games/duke/src/sector.h @@ -190,6 +190,7 @@ inline int checkcursectnums(int se) return G_CheckPlayerInSector(se); } +// These are from duke's sector.c inline int ldist(const spritetype* s1, const spritetype* s2) { int vx, vy;