From 57848d7e3bfd860dbee165b2ad1e35787f12bbc4 Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Sun, 12 Jul 2020 11:46:43 +1000 Subject: [PATCH] Making vscript register all classes --- sp/src/game/client/vscript_client.cpp | 2 ++ sp/src/game/server/vscript_server.cpp | 2 ++ sp/src/public/vscript/ivscript.h | 25 ++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sp/src/game/client/vscript_client.cpp b/sp/src/game/client/vscript_client.cpp index 29b998f8..cc573c3a 100644 --- a/sp/src/game/client/vscript_client.cpp +++ b/sp/src/game/client/vscript_client.cpp @@ -487,6 +487,8 @@ bool VScriptClientInit() } #ifdef MAPBASE_VSCRIPT + g_pScriptVM->RegisterAllClasses(); + g_pScriptVM->RegisterInstance( &g_ScriptEntityIterator, "Entities" ); IGameSystem::RegisterVScriptAllSystems(); diff --git a/sp/src/game/server/vscript_server.cpp b/sp/src/game/server/vscript_server.cpp index a0c87f93..a298c268 100644 --- a/sp/src/game/server/vscript_server.cpp +++ b/sp/src/game/server/vscript_server.cpp @@ -569,6 +569,8 @@ bool VScriptServerInit() g_pScriptVM->RegisterInstance( &g_ScriptEntityIterator, "Entities" ); #ifdef MAPBASE_VSCRIPT + g_pScriptVM->RegisterAllClasses(); + IGameSystem::RegisterVScriptAllSystems(); RegisterSharedScriptFunctions(); diff --git a/sp/src/public/vscript/ivscript.h b/sp/src/public/vscript/ivscript.h index 3526f468..390f80cf 100644 --- a/sp/src/public/vscript/ivscript.h +++ b/sp/src/public/vscript/ivscript.h @@ -297,7 +297,12 @@ public: struct ScriptClassDesc_t { - ScriptClassDesc_t() : m_pszScriptName( 0 ), m_pszClassname( 0 ), m_pszDescription( 0 ), m_pBaseDesc( 0 ), m_pfnConstruct( 0 ), m_pfnDestruct( 0 ), pHelper(NULL) {} + ScriptClassDesc_t() : m_pszScriptName( 0 ), m_pszClassname( 0 ), m_pszDescription( 0 ), m_pBaseDesc( 0 ), m_pfnConstruct( 0 ), m_pfnDestruct( 0 ), pHelper(NULL) + { +#ifdef MAPBASE_VSCRIPT + AllClassesDesc().AddToTail(this); +#endif + } const char * m_pszScriptName; const char * m_pszClassname; @@ -308,6 +313,14 @@ struct ScriptClassDesc_t void *(*m_pfnConstruct)(); void (*m_pfnDestruct)( void *); IScriptInstanceHelper * pHelper; // optional helper + +#ifdef MAPBASE_VSCRIPT + static CUtlVector& AllClassesDesc() + { + static CUtlVector classes; + return classes; + } +#endif }; //--------------------------------------------------------- @@ -875,6 +888,16 @@ public: return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait ); } +#ifdef MAPBASE_VSCRIPT + void RegisterAllClasses() + { + CUtlVector& classDescs = ScriptClassDesc_t::AllClassesDesc(); + FOR_EACH_VEC(classDescs, i) + { + RegisterClass(classDescs[i]); + } + } +#endif };