Skip to content

Commit dc6599e

Browse files
authored
Merge pull request mapbase-source#122 from samisalreadytaken/cleanup
Minor adjustments
2 parents 49f167f + ea1d4ef commit dc6599e

7 files changed

+132
-82
lines changed

sp/src/game/client/vscript_client.nut

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ function IncludeScript( name, scope = null )
2424
2525
function DispatchParticleEffect( particleName, origin, angles, entity = null )
2626
{
27-
DoDispatchParticleEffect( particleName, origin, angles, entity );
27+
return DoDispatchParticleEffect( particleName, origin, angles, entity );
2828
}
2929
30+
function ImpulseScale( flTargetMass, flDesiredSpeed )
31+
{
32+
return flTargetMass * flDesiredSpeed;
33+
}
34+
__Documentation.RegisterHelp( "ImpulseScale", "float ImpulseScale(float, float)", "Returns an impulse scale required to push an object." );
35+
3036
)vscript";

sp/src/game/server/vscript_server.nut

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ function EntFireByHandle( target, action, value = null, delay = 0.0, activator =
6363
6464
function DispatchParticleEffect( particleName, origin, angles, entity = null )
6565
{
66-
DoDispatchParticleEffect( particleName, origin, angles, entity );
66+
return DoDispatchParticleEffect( particleName, origin, angles, entity );
6767
}
6868
69-
__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." );
69+
function ImpulseScale( flTargetMass, flDesiredSpeed )
70+
{
71+
return flTargetMass * flDesiredSpeed;
72+
}
73+
__Documentation.RegisterHelp( "ImpulseScale", "float ImpulseScale(float, float)", "Returns an impulse scale required to push an object." );
7074
7175
function __ReplaceClosures( script, scope )
7276
{

sp/src/game/shared/baseentity_shared.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,8 @@ void CBaseEntity::ScriptContextThink()
27372737
float flNextThink = FLT_MAX;
27382738
float flScheduled = 0.0f;
27392739

2740+
ScriptVariant_t arg = m_hScriptInstance;
2741+
27402742
for ( int i = 0; i < m_ScriptThinkFuncs.Count(); ++i )
27412743
{
27422744
scriptthinkfunc_t *cur = m_ScriptThinkFuncs[i];
@@ -2766,21 +2768,12 @@ void CBaseEntity::ScriptContextThink()
27662768
if ( !cur->m_bNoParam )
27672769
{
27682770
#endif
2769-
ScriptVariant_t arg = m_hScriptInstance;
2770-
if ( g_pScriptVM->ExecuteFunction( cur->m_hfnThink, &arg, 1, &varReturn, NULL, true ) == SCRIPT_ERROR )
2771-
{
2772-
cur->m_flNextThink = SCRIPT_NEVER_THINK;
2773-
continue;
2774-
}
2771+
g_pScriptVM->ExecuteFunction( cur->m_hfnThink, &arg, 1, &varReturn, NULL, true );
27752772
#ifndef CLIENT_DLL
27762773
}
27772774
else
27782775
{
2779-
if ( g_pScriptVM->ExecuteFunction( cur->m_hfnThink, NULL, 0, &varReturn, NULL, true ) == SCRIPT_ERROR )
2780-
{
2781-
cur->m_flNextThink = SCRIPT_NEVER_THINK;
2782-
continue;
2783-
}
2776+
g_pScriptVM->ExecuteFunction( cur->m_hfnThink, NULL, 0, &varReturn, NULL, true );
27842777
}
27852778
#endif
27862779

@@ -2793,6 +2786,7 @@ void CBaseEntity::ScriptContextThink()
27932786
float flReturn;
27942787
if ( !varReturn.AssignTo( &flReturn ) )
27952788
{
2789+
varReturn.Free();
27962790
cur->m_flNextThink = SCRIPT_NEVER_THINK;
27972791
continue;
27982792
}
@@ -2808,7 +2802,7 @@ void CBaseEntity::ScriptContextThink()
28082802
flNextThink = flReturn;
28092803
}
28102804

2811-
cur->m_flNextThink = gpGlobals->curtime + flReturn - 0.001;
2805+
cur->m_flNextThink = gpGlobals->curtime + flReturn - 0.001f;
28122806
}
28132807

28142808
// deferred safe removal

sp/src/game/shared/mapbase/vscript_funcs_shared.cpp

+2-13
Original file line numberDiff line numberDiff line change
@@ -679,16 +679,6 @@ static void AddPhysVelocity( HSCRIPT hPhys, const Vector& vecVelocity, const Vec
679679
//=============================================================================
680680
//=============================================================================
681681

682-
static int ScriptPrecacheModel( const char *modelname )
683-
{
684-
return CBaseEntity::PrecacheModel( modelname );
685-
}
686-
687-
static void ScriptPrecacheOther( const char *classname )
688-
{
689-
UTIL_PrecacheOther( classname );
690-
}
691-
692682
#ifndef CLIENT_DLL
693683
// TODO: Move this?
694684
static void ScriptInsertSound( int iType, const Vector &vecOrigin, int iVolume, float flDuration, HSCRIPT hOwner, int soundChannelIndex, HSCRIPT hSoundTarget )
@@ -873,7 +863,6 @@ void RegisterSharedScriptFunctions()
873863

874864
ScriptRegisterFunction( g_pScriptVM, CreateDamageInfo, "Creates damage info." );
875865
ScriptRegisterFunction( g_pScriptVM, DestroyDamageInfo, "Destroys damage info." );
876-
ScriptRegisterFunction( g_pScriptVM, ImpulseScale, "Returns an impulse scale required to push an object." );
877866
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalculateExplosiveDamageForce, "CalculateExplosiveDamageForce", "Fill out a damage info handle with a damage force for an explosive." );
878867
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalculateBulletDamageForce, "CalculateBulletDamageForce", "Fill out a damage info handle with a damage force for a bullet impact." );
879868
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalculateMeleeDamageForce, "CalculateMeleeDamageForce", "Fill out a damage info handle with a damage force for a melee impact." );
@@ -896,10 +885,10 @@ void RegisterSharedScriptFunctions()
896885
//
897886
// Precaching
898887
//
899-
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPrecacheModel, "PrecacheModel", "Precaches a model for later usage." );
888+
ScriptRegisterFunctionNamed( g_pScriptVM, CBaseEntity::PrecacheModel, "PrecacheModel", "Precaches a model for later usage." );
900889
ScriptRegisterFunction( g_pScriptVM, PrecacheMaterial, "Precaches a material for later usage." );
901890
ScriptRegisterFunction( g_pScriptVM, PrecacheParticleSystem, "Precaches a particle system for later usage." );
902-
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPrecacheOther, "PrecacheOther", "Precaches an entity class for later usage." );
891+
ScriptRegisterFunctionNamed( g_pScriptVM, UTIL_PrecacheOther, "PrecacheOther", "Precaches an entity class for later usage." );
903892

904893
//
905894
// NPCs

sp/src/game/shared/mapbase/vscript_singletons.cpp

+38-45
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "tier0/memdbgon.h"
4343

4444
extern IScriptManager *scriptmanager;
45-
CNetMsgScriptHelper *g_ScriptNetMsg = new CNetMsgScriptHelper();
4645

4746
//=============================================================================
4847
// Net Prop Manager
@@ -401,7 +400,7 @@ class CScriptGameEventListener : public IGameEventListener2, public CAutoGameSys
401400
//int m_nEventTick;
402401

403402
static StringHashFunctor Hash;
404-
static inline unsigned int HashContext( const char* c ) { return (c && *c) ? Hash(c) : 0; }
403+
static inline unsigned int HashContext( const char* c ) { return c ? Hash(c) : 0; }
405404

406405
inline int GetIndex()
407406
{
@@ -574,11 +573,10 @@ void CScriptGameEventListener::LoadEventsFromFile( const char *filename, const c
574573
void CScriptGameEventListener::DumpEventListeners()
575574
{
576575
CGMsg( 0, CON_GROUP_VSCRIPT, "--- Script game event listener dump start\n" );
577-
CGMsg( 0, CON_GROUP_VSCRIPT, "# ADDRESS ID CONTEXT\n" );
576+
CGMsg( 0, CON_GROUP_VSCRIPT, "# ID CONTEXT\n" );
578577
FOR_EACH_VEC( s_Listeners, i )
579578
{
580-
CGMsg( 0, CON_GROUP_VSCRIPT, " %d (0x%p) %d : %u\n", i,
581-
(void*)s_Listeners[i],
579+
CGMsg( 0, CON_GROUP_VSCRIPT, " %d : %d : %u\n", i,
582580
s_Listeners[i]->GetIndex(),
583581
s_Listeners[i]->m_iContextHash );
584582
}
@@ -755,14 +753,12 @@ bool CScriptGameEventListener::StopListeningToGameEvent( int listener )
755753
void CScriptGameEventListener::StopListeningToAllGameEvents( const char* szContext )
756754
{
757755
unsigned int hash = HashContext( szContext );
758-
759-
// Iterate from the end so they can be safely removed as they are deleted
760756
for ( int i = s_Listeners.Count(); i--; )
761757
{
762758
CScriptGameEventListener *pCur = s_Listeners[i];
763759
if ( pCur->m_iContextHash == hash )
764760
{
765-
s_Listeners.Remove(i); // keep list order
761+
s_Listeners.FastRemove(i);
766762
delete pCur;
767763
}
768764
}
@@ -1202,10 +1198,7 @@ HSCRIPT CScriptReadWriteFile::KeyValuesRead( const char *szFile )
12021198

12031199
return hScript;
12041200
}
1205-
#undef SCRIPT_MAX_FILE_READ_SIZE
1206-
#undef SCRIPT_MAX_FILE_WRITE_SIZE
1207-
#undef SCRIPT_RW_PATH_ID
1208-
#undef SCRIPT_RW_FULL_PATH_FMT
1201+
12091202

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

1211+
static CNetMsgScriptHelper scriptnetmsg;
1212+
CNetMsgScriptHelper *g_ScriptNetMsg = &scriptnetmsg;
12181213

12191214
#ifdef GAME_DLL
12201215
#define m_MsgIn_() m_MsgIn->
@@ -2181,23 +2176,23 @@ END_SCRIPTDESC();
21812176
//=============================================================================
21822177
// ConVars
21832178
//=============================================================================
2184-
class CScriptConCommand : public ICommandCallback, public ICommandCompletionCallback
2179+
class CScriptConCommand : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
21852180
{
2181+
typedef ConCommand BaseClass;
2182+
21862183
public:
21872184
~CScriptConCommand()
21882185
{
21892186
Unregister();
2190-
delete m_pBase;
21912187
}
21922188

21932189
CScriptConCommand( const char *name, HSCRIPT fn, const char *helpString, int flags, ConCommand *pLinked = NULL )
2190+
: BaseClass( name, this, helpString, flags, 0 ),
2191+
m_pLinked(pLinked),
2192+
m_hCallback(fn),
2193+
m_hCompletionCallback(NULL)
21942194
{
2195-
m_pBase = new ConCommand( name, this, helpString, flags, 0 );
2196-
m_pLinked = pLinked;
2197-
m_hCallback = fn;
2198-
m_hCompletionCallback = NULL;
21992195
m_nCmdNameLen = V_strlen(name) + 1;
2200-
22012196
Assert( m_nCmdNameLen - 1 <= 128 );
22022197
}
22032198

@@ -2272,17 +2267,17 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
22722267

22732268
if (fn)
22742269
{
2275-
if ( !m_pBase->IsRegistered() )
2270+
if ( !BaseClass::IsRegistered() )
22762271
return;
22772272

2278-
m_pBase->m_pCommandCompletionCallback = this;
2279-
m_pBase->m_bHasCompletionCallback = true;
2273+
BaseClass::m_pCommandCompletionCallback = this;
2274+
BaseClass::m_bHasCompletionCallback = true;
22802275
m_hCompletionCallback = fn;
22812276
}
22822277
else
22832278
{
2284-
m_pBase->m_pCommandCompletionCallback = NULL;
2285-
m_pBase->m_bHasCompletionCallback = false;
2279+
BaseClass::m_pCommandCompletionCallback = NULL;
2280+
BaseClass::m_bHasCompletionCallback = false;
22862281
m_hCompletionCallback = NULL;
22872282
}
22882283
}
@@ -2291,7 +2286,7 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
22912286
{
22922287
if (fn)
22932288
{
2294-
if ( !m_pBase->IsRegistered() )
2289+
if ( !BaseClass::IsRegistered() )
22952290
Register();
22962291

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

23072302
inline void Unregister()
23082303
{
2309-
if ( g_pCVar && m_pBase->IsRegistered() )
2310-
g_pCVar->UnregisterConCommand( m_pBase );
2304+
if ( g_pCVar && BaseClass::IsRegistered() )
2305+
g_pCVar->UnregisterConCommand( this );
23112306

23122307
if ( g_pScriptVM )
23132308
{
@@ -2324,30 +2319,29 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
23242319
inline void Register()
23252320
{
23262321
if ( g_pCVar )
2327-
g_pCVar->RegisterConCommand( m_pBase );
2322+
g_pCVar->RegisterConCommand( this );
23282323
}
23292324

23302325
HSCRIPT m_hCallback;
2326+
ConCommand *m_pLinked;
23312327
HSCRIPT m_hCompletionCallback;
23322328
int m_nCmdNameLen;
2333-
ConCommand *m_pLinked;
2334-
ConCommand *m_pBase;
23352329
};
23362330

2337-
class CScriptConVar
2331+
class CScriptConVar : public ConVar
23382332
{
2333+
typedef ConVar BaseClass;
2334+
23392335
public:
23402336
~CScriptConVar()
23412337
{
23422338
Unregister();
2343-
delete m_pBase;
23442339
}
23452340

23462341
CScriptConVar( const char *pName, const char *pDefaultValue, const char *pHelpString, int flags/*, float fMin, float fMax*/ )
2347-
{
2348-
m_pBase = new ConVar( pName, pDefaultValue, flags, pHelpString );
2349-
m_hCallback = NULL;
2350-
}
2342+
: BaseClass( pName, pDefaultValue, flags, pHelpString ),
2343+
m_hCallback(NULL)
2344+
{}
23512345

23522346
void SetChangeCallback( HSCRIPT fn )
23532347
{
@@ -2359,19 +2353,19 @@ class CScriptConVar
23592353
if (fn)
23602354
{
23612355
m_hCallback = fn;
2362-
m_pBase->InstallChangeCallback( (FnChangeCallback_t)ScriptConVarCallback );
2356+
BaseClass::InstallChangeCallback( (FnChangeCallback_t)ScriptConVarCallback );
23632357
}
23642358
else
23652359
{
23662360
m_hCallback = NULL;
2367-
m_pBase->InstallChangeCallback( NULL );
2361+
BaseClass::InstallChangeCallback( NULL );
23682362
}
23692363
}
23702364

23712365
inline void Unregister()
23722366
{
2373-
if ( g_pCVar && m_pBase->IsRegistered() )
2374-
g_pCVar->UnregisterConCommand( m_pBase );
2367+
if ( g_pCVar && BaseClass::IsRegistered() )
2368+
g_pCVar->UnregisterConCommand( this );
23752369

23762370
if ( g_pScriptVM )
23772371
{
@@ -2380,7 +2374,6 @@ class CScriptConVar
23802374
}
23812375

23822376
HSCRIPT m_hCallback;
2383-
ConVar *m_pBase;
23842377
};
23852378

23862379
static CUtlMap< unsigned int, bool > g_ConVarsBlocked( DefLessFunc(unsigned int) );
@@ -2541,8 +2534,8 @@ void CScriptConvarAccessor::RegisterCommand( const char *name, HSCRIPT fn, const
25412534
int idx = g_ScriptConCommands.Find(hash);
25422535
if ( idx == g_ScriptConCommands.InvalidIndex() )
25432536
{
2544-
ConCommand *pLinked = NULL;
2545-
if ( g_pCVar->FindVar(name) || ( ((pLinked = g_pCVar->FindCommand(name)) != NULL) && !IsOverridable(hash) ) )
2537+
ConCommandBase *pBase = g_pCVar->FindCommandBase(name);
2538+
if ( pBase && ( !pBase->IsCommand() || !IsOverridable(hash) ) )
25462539
{
25472540
DevWarning( 1, "CScriptConvarAccessor::RegisterCommand unable to register blocked ConCommand: %s\n", name );
25482541
return;
@@ -2551,7 +2544,7 @@ void CScriptConvarAccessor::RegisterCommand( const char *name, HSCRIPT fn, const
25512544
if ( !fn )
25522545
return;
25532546

2554-
CScriptConCommand *p = new CScriptConCommand( name, fn, helpString, flags, pLinked );
2547+
CScriptConCommand *p = new CScriptConCommand( name, fn, helpString, flags, static_cast< ConCommand* >(pBase) );
25552548
g_ScriptConCommands.Insert( hash, p );
25562549
}
25572550
else
@@ -2589,7 +2582,7 @@ void CScriptConvarAccessor::RegisterConvar( const char *name, const char *pDefau
25892582
int idx = g_ScriptConVars.Find(hash);
25902583
if ( idx == g_ScriptConVars.InvalidIndex() )
25912584
{
2592-
if ( g_pCVar->FindVar(name) || g_pCVar->FindCommand(name) )
2585+
if ( g_pCVar->FindCommandBase(name) )
25932586
{
25942587
DevWarning( 1, "CScriptConvarAccessor::RegisterConvar unable to register blocked ConCommand: %s\n", name );
25952588
return;

0 commit comments

Comments
 (0)