Skip to content

Commit

Permalink
Finish Trace Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
caxanga334 committed Jun 7, 2024
1 parent 758cd02 commit 72cd986
Show file tree
Hide file tree
Showing 39 changed files with 328 additions and 1,410 deletions.
4 changes: 0 additions & 4 deletions extension/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ sourceFiles = [
'navmesh/nav_node.cpp',
'navmesh/nav_simplify.cpp',
# Utility
'util/BaseEntity.cpp',
'util/EntityUtils.cpp',
'util/SimpleException.cpp',
'util/UtilTrace.cpp',
'util/entprops.cpp',
'util/helpers.cpp',
'util/librandom.cpp',
Expand Down
88 changes: 38 additions & 50 deletions extension/bot/interfaces/movement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <navmesh/nav_ladder.h>
#include <manager.h>
#include <mods/basemod.h>
#include <util/EntityUtils.h>
#include <util/entprops.h>
#include <util/helpers.h>
#include <entities/baseentity.h>
#include "movement.h"

extern CExtManager* extmanager;
Expand All @@ -19,46 +19,41 @@ constexpr auto DEFAULT_PLAYER_DUCKING_HEIGHT = 36.0f;
constexpr auto DEFAULT_PLAYER_HULL_WIDTH = 32.0f;

CMovementTraverseFilter::CMovementTraverseFilter(CBaseBot* bot, IMovement* mover, const bool now) :
CTraceFilterSimple(bot->GetEdict()->GetIServerEntity(), COLLISION_GROUP_PLAYER_MOVEMENT)
trace::CTraceFilterSimple(bot->GetEntity(), COLLISION_GROUP_NONE)
{
m_me = bot;
m_mover = mover;
m_now = now;
}

bool CMovementTraverseFilter::ShouldHitEntity(IHandleEntity* pHandleEntity, int contentsMask)
bool CMovementTraverseFilter::ShouldHitEntity(int entity, CBaseEntity* pEntity, edict_t* pEdict, const int contentsMask)
{
edict_t* entity = entityFromEntityHandle(pHandleEntity);

if (entity == m_me->GetEdict())
if (pEntity != nullptr && pEdict != nullptr)
{
return false; // don't hit the bot
}
if (pEntity == m_me->GetEntity())
{
return false; // Don't hit myself
}

if (CTraceFilterSimple::ShouldHitEntity(pHandleEntity, contentsMask))
{
return !m_mover->IsEntityTraversable(entity, m_now);
if (CTraceFilterSimple::ShouldHitEntity(entity, pEntity, pEdict, contentsMask))
{
return !m_mover->IsEntityTraversable(pEdict, m_now);
}
}

return false;
}

CTraceFilterOnlyActors::CTraceFilterOnlyActors(const IHandleEntity* handleentity) :
CTraceFilterSimple(handleentity, COLLISION_GROUP_NONE, nullptr)
CTraceFilterOnlyActors::CTraceFilterOnlyActors(CBaseEntity* pPassEnt, int collisionGroup) :
trace::CTraceFilterSimple(pPassEnt, collisionGroup)
{
}

bool CTraceFilterOnlyActors::ShouldHitEntity(IHandleEntity* pHandleEntity, int contentsMask)
bool CTraceFilterOnlyActors::ShouldHitEntity(int entity, CBaseEntity* pEntity, edict_t* pEdict, const int contentsMask)
{
if (CTraceFilterSimple::ShouldHitEntity(pHandleEntity, contentsMask))
if (trace::CTraceFilterSimple::ShouldHitEntity(entity, pEntity, pEdict, contentsMask))
{
edict_t* entity = entityFromEntityHandle(pHandleEntity);
int index = gamehelpers->IndexOfEdict(entity);

if (UtilHelpers::IsPlayerIndex(index))
{
return true; // hit players
}
return UtilHelpers::IsPlayerIndex(entity);
}

return false;
Expand Down Expand Up @@ -425,7 +420,7 @@ bool IMovement::IsAbleToClimbOntoEntity(edict_t* entity)
return false;
}

if (FClassnameIs(entity, "func_door*") == true || FClassnameIs(entity, "prop_door*") == true)
if (UtilHelpers::FClassnameIs(entity, "func_door*") == true || UtilHelpers::FClassnameIs(entity, "prop_door*") == true)
{
return false; // never climb doors
}
Expand Down Expand Up @@ -455,11 +450,10 @@ bool IMovement::IsOnLadder()
bool IMovement::IsGap(const Vector& pos, const Vector& forward)
{
trace_t result;
CTraceFilterNoNPCsOrPlayer filter(GetBot()->GetEdict()->GetIServerEntity(), COLLISION_GROUP_PLAYER_MOVEMENT);
trace::CTraceFilterNoNPCsOrPlayers filter(GetBot()->GetEntity(), COLLISION_GROUP_NONE);
Vector start = pos + Vector(0.0f, 0.0f, GetStepHeight());
Vector end = pos + Vector(0.0f, 0.0f, -GetMaxJumpHeight());
UTIL_TraceLine(start, end, GetMovementTraceMask(), &filter, &result);

trace::line(start, end, GetMovementTraceMask(), &filter, result);
return result.fraction >= 1.0f && !result.startsolid;
}

Expand Down Expand Up @@ -493,7 +487,7 @@ bool IMovement::IsPotentiallyTraversable(const Vector& from, const Vector& to, f
const float height = GetStepHeight();
Vector mins(-hullsize, -hullsize, height);
Vector maxs(hullsize, hullsize, GetCrouchedHullHeigh());
UTIL_TraceHull(from, to, mins, maxs, GetMovementTraceMask(), nullptr, COLLISION_GROUP_NONE, &result);
trace::hull(from, to, mins, maxs, GetMovementTraceMask(), &filter, result);

if (GetBot()->IsDebugging(BOTDEBUG_MOVEMENT))
{
Expand Down Expand Up @@ -558,12 +552,12 @@ bool IMovement::IsEntityTraversable(edict_t* entity, const bool now)
return false;
}

if (FClassnameIs(entity, "func_door*") == true)
if (UtilHelpers::FClassnameIs(entity, "func_door*") == true)
{
return true;
}

if (FClassnameIs(entity, "prop_door*") == true)
if (UtilHelpers::FClassnameIs(entity, "prop_door*") == true)
{
int doorstate = 0;
if (entprops->GetEntProp(index, Prop_Data, "m_eDoorState", doorstate) == false)
Expand All @@ -580,24 +574,19 @@ bool IMovement::IsEntityTraversable(edict_t* entity, const bool now)
}
}

if (FClassnameIs(entity, "func_brush") == true)
if (UtilHelpers::FClassnameIs(entity, "func_brush") == true)
{
int solidity = 0;
if (entprops->GetEntProp(index, Prop_Data, "m_iSolidity", solidity) == true)
entities::HFuncBrush brush(gamehelpers->EdictOfIndex(index));
auto solidity = brush.GetSolidity();

switch (solidity)
{
switch (solidity)
{
case BRUSHSOLID_NEVER:
case BRUSHSOLID_TOGGLE:
{
return true;
}
case BRUSHSOLID_ALWAYS:
default:
{
return false;
}
}
case entities::HFuncBrush::BRUSHSOLID_TOGGLE:
case entities::HFuncBrush::BRUSHSOLID_NEVER:
return true;
case entities::HFuncBrush::BRUSHSOLID_ALWAYS:
default:
return false;
}
}

Expand Down Expand Up @@ -669,14 +658,14 @@ void IMovement::AdjustPathCrossingPoint(const CNavArea* fromArea, const CNavArea
return;
}

CTraceFilterNoNPCsOrPlayer filter(GetBot()->GetHandleEntity(), COLLISION_GROUP_NONE);
trace::CTraceFilterNoNPCsOrPlayers filter(GetBot()->GetEntity(), COLLISION_GROUP_NONE);
trace_t result;
float hullwidth = GetHullWidth();
Vector mins(-hullwidth, -hullwidth, GetStepHeight());
Vector maxs(hullwidth, hullwidth, GetStandingHullHeigh());
const Vector& endPos = *crosspoint;

UTIL_TraceHull(fromPos, endPos, mins, maxs, GetMovementTraceMask(), filter, &result);
trace::hull(fromPos, endPos, mins, maxs, GetMovementTraceMask(), &filter, result);

if (!result.DidHit())
{
Expand All @@ -690,7 +679,7 @@ void IMovement::AdjustPathCrossingPoint(const CNavArea* fromArea, const CNavArea

// direct path is blocked, try left first

UTIL_TraceHull(fromPos, endPos + (left * hullwidth), mins, maxs, GetMovementTraceMask(), filter, &result);
trace::hull(fromPos, endPos + (left * hullwidth), mins, maxs, GetMovementTraceMask(), &filter, result);

if (!result.DidHit())
{
Expand All @@ -705,8 +694,7 @@ void IMovement::AdjustPathCrossingPoint(const CNavArea* fromArea, const CNavArea
}

// try right

UTIL_TraceHull(fromPos, endPos + (left * -hullwidth), mins, maxs, GetMovementTraceMask(), filter, &result);
trace::hull(fromPos, endPos + (left * -hullwidth), mins, maxs, GetMovementTraceMask(), &filter, result);

if (!result.DidHit())
{
Expand Down
11 changes: 6 additions & 5 deletions extension/bot/interfaces/movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@

#include <bot/interfaces/base_interface.h>
#include <sdkports/sdk_timers.h>
#include <sdkports/sdk_traces.h>

class CNavLadder;
class CNavArea;
class IMovement;

class CMovementTraverseFilter : public CTraceFilterSimple
class CMovementTraverseFilter : public trace::CTraceFilterSimple
{
public:
CMovementTraverseFilter(CBaseBot* bot, IMovement* mover, const bool now = true);

virtual bool ShouldHitEntity(IHandleEntity* pHandleEntity, int contentsMask) override;
bool ShouldHitEntity(int entity, CBaseEntity* pEntity, edict_t* pEdict, const int contentsMask) override;

private:
CBaseBot* m_me;
IMovement* m_mover;
bool m_now;
};

class CTraceFilterOnlyActors : public CTraceFilterSimple
class CTraceFilterOnlyActors : public trace::CTraceFilterSimple
{
public:
CTraceFilterOnlyActors(const IHandleEntity* handleentity);
CTraceFilterOnlyActors(CBaseEntity* pPassEnt, int collisionGroup);

virtual TraceType_t GetTraceType() const override
{
return TRACE_ENTITIES_ONLY;
}

virtual bool ShouldHitEntity(IHandleEntity* pHandleEntity, int contentsMask) override;
bool ShouldHitEntity(int entity, CBaseEntity* pEntity, edict_t* pEdict, const int contentsMask) override;
};

// Interface responsible for managing the bot's momvement and sending proper inputs to IPlayerController
Expand Down
9 changes: 4 additions & 5 deletions extension/bot/interfaces/path/basepath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,11 @@ bool CPath::ProcessGroundPath(CBaseBot* bot, const Vector& start, CBasePathSegme
Vector lowerPos = Vector(pos.x, pos.y, toPos.z);

trace_t result;
const IHandleEntity* botent = bot->GetEdict()->GetIServerEntity();
CTraceFilterNoNPCsOrPlayer filter(botent, COLLISION_GROUP_NONE);
trace::CTraceFilterNoNPCsOrPlayers filter(bot->GetEntity(), COLLISION_GROUP_NONE);
Vector v1(-halfWidth, -halfWidth, mover->GetStepHeight());
Vector v2(halfWidth, halfWidth, hullHeight);

UTIL_TraceHull(pos, lowerPos, v1, v2, mover->GetMovementTraceMask(), filter, &result);
trace::hull(pos, lowerPos, v1, v2, mover->GetMovementTraceMask(), &filter, result);

if (result.fraction >= 1.0f)
{
Expand Down Expand Up @@ -528,12 +527,12 @@ bool CPath::ProcessGroundPath(CBaseBot* bot, const Vector& start, CBasePathSegme

// Sometimes there is a railing between the drop and the ground

CTraceFilterNoNPCsOrPlayer filter(bot->GetHandleEntity(), COLLISION_GROUP_NONE);
trace::CTraceFilterNoNPCsOrPlayers filter(bot->GetEntity(), COLLISION_GROUP_NONE);
trace_t result;
Vector mins(-halfWidth, -halfWidth, mover->GetStepHeight());
Vector maxs(halfWidth, halfWidth, hullHeight);

UTIL_TraceHull(from->goal, startDrop, mins, maxs, mover->GetMovementTraceMask(), filter, &result);
trace::hull(from->goal, startDrop, mins, maxs, mover->GetMovementTraceMask(), &filter, result);

if (result.DidHit()) // probably collided with a railing
{
Expand Down
Loading

0 comments on commit 72cd986

Please sign in to comment.