mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 03:00:46 +00:00
Add support for returning the closest point in the sector to getsectordist()
git-svn-id: https://svn.eduke32.com/eduke32@7609 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
8d85e8d934
commit
60ea578a8c
2 changed files with 25 additions and 10 deletions
|
@ -1176,8 +1176,8 @@ int32_t try_facespr_intersect(uspriteptr_t const spr, const vec3_t *refpos,
|
||||||
|
|
||||||
int findwallbetweensectors(int sect1, int sect2);
|
int findwallbetweensectors(int sect1, int sect2);
|
||||||
static FORCE_INLINE bool sectoradjacent(int sect1, int sect2) { return findwallbetweensectors(sect1, sect2) != -1; }
|
static FORCE_INLINE bool sectoradjacent(int sect1, int sect2) { return findwallbetweensectors(sect1, sect2) != -1; }
|
||||||
int32_t getwalldist(vec2_t const &p, int const wallnum, vec2_t * const output = nullptr);
|
int32_t getwalldist(vec2_t const &in, int const wallnum, vec2_t * const out = nullptr);
|
||||||
int32_t getsectordist(vec2_t const &p, int const sectnum);
|
int32_t getsectordist(vec2_t const &in, int const sectnum, vec2_t * const out = nullptr);
|
||||||
extern const int16_t *chsecptr_onextwall;
|
extern const int16_t *chsecptr_onextwall;
|
||||||
int32_t checksectorpointer(int16_t i, int16_t sectnum);
|
int32_t checksectorpointer(int16_t i, int16_t sectnum);
|
||||||
|
|
||||||
|
|
|
@ -10964,18 +10964,23 @@ static inline bool inside_z_p(int32_t const x, int32_t const y, int32_t const z,
|
||||||
return (z >= cz && z <= fz && inside_p(x, y, sectnum));
|
return (z >= cz && z <= fz && inside_p(x, y, sectnum));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getwalldist(vec2_t const &pos, int const wallnum, vec2_t * const output)
|
int32_t getwalldist(vec2_t const &in, int const wallnum, vec2_t * const out /*= nullptr*/)
|
||||||
{
|
{
|
||||||
vec2_t closest;
|
vec2_t closest;
|
||||||
getclosestpointonwall_internal(pos, wallnum, &closest);
|
getclosestpointonwall_internal(in, wallnum, &closest);
|
||||||
if (output) *output = closest;
|
if (out)
|
||||||
return klabs(closest.x - pos.x) + klabs(closest.y - pos.y);
|
*out = closest;
|
||||||
|
return klabs(closest.x - in.x) + klabs(closest.y - in.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getsectordist(vec2_t const &pos, int const sectnum)
|
int32_t getsectordist(vec2_t const &in, int const sectnum, vec2_t * const out /*= nullptr*/)
|
||||||
{
|
{
|
||||||
if (inside_p(pos.x, pos.y, sectnum))
|
if (inside_p(in.x, in.y, sectnum))
|
||||||
|
{
|
||||||
|
if (out)
|
||||||
|
*out = in;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t distance = INT32_MAX;
|
int32_t distance = INT32_MAX;
|
||||||
|
|
||||||
|
@ -10983,13 +10988,23 @@ int32_t getsectordist(vec2_t const &pos, int const sectnum)
|
||||||
int const startwall = sec->wallptr;
|
int const startwall = sec->wallptr;
|
||||||
int const endwall = sec->wallptr + sec->wallnum;
|
int const endwall = sec->wallptr + sec->wallnum;
|
||||||
auto uwal = (uwallptr_t)&wall[startwall];
|
auto uwal = (uwallptr_t)&wall[startwall];
|
||||||
|
vec2_t closest = {};
|
||||||
|
|
||||||
for (int j = startwall; j < endwall; j++, uwal++)
|
for (int j = startwall; j < endwall; j++, uwal++)
|
||||||
{
|
{
|
||||||
int32_t const walldist = getwalldist(pos, j);
|
vec2_t p;
|
||||||
distance = min(walldist, distance);
|
int32_t const walldist = getwalldist(in, j, &p);
|
||||||
|
|
||||||
|
if (walldist < distance)
|
||||||
|
{
|
||||||
|
distance = walldist;
|
||||||
|
closest = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (out)
|
||||||
|
*out = closest;
|
||||||
|
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue