Skip to content

Commit

Permalink
Merge pull request #122 from samisalreadytaken/cleanup
Browse files Browse the repository at this point in the history
Minor adjustments
  • Loading branch information
Blixibon authored May 27, 2021
2 parents 3287643 + c62d86e commit be71cb4
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 82 deletions.
8 changes: 7 additions & 1 deletion sp/src/game/client/vscript_client.nut
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ function IncludeScript( name, scope = null )
function DispatchParticleEffect( particleName, origin, angles, entity = null )
{
DoDispatchParticleEffect( particleName, origin, angles, entity );
return DoDispatchParticleEffect( particleName, origin, angles, entity );
}
function ImpulseScale( flTargetMass, flDesiredSpeed )
{
return flTargetMass * flDesiredSpeed;
}
__Documentation.RegisterHelp( "ImpulseScale", "float ImpulseScale(float, float)", "Returns an impulse scale required to push an object." );
)vscript";
8 changes: 6 additions & 2 deletions sp/src/game/server/vscript_server.nut
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ function EntFireByHandle( target, action, value = null, delay = 0.0, activator =
function DispatchParticleEffect( particleName, origin, angles, entity = null )
{
DoDispatchParticleEffect( particleName, origin, angles, entity );
return DoDispatchParticleEffect( particleName, origin, angles, entity );
}
__Documentation.RegisterHelp( "CConvars::GetClientConvarValue", "CConvars::GetClientConvarValue(string, int)", "Returns the convar value for the entindex as a string. Only works with client convars with the FCVAR_USERINFO flag." );
function ImpulseScale( flTargetMass, flDesiredSpeed )
{
return flTargetMass * flDesiredSpeed;
}
__Documentation.RegisterHelp( "ImpulseScale", "float ImpulseScale(float, float)", "Returns an impulse scale required to push an object." );
function __ReplaceClosures( script, scope )
{
Expand Down
18 changes: 6 additions & 12 deletions sp/src/game/shared/baseentity_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,8 @@ void CBaseEntity::ScriptContextThink()
float flNextThink = FLT_MAX;
float flScheduled = 0.0f;

ScriptVariant_t arg = m_hScriptInstance;

for ( int i = 0; i < m_ScriptThinkFuncs.Count(); ++i )
{
scriptthinkfunc_t *cur = m_ScriptThinkFuncs[i];
Expand Down Expand Up @@ -2766,21 +2768,12 @@ void CBaseEntity::ScriptContextThink()
if ( !cur->m_bNoParam )
{
#endif
ScriptVariant_t arg = m_hScriptInstance;
if ( g_pScriptVM->ExecuteFunction( cur->m_hfnThink, &arg, 1, &varReturn, NULL, true ) == SCRIPT_ERROR )
{
cur->m_flNextThink = SCRIPT_NEVER_THINK;
continue;
}
g_pScriptVM->ExecuteFunction( cur->m_hfnThink, &arg, 1, &varReturn, NULL, true );
#ifndef CLIENT_DLL
}
else
{
if ( g_pScriptVM->ExecuteFunction( cur->m_hfnThink, NULL, 0, &varReturn, NULL, true ) == SCRIPT_ERROR )
{
cur->m_flNextThink = SCRIPT_NEVER_THINK;
continue;
}
g_pScriptVM->ExecuteFunction( cur->m_hfnThink, NULL, 0, &varReturn, NULL, true );
}
#endif

Expand All @@ -2793,6 +2786,7 @@ void CBaseEntity::ScriptContextThink()
float flReturn;
if ( !varReturn.AssignTo( &flReturn ) )
{
varReturn.Free();
cur->m_flNextThink = SCRIPT_NEVER_THINK;
continue;
}
Expand All @@ -2808,7 +2802,7 @@ void CBaseEntity::ScriptContextThink()
flNextThink = flReturn;
}

cur->m_flNextThink = gpGlobals->curtime + flReturn - 0.001;
cur->m_flNextThink = gpGlobals->curtime + flReturn - 0.001f;
}

// deferred safe removal
Expand Down
15 changes: 2 additions & 13 deletions sp/src/game/shared/mapbase/vscript_funcs_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,6 @@ 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
// TODO: Move this?
static void ScriptInsertSound( int iType, const Vector &vecOrigin, int iVolume, float flDuration, HSCRIPT hOwner, int soundChannelIndex, HSCRIPT hSoundTarget )
Expand Down Expand Up @@ -873,7 +863,6 @@ void RegisterSharedScriptFunctions()

ScriptRegisterFunction( g_pScriptVM, CreateDamageInfo, "Creates damage info." );
ScriptRegisterFunction( g_pScriptVM, DestroyDamageInfo, "Destroys damage info." );
ScriptRegisterFunction( g_pScriptVM, ImpulseScale, "Returns an impulse scale required to push an object." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalculateExplosiveDamageForce, "CalculateExplosiveDamageForce", "Fill out a damage info handle with a damage force for an explosive." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalculateBulletDamageForce, "CalculateBulletDamageForce", "Fill out a damage info handle with a damage force for a bullet impact." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalculateMeleeDamageForce, "CalculateMeleeDamageForce", "Fill out a damage info handle with a damage force for a melee impact." );
Expand All @@ -896,10 +885,10 @@ void RegisterSharedScriptFunctions()
//
// Precaching
//
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPrecacheModel, "PrecacheModel", "Precaches a model for later usage." );
ScriptRegisterFunctionNamed( g_pScriptVM, CBaseEntity::PrecacheModel, "PrecacheModel", "Precaches a model for later usage." );
ScriptRegisterFunction( g_pScriptVM, PrecacheMaterial, "Precaches a material for later usage." );
ScriptRegisterFunction( g_pScriptVM, PrecacheParticleSystem, "Precaches a particle system for later usage." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPrecacheOther, "PrecacheOther", "Precaches an entity class for later usage." );
ScriptRegisterFunctionNamed( g_pScriptVM, UTIL_PrecacheOther, "PrecacheOther", "Precaches an entity class for later usage." );

//
// NPCs
Expand Down
83 changes: 38 additions & 45 deletions sp/src/game/shared/mapbase/vscript_singletons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "tier0/memdbgon.h"

extern IScriptManager *scriptmanager;
CNetMsgScriptHelper *g_ScriptNetMsg = new CNetMsgScriptHelper();

//=============================================================================
// Net Prop Manager
Expand Down Expand Up @@ -401,7 +400,7 @@ class CScriptGameEventListener : public IGameEventListener2, public CAutoGameSys
//int m_nEventTick;

static StringHashFunctor Hash;
static inline unsigned int HashContext( const char* c ) { return (c && *c) ? Hash(c) : 0; }
static inline unsigned int HashContext( const char* c ) { return c ? Hash(c) : 0; }

inline int GetIndex()
{
Expand Down Expand Up @@ -574,11 +573,10 @@ void CScriptGameEventListener::LoadEventsFromFile( const char *filename, const c
void CScriptGameEventListener::DumpEventListeners()
{
CGMsg( 0, CON_GROUP_VSCRIPT, "--- Script game event listener dump start\n" );
CGMsg( 0, CON_GROUP_VSCRIPT, "# ADDRESS ID CONTEXT\n" );
CGMsg( 0, CON_GROUP_VSCRIPT, "# ID CONTEXT\n" );
FOR_EACH_VEC( s_Listeners, i )
{
CGMsg( 0, CON_GROUP_VSCRIPT, " %d (0x%p) %d : %u\n", i,
(void*)s_Listeners[i],
CGMsg( 0, CON_GROUP_VSCRIPT, " %d : %d : %u\n", i,
s_Listeners[i]->GetIndex(),
s_Listeners[i]->m_iContextHash );
}
Expand Down Expand Up @@ -755,14 +753,12 @@ bool CScriptGameEventListener::StopListeningToGameEvent( int listener )
void CScriptGameEventListener::StopListeningToAllGameEvents( const char* szContext )
{
unsigned int hash = HashContext( szContext );

// Iterate from the end so they can be safely removed as they are deleted
for ( int i = s_Listeners.Count(); i--; )
{
CScriptGameEventListener *pCur = s_Listeners[i];
if ( pCur->m_iContextHash == hash )
{
s_Listeners.Remove(i); // keep list order
s_Listeners.FastRemove(i);
delete pCur;
}
}
Expand Down Expand Up @@ -1202,10 +1198,7 @@ HSCRIPT CScriptReadWriteFile::KeyValuesRead( const char *szFile )

return hScript;
}
#undef SCRIPT_MAX_FILE_READ_SIZE
#undef SCRIPT_MAX_FILE_WRITE_SIZE
#undef SCRIPT_RW_PATH_ID
#undef SCRIPT_RW_FULL_PATH_FMT


//=============================================================================
// Network message helper
Expand All @@ -1215,6 +1208,8 @@ HSCRIPT CScriptReadWriteFile::KeyValuesRead( const char *szFile )
// The custom message name is hashed and sent as word with the message.
//=============================================================================

static CNetMsgScriptHelper scriptnetmsg;
CNetMsgScriptHelper *g_ScriptNetMsg = &scriptnetmsg;

#ifdef GAME_DLL
#define m_MsgIn_() m_MsgIn->
Expand Down Expand Up @@ -2181,23 +2176,23 @@ END_SCRIPTDESC();
//=============================================================================
// ConVars
//=============================================================================
class CScriptConCommand : public ICommandCallback, public ICommandCompletionCallback
class CScriptConCommand : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
{
typedef ConCommand BaseClass;

public:
~CScriptConCommand()
{
Unregister();
delete m_pBase;
}

CScriptConCommand( const char *name, HSCRIPT fn, const char *helpString, int flags, ConCommand *pLinked = NULL )
: BaseClass( name, this, helpString, flags, 0 ),
m_pLinked(pLinked),
m_hCallback(fn),
m_hCompletionCallback(NULL)
{
m_pBase = new ConCommand( name, this, helpString, flags, 0 );
m_pLinked = pLinked;
m_hCallback = fn;
m_hCompletionCallback = NULL;
m_nCmdNameLen = V_strlen(name) + 1;

Assert( m_nCmdNameLen - 1 <= 128 );
}

Expand Down Expand Up @@ -2272,17 +2267,17 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall

if (fn)
{
if ( !m_pBase->IsRegistered() )
if ( !BaseClass::IsRegistered() )
return;

m_pBase->m_pCommandCompletionCallback = this;
m_pBase->m_bHasCompletionCallback = true;
BaseClass::m_pCommandCompletionCallback = this;
BaseClass::m_bHasCompletionCallback = true;
m_hCompletionCallback = fn;
}
else
{
m_pBase->m_pCommandCompletionCallback = NULL;
m_pBase->m_bHasCompletionCallback = false;
BaseClass::m_pCommandCompletionCallback = NULL;
BaseClass::m_bHasCompletionCallback = false;
m_hCompletionCallback = NULL;
}
}
Expand All @@ -2291,7 +2286,7 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
{
if (fn)
{
if ( !m_pBase->IsRegistered() )
if ( !BaseClass::IsRegistered() )
Register();

if ( m_hCallback )
Expand All @@ -2306,8 +2301,8 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall

inline void Unregister()
{
if ( g_pCVar && m_pBase->IsRegistered() )
g_pCVar->UnregisterConCommand( m_pBase );
if ( g_pCVar && BaseClass::IsRegistered() )
g_pCVar->UnregisterConCommand( this );

if ( g_pScriptVM )
{
Expand All @@ -2324,30 +2319,29 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
inline void Register()
{
if ( g_pCVar )
g_pCVar->RegisterConCommand( m_pBase );
g_pCVar->RegisterConCommand( this );
}

HSCRIPT m_hCallback;
ConCommand *m_pLinked;
HSCRIPT m_hCompletionCallback;
int m_nCmdNameLen;
ConCommand *m_pLinked;
ConCommand *m_pBase;
};

class CScriptConVar
class CScriptConVar : public ConVar
{
typedef ConVar BaseClass;

public:
~CScriptConVar()
{
Unregister();
delete m_pBase;
}

CScriptConVar( const char *pName, const char *pDefaultValue, const char *pHelpString, int flags/*, float fMin, float fMax*/ )
{
m_pBase = new ConVar( pName, pDefaultValue, flags, pHelpString );
m_hCallback = NULL;
}
: BaseClass( pName, pDefaultValue, flags, pHelpString ),
m_hCallback(NULL)
{}

void SetChangeCallback( HSCRIPT fn )
{
Expand All @@ -2359,19 +2353,19 @@ class CScriptConVar
if (fn)
{
m_hCallback = fn;
m_pBase->InstallChangeCallback( (FnChangeCallback_t)ScriptConVarCallback );
BaseClass::InstallChangeCallback( (FnChangeCallback_t)ScriptConVarCallback );
}
else
{
m_hCallback = NULL;
m_pBase->InstallChangeCallback( NULL );
BaseClass::InstallChangeCallback( NULL );
}
}

inline void Unregister()
{
if ( g_pCVar && m_pBase->IsRegistered() )
g_pCVar->UnregisterConCommand( m_pBase );
if ( g_pCVar && BaseClass::IsRegistered() )
g_pCVar->UnregisterConCommand( this );

if ( g_pScriptVM )
{
Expand All @@ -2380,7 +2374,6 @@ class CScriptConVar
}

HSCRIPT m_hCallback;
ConVar *m_pBase;
};

static CUtlMap< unsigned int, bool > g_ConVarsBlocked( DefLessFunc(unsigned int) );
Expand Down Expand Up @@ -2541,8 +2534,8 @@ void CScriptConvarAccessor::RegisterCommand( const char *name, HSCRIPT fn, const
int idx = g_ScriptConCommands.Find(hash);
if ( idx == g_ScriptConCommands.InvalidIndex() )
{
ConCommand *pLinked = NULL;
if ( g_pCVar->FindVar(name) || ( ((pLinked = g_pCVar->FindCommand(name)) != NULL) && !IsOverridable(hash) ) )
ConCommandBase *pBase = g_pCVar->FindCommandBase(name);
if ( pBase && ( !pBase->IsCommand() || !IsOverridable(hash) ) )
{
DevWarning( 1, "CScriptConvarAccessor::RegisterCommand unable to register blocked ConCommand: %s\n", name );
return;
Expand All @@ -2551,7 +2544,7 @@ void CScriptConvarAccessor::RegisterCommand( const char *name, HSCRIPT fn, const
if ( !fn )
return;

CScriptConCommand *p = new CScriptConCommand( name, fn, helpString, flags, pLinked );
CScriptConCommand *p = new CScriptConCommand( name, fn, helpString, flags, static_cast< ConCommand* >(pBase) );
g_ScriptConCommands.Insert( hash, p );
}
else
Expand Down Expand Up @@ -2589,7 +2582,7 @@ void CScriptConvarAccessor::RegisterConvar( const char *name, const char *pDefau
int idx = g_ScriptConVars.Find(hash);
if ( idx == g_ScriptConVars.InvalidIndex() )
{
if ( g_pCVar->FindVar(name) || g_pCVar->FindCommand(name) )
if ( g_pCVar->FindCommandBase(name) )
{
DevWarning( 1, "CScriptConvarAccessor::RegisterConvar unable to register blocked ConCommand: %s\n", name );
return;
Expand Down
Loading

0 comments on commit be71cb4

Please sign in to comment.