Merge pull request #148 from samisalreadytaken/fixup

Minor fixup
This commit is contained in:
Blixibon 2021-11-07 08:15:30 -06:00 committed by GitHub
commit 4b295c17e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 119 additions and 59 deletions

View File

@ -4037,7 +4037,10 @@ Vector CHL2_Player::EyeDirection2D( void )
Vector CHL2_Player::EyeDirection3D( void ) Vector CHL2_Player::EyeDirection3D( void )
{ {
Vector vecForward; Vector vecForward;
#ifdef MAPBASE
EyeVectors( &vecForward );
return vecForward;
#else
// Return the vehicle angles if we request them // Return the vehicle angles if we request them
if ( GetVehicle() != NULL ) if ( GetVehicle() != NULL )
{ {
@ -4048,6 +4051,7 @@ Vector CHL2_Player::EyeDirection3D( void )
AngleVectors( EyeAngles(), &vecForward ); AngleVectors( EyeAngles(), &vecForward );
return vecForward; return vecForward;
#endif
} }

View File

@ -775,6 +775,16 @@ static void AddPhysVelocity( HSCRIPT hPhys, const Vector& vecVelocity, const Vec
//============================================================================= //=============================================================================
//============================================================================= //=============================================================================
static int ScriptPrecacheModel( const char *modelname )
{
return CBaseEntity::PrecacheModel( modelname );
}
static void ScriptPrecacheOther( const char *classname )
{
UTIL_PrecacheOther( classname );
}
#ifndef CLIENT_DLL #ifndef CLIENT_DLL
// TODO: Move this? // TODO: Move this?
static void ScriptInsertSound( int iType, const Vector &vecOrigin, int iVolume, float flDuration, HSCRIPT hOwner, int soundChannelIndex, HSCRIPT hSoundTarget ) static void ScriptInsertSound( int iType, const Vector &vecOrigin, int iVolume, float flDuration, HSCRIPT hOwner, int soundChannelIndex, HSCRIPT hSoundTarget )
@ -996,10 +1006,10 @@ void RegisterSharedScriptFunctions()
// //
// Precaching // Precaching
// //
ScriptRegisterFunctionNamed( g_pScriptVM, CBaseEntity::PrecacheModel, "PrecacheModel", "Precaches a model for later usage." ); ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPrecacheModel, "PrecacheModel", "Precaches a model for later usage." );
ScriptRegisterFunction( g_pScriptVM, PrecacheMaterial, "Precaches a material for later usage." ); ScriptRegisterFunction( g_pScriptVM, PrecacheMaterial, "Precaches a material for later usage." );
ScriptRegisterFunction( g_pScriptVM, PrecacheParticleSystem, "Precaches a particle system for later usage." ); ScriptRegisterFunction( g_pScriptVM, PrecacheParticleSystem, "Precaches a particle system for later usage." );
ScriptRegisterFunctionNamed( g_pScriptVM, UTIL_PrecacheOther, "PrecacheOther", "Precaches an entity class for later usage." ); ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPrecacheOther, "PrecacheOther", "Precaches an entity class for later usage." );
// //
// NPCs // NPCs

View File

@ -366,6 +366,11 @@ END_SCRIPTDESC();
//============================================================================= //=============================================================================
// Game Event Listener // Game Event Listener
// Based on Source 2 API // Based on Source 2 API
//
// NOTE: In Source 2 vscript (Lua) event listener contexts are tables that are
// passed to the callback function as the call environment.
// In mapbase implementation these are string identifiers because unlike Lua,
// Squirrel has closure methods such as 'bindenv' which can bind functions to specified environments.
//============================================================================= //=============================================================================
// Define to use the older code that loads all events manually independent from the game event manager. // Define to use the older code that loads all events manually independent from the game event manager.
@ -375,7 +380,13 @@ END_SCRIPTDESC();
class CScriptGameEventListener : public IGameEventListener2, public CAutoGameSystem class CScriptGameEventListener : public IGameEventListener2, public CAutoGameSystem
{ {
public: public:
CScriptGameEventListener() : m_bActive(false) /*, m_nEventTick(0)*/ {} CScriptGameEventListener() : m_bActive(false)
{
#ifdef _DEBUG
m_nEventTick = 0;
#endif
}
~CScriptGameEventListener() ~CScriptGameEventListener()
{ {
StopListeningForEvent(); StopListeningForEvent();
@ -397,7 +408,9 @@ private:
HSCRIPT m_hCallback; HSCRIPT m_hCallback;
unsigned int m_iContextHash; unsigned int m_iContextHash;
bool m_bActive; bool m_bActive;
//int m_nEventTick; #ifdef _DEBUG
int m_nEventTick;
#endif
static StringHashFunctor Hash; static StringHashFunctor Hash;
static inline unsigned int HashContext( const char* c ) { return c ? Hash(c) : 0; } static inline unsigned int HashContext( const char* c ) { return c ? Hash(c) : 0; }
@ -592,7 +605,9 @@ void CScriptGameEventListener::LevelShutdownPreEntity()
void CScriptGameEventListener::FireGameEvent( IGameEvent *event ) void CScriptGameEventListener::FireGameEvent( IGameEvent *event )
{ {
//m_nEventTick = gpGlobals->tickcount; #ifdef _DEBUG
m_nEventTick = gpGlobals->tickcount;
#endif
ScriptVariant_t hTable; ScriptVariant_t hTable;
g_pScriptVM->CreateTable( hTable ); g_pScriptVM->CreateTable( hTable );
WriteEventData( event, hTable ); WriteEventData( event, hTable );
@ -722,13 +737,15 @@ void CScriptGameEventListener::StopListeningForEvent()
if ( gameeventmanager ) if ( gameeventmanager )
gameeventmanager->RemoveListener( this ); gameeventmanager->RemoveListener( this );
#ifdef _DEBUG
// Event listeners are iterated forwards in the game event manager, // Event listeners are iterated forwards in the game event manager,
// removing while iterating will cause it to skip one listener. // removing while iterating will cause it to skip one listener.
// This could be prevented by writing a custom game event manager. // This could be prevented by writing a custom game event manager.
//if ( m_nEventTick == gpGlobals->tickcount ) if ( m_nEventTick == gpGlobals->tickcount )
//{ {
// Warning("CScriptGameEventListener stopped in the same frame it was fired. This will break other event listeners!\n"); Warning("CScriptGameEventListener stopped in the same frame it was fired. This will break other event listeners!\n");
//} }
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -2423,9 +2440,7 @@ public:
inline bool IsOverridable( unsigned int hash ) inline bool IsOverridable( unsigned int hash )
{ {
int idx = g_ConCommandsOverridable.Find( hash ); int idx = g_ConCommandsOverridable.Find( hash );
if ( idx == g_ConCommandsOverridable.InvalidIndex() ) return ( idx != g_ConCommandsOverridable.InvalidIndex() );
return false;
return true;
} }
inline void AddBlockedConVar( const char *name ) inline void AddBlockedConVar( const char *name )
@ -2436,9 +2451,7 @@ public:
inline bool IsBlockedConvar( const char *name ) inline bool IsBlockedConvar( const char *name )
{ {
int idx = g_ConVarsBlocked.Find( Hash(name) ); int idx = g_ConVarsBlocked.Find( Hash(name) );
if ( idx == g_ConVarsBlocked.InvalidIndex() ) return ( idx != g_ConVarsBlocked.InvalidIndex() );
return false;
return true;
} }
public: public:

View File

@ -11,58 +11,78 @@ function clamp(val,min,max)
{ {
if ( max < min ) if ( max < min )
return max; return max;
else if( val < min ) if ( val < min )
return min; return min;
else if( val > max ) if ( val > max )
return max; return max;
else
return val; return val;
} }
function max(a,b) return a > b ? a : b function max( a, b )
{
if ( a > b )
return a;
return b;
}
function min(a,b) return a < b ? a : b function min( a, b )
{
if ( a < b )
return a;
return b;
}
function RemapVal( val, A, B, C, D ) function RemapVal( val, A, B, C, D )
{ {
if ( A == B ) if ( A == B )
return val >= B ? D : C; {
if ( val >= B )
return D;
return C;
};
return C + (D - C) * (val - A) / (B - A); return C + (D - C) * (val - A) / (B - A);
} }
function RemapValClamped( val, A, B, C, D ) function RemapValClamped( val, A, B, C, D )
{ {
if ( A == B ) if ( A == B )
return val >= B ? D : C; {
if ( val >= B )
return D;
return C;
};
local cVal = (val - A) / (B - A); local cVal = (val - A) / (B - A);
cVal = (cVal < 0.0) ? 0.0 : (1.0 < cVal) ? 1.0 : cVal;
if ( cVal <= 0.0 )
return C;
if ( cVal >= 1.0 )
return D;
return C + (D - C) * cVal; return C + (D - C) * cVal;
} }
function Approach( target, value, speed ) function Approach( target, value, speed )
{ {
local delta = target - value local delta = target - value;
if ( delta > speed ) if ( delta > speed )
value += speed return value + speed;
else if( delta < (-speed) ) if ( -speed > delta )
value -= speed return value - speed;
else return target;
value = target
return value
} }
function AngleDistance( next, cur ) function AngleDistance( next, cur )
{ {
local delta = next - cur local delta = next - cur
if ( delta < (-180.0) ) if ( delta > 180.0 )
delta += 360.0 return delta - 360.0;
else if ( delta > 180.0 ) if ( -180.0 > delta )
delta -= 360.0 return delta + 360.0;
return delta;
return delta
} }
function FLerp( f1, f2, i1, i2, x ) function FLerp( f1, f2, i1, i2, x )
@ -83,7 +103,7 @@ function SimpleSpline( f )
function printl( text ) function printl( text )
{ {
return ::print(text + "\n"); return print(text + "\n");
} }
class CSimpleCallChainer class CSimpleCallChainer
@ -481,6 +501,8 @@ else
} }
} }
if (developer)
{
// Vector documentation // Vector documentation
__Documentation.RegisterClassHelp( "Vector", "", "Basic 3-float Vector class." ); __Documentation.RegisterClassHelp( "Vector", "", "Basic 3-float Vector class." );
__Documentation.RegisterHelp( "Vector::Length", "float Vector::Length()", "Return the vector's length." ); __Documentation.RegisterHelp( "Vector::Length", "float Vector::Length()", "Return the vector's length." );
@ -500,4 +522,15 @@ __Documentation.RegisterMemberHelp( "Vector.x", "float Vector.x", "The vector's
__Documentation.RegisterMemberHelp( "Vector.y", "float Vector.y", "The vector's Y coordinate on the cartesian Y axis." ); __Documentation.RegisterMemberHelp( "Vector.y", "float Vector.y", "The vector's Y coordinate on the cartesian Y axis." );
__Documentation.RegisterMemberHelp( "Vector.z", "float Vector.z", "The vector's Z coordinate on the cartesian Z axis." ); __Documentation.RegisterMemberHelp( "Vector.z", "float Vector.z", "The vector's Z coordinate on the cartesian Z axis." );
__Documentation.RegisterHelp( "clamp", "float clamp(float, float, float)", "" );
__Documentation.RegisterHelp( "max", "float max(float, float)", "" );
__Documentation.RegisterHelp( "min", "float min(float, float)", "" );
__Documentation.RegisterHelp( "RemapVal", "float RemapVal(float, float, float, float, float)", "" );
__Documentation.RegisterHelp( "RemapValClamped", "float RemapValClamped(float, float, float, float, float)", "" );
__Documentation.RegisterHelp( "Approach", "float Approach(float, float, float)", "" );
__Documentation.RegisterHelp( "AngleDistance", "float AngleDistance(float, float)", "" );
__Documentation.RegisterHelp( "FLerp", "float FLerp(float, float, float, float, float)", "" );
__Documentation.RegisterHelp( "Lerp", "float Lerp(float, float, float)", "" );
__Documentation.RegisterHelp( "SimpleSpline", "float SimpleSpline(float)", "" );
}
)vscript"; )vscript";