Skip to content

Commit

Permalink
Stop motion_manager from spamming the console if position couldn't be…
Browse files Browse the repository at this point in the history
… calculated
  • Loading branch information
FreeSlave committed Sep 26, 2024
1 parent e5863e7 commit b72aebc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
40 changes: 26 additions & 14 deletions dlls/locus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool IsLikelyNumber(const char* szText)
return (*szText >= '0' && *szText <= '9') || *szText == '-';
}

bool TryCalcLocus_Position( CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result )
bool TryCalcLocus_Position(CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result, bool showError)
{
if (IsLikelyNumber(szText))
{ // it's a vector
Expand All @@ -34,13 +34,16 @@ bool TryCalcLocus_Position( CBaseEntity *pEntity, CBaseEntity *pLocus, const cha
return pCalc->CalcPosition( pLocus, &result );
}

const char* requesterClassname = pEntity ? STRING(pEntity->pev->classname) : "";
const char* requesterTargetname = pEntity ? STRING(pEntity->pev->targetname) : "";
ALERT(at_error, "%s \"%s\" has bad or missing calc_position value \"%s\"\n", requesterClassname, requesterTargetname, szText);
if (showError)
{
const char* requesterClassname = pEntity ? STRING(pEntity->pev->classname) : "";
const char* requesterTargetname = pEntity ? STRING(pEntity->pev->targetname) : "";
ALERT(at_error, "%s \"%s\" has bad or missing calc_position value \"%s\"\n", requesterClassname, requesterTargetname, szText);
}
return false;
}

bool TryCalcLocus_Velocity(CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result)
bool TryCalcLocus_Velocity(CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result, bool showError)
{
if (IsLikelyNumber(szText))
{ // it's a vector
Expand All @@ -56,13 +59,16 @@ bool TryCalcLocus_Velocity(CBaseEntity *pEntity, CBaseEntity *pLocus, const char
return pCalc->CalcVelocity( pLocus, &result );
}

const char* requesterClassname = pEntity ? STRING(pEntity->pev->classname) : "";
const char* requesterTargetname = pEntity ? STRING(pEntity->pev->targetname) : "";
ALERT(at_error, "%s \"%s\" has bad or missing calc_velocity value \"%s\"\n", requesterClassname, requesterTargetname, szText);
if (showError)
{
const char* requesterClassname = pEntity ? STRING(pEntity->pev->classname) : "";
const char* requesterTargetname = pEntity ? STRING(pEntity->pev->targetname) : "";
ALERT(at_error, "%s \"%s\" has bad or missing calc_velocity value \"%s\"\n", requesterClassname, requesterTargetname, szText);
}
return false;
}

bool TryCalcLocus_Ratio(CBaseEntity *pLocus, const char *szText, float& result)
bool TryCalcLocus_Ratio(CBaseEntity *pLocus, const char *szText, float& result, bool showError)
{
if (IsLikelyNumber(szText))
{ // assume it's a float
Expand All @@ -77,11 +83,14 @@ bool TryCalcLocus_Ratio(CBaseEntity *pLocus, const char *szText, float& result)
return pCalc->CalcRatio( pLocus, &result );
}

ALERT(at_error, "Bad or missing calc_ratio entity \"%s\"\n", szText);
if (showError)
{
ALERT(at_error, "Bad or missing calc_ratio entity \"%s\"\n", szText);
}
return false;
}

bool TryCalcLocus_Color(CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result)
bool TryCalcLocus_Color(CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result, bool showError)
{
if (IsLikelyNumber(szText))
{ // it's a vector
Expand All @@ -98,9 +107,12 @@ bool TryCalcLocus_Color(CBaseEntity *pEntity, CBaseEntity *pLocus, const char *s
return true;
}

const char* requesterClassname = pEntity ? STRING(pEntity->pev->classname) : "";
const char* requesterTargetname = pEntity ? STRING(pEntity->pev->targetname) : "";
ALERT(at_error, "%s \"%s\" has bad or missing color value \"%s\"\n", requesterClassname, requesterTargetname, szText);
if (showError)
{
const char* requesterClassname = pEntity ? STRING(pEntity->pev->classname) : "";
const char* requesterTargetname = pEntity ? STRING(pEntity->pev->targetname) : "";
ALERT(at_error, "%s \"%s\" has bad or missing color value \"%s\"\n", requesterClassname, requesterTargetname, szText);
}
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions dlls/locus.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "cbase.h"

bool IsLikelyNumber(const char* szText);
bool TryCalcLocus_Position ( CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText , Vector& result );
bool TryCalcLocus_Velocity ( CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result );
bool TryCalcLocus_Ratio ( CBaseEntity *pLocus, const char *szText, float& result );
bool TryCalcLocus_Color ( CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result );
bool TryCalcLocus_Position ( CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText , Vector& result, bool showError = true );
bool TryCalcLocus_Velocity ( CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result, bool showError = true );
bool TryCalcLocus_Ratio ( CBaseEntity *pLocus, const char *szText, float& result, bool showError = true );
bool TryCalcLocus_Color ( CBaseEntity *pEntity, CBaseEntity *pLocus, const char *szText, Vector& result, bool showError = true );

#endif
37 changes: 29 additions & 8 deletions dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5090,6 +5090,9 @@ class CMotionThread : public CPointEntity
EHANDLE m_hLocus;
EHANDLE m_hTarget;

bool m_reportedPosError; // don't save
bool m_reportedDirError; // don't save

enum {
POSMODE_SET = 0,
POSMODE_OFFSET,
Expand Down Expand Up @@ -5154,44 +5157,54 @@ void CMotionThread::MotionThink( void )
switch (m_iPosMode)
{
case POSMODE_SET: // set position
if (TryCalcLocus_Position( this, m_hLocus, STRING(m_iszPosition), vecTemp )) {
if (TryCalcLocus_Position( this, m_hLocus, STRING(m_iszPosition), vecTemp, !m_reportedPosError )) {
if (debug)
Motion_PrintVectors("DEBUG: Set origin", m_hTarget->pev->origin, vecTemp);
UTIL_AssignOrigin(m_hTarget, vecTemp);
}
else
m_reportedPosError = true;
m_hTarget->pev->flags &= ~FL_ONGROUND;
break;
case POSMODE_OFFSET: // offset position (= fake velocity)
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszPosition), vecTemp )) {
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszPosition), vecTemp, !m_reportedPosError )) {
vecOld = m_hTarget->pev->origin;
UTIL_AssignOrigin(m_hTarget, vecOld + gpGlobals->frametime * vecTemp);
if (debug)
Motion_PrintVectors("DEBUG: Set origin", vecOld, m_hTarget->pev->origin);
}
else
m_reportedPosError = true;
m_hTarget->pev->flags &= ~FL_ONGROUND;
break;
case POSMODE_SETVEL: // set velocity
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszPosition), vecTemp )) {
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszPosition), vecTemp, !m_reportedPosError )) {
if (debug)
Motion_PrintVectors("DEBUG: Set velocity", m_hTarget->pev->velocity, vecTemp);
UTIL_SetVelocity(m_hTarget, vecTemp);
}
else
m_reportedPosError = true;
break;
case POSMODE_ACCELERATE: // accelerate
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszPosition), vecTemp )) {
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszPosition), vecTemp, !m_reportedPosError )) {
vecOld = m_hTarget->pev->velocity;
UTIL_SetVelocity(m_hTarget, vecOld + gpGlobals->frametime * vecTemp);
if (debug)
Motion_PrintVectors("DEBUG: Accelerate", vecOld, m_hTarget->pev->velocity);
}
else
m_reportedPosError = true;
break;
case POSMODE_FOLLOW: // follow position
if (TryCalcLocus_Position( this, m_hLocus, STRING(m_iszPosition), vecTemp )) {
if (TryCalcLocus_Position( this, m_hLocus, STRING(m_iszPosition), vecTemp, !m_reportedPosError )) {
vecOld = m_hTarget->pev->velocity;
UTIL_SetVelocity(m_hTarget, vecTemp - m_hTarget->pev->origin);
if (debug)
Motion_PrintVectors("DEBUG: Set velocity", vecOld, m_hTarget->pev->velocity);
}
else
m_reportedPosError = true;
break;
}
}
Expand All @@ -5204,7 +5217,7 @@ void CMotionThread::MotionThink( void )
switch (m_iFaceMode)
{
case FACEMODE_DIRECTION: // set angles
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszFacing), vecTemp ))
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszFacing), vecTemp, !m_reportedDirError ))
{
if (vecTemp != g_vecZero) // if the vector is 0 0 0, don't use it
{
Expand All @@ -5218,9 +5231,11 @@ void CMotionThread::MotionThink( void )
ALERT(at_console, "Zero velocity, don't change angles\n");
}
}
else
m_reportedDirError = true;
break;
case FACEMODE_ROTATE: // offset angles (= fake avelocity)
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszFacing), vecTemp ))
if (TryCalcLocus_Velocity( this, m_hLocus, STRING(m_iszFacing), vecTemp, !m_reportedDirError ))
{
if (vecTemp != g_vecZero) // if the vector is 0 0 0, don't use it
{
Expand All @@ -5234,6 +5249,8 @@ void CMotionThread::MotionThink( void )
ALERT(at_console, "Zero velocity, don't change angles\n");
}
}
else
m_reportedDirError = true;
break;
case FACEMODE_ROTATE_BY_VALUES: // offset angles (= fake avelocity)
UTIL_StringToRandomVector( vecVelAngles, STRING(m_iszFacing) );
Expand Down Expand Up @@ -5261,7 +5278,11 @@ void CMotionThread::MotionThink( void )
}
else
{
ALERT(at_error, "Could not find \"%s\" to set angles for \"%s\"", STRING(m_iszFacing), STRING(m_hTarget->pev->targetname));
if (!m_reportedDirError)
{
ALERT(at_error, "Could not find \"%s\" to set angles for \"%s\"", STRING(m_iszFacing), STRING(m_hTarget->pev->targetname));
m_reportedDirError = true;
}
}
}
break;
Expand Down

0 comments on commit b72aebc

Please sign in to comment.