- floatified part of clipmove that pushes the caller away from obstacles

This commit is contained in:
Christoph Oelckers 2022-10-25 12:40:57 +02:00
parent b72283e9cb
commit 66e6d166d6
3 changed files with 71 additions and 11 deletions

View file

@ -146,17 +146,10 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
{
if (clip.precise && (xvect|yvect))
{
for (int i=clip.clipobjects.Size() - 1; i >= 0; --i)
{
if (!clip.clipobjects[i].obj.exbits && clipinsideboxline(pos->X, pos->Y, clip.clipobjects[i].x1(), clip.clipobjects[i].y1(), clip.clipobjects[i].x2(), clip.clipobjects[i].y2(), walldist))
{
vec2_t const vec = pos->vec2;
keepaway(clip, &pos->X, &pos->Y, i);
if (inside(pos->X * inttoworld, pos->Y * inttoworld, &sector[*sectnum]) != 1)
pos->vec2 = vec;
break;
}
}
DVector2 fpos(pos->X * inttoworld, pos->Y * inttoworld);
PushAway(clip, fpos, &sector[*sectnum]);
pos->X = int(fpos.X * worldtoint);
pos->Y = int(fpos.Y * worldtoint);
}
vec2_t vec = goal;

View file

@ -1671,6 +1671,70 @@ int FindBestSector(const DVector3& pos)
//
//==========================================================================
#if 0
static inline void keepaway(MoveClipper& clip, DVector2& pos, ClipObject& clipo)
{
// later, once we are using floats throughout we should be able to do this
auto start = clipo.line.start, normal = clipo.line.delta().Rotated90CCW().Unit();
while (normal.dot(pos - start) <= 0)
{
pos += normal;
}
}
#else
static inline void keepaway(MoveClipper& clip, DVector2& pos, ClipObject& clipo)
{
// for now this has to be retained...
auto start = clipo.line.start, normal = clipo.line.delta().Rotated90CCW();
const double ox = Sgn(normal.X) * inttoworld, oy = Sgn(normal.Y) * inttoworld;
bool first = (abs(normal.Y) <= abs(normal.X));
do
{
if (normal.dot(pos - start) > 0)
return;
if (!first)
pos.X += ox;
else
pos.Y += oy;
first = !first;
}
while (1);
}
#endif
//==========================================================================
//
//
//
//==========================================================================
void PushAway(MoveClipper &clip, DVector2& pos, sectortype* sect)
{
for (int i = clip.clipobjects.Size() - 1; i >= 0; --i)
{
auto& clipo = clip.clipobjects[i];
if (!clipo.obj.exbits && IsCloseToLine(pos, clipo.line.start, clipo.line.end, clip.walldist) != EClose::Outside)
{
auto opos = pos;
keepaway(clip, pos, clipo);
if (!inside(pos.X, pos.Y, sect))
pos = opos;
break;
}
}
}
//==========================================================================
//
//
//
//==========================================================================
bool isAwayFromWall(DCoreActor* ac, double delta)
{
sectortype* s1;

View file

@ -278,6 +278,8 @@ struct ClipRect
struct ClipLine
{
DVector2 start, end;
DVector2 delta() const { return end - start; }
};
struct ClipObject
@ -314,6 +316,7 @@ struct MoveClipper
void collectClipObjects(MoveClipper& clip, int spritemask);
int FindBestSector(const DVector3& pos);
int FindSectorInSearchList(const DVector3& pos, BFSSectorSearch& search);
void PushAway(MoveClipper &clip, DVector2& pos, sectortype* sect);
int FindBestSector(const DVector3& pos);