Register CScriptGameTrace accessor script instances only on access

This commit is contained in:
samisalreadytaken 2024-11-20 15:19:57 +03:00
parent 4e68a35149
commit 2fd480704c
2 changed files with 23 additions and 22 deletions

View File

@ -381,9 +381,6 @@ static HSCRIPT_RC ScriptTraceLineComplex( const Vector &vecStart, const Vector &
CBaseEntity *pIgnore = ToEnt( entIgnore );
UTIL_TraceLine( vecStart, vecEnd, iMask, pIgnore, iCollisionGroup, tr );
tr->RegisterSurface();
tr->RegisterPlane();
return g_pScriptVM->RegisterInstance( tr, true );
}
@ -395,9 +392,6 @@ static HSCRIPT_RC ScriptTraceHullComplex( const Vector &vecStart, const Vector &
CBaseEntity *pIgnore = ToEnt( entIgnore );
UTIL_TraceHull( vecStart, vecEnd, hullMin, hullMax, iMask, pIgnore, iCollisionGroup, tr );
tr->RegisterSurface();
tr->RegisterPlane();
return g_pScriptVM->RegisterInstance( tr, true );
}

View File

@ -46,12 +46,14 @@ public:
class CSurfaceScriptHelper
{
public:
// This class is owned by CScriptGameTrace, and cannot be accessed without being initialised in CScriptGameTrace::RegisterSurface()
//CSurfaceScriptHelper() : m_pSurface(NULL), m_hSurfaceData(NULL) {}
CSurfaceScriptHelper() : m_pSurface(NULL), m_hSurfaceData(NULL) {}
~CSurfaceScriptHelper()
{
g_pScriptVM->RemoveInstance( m_hSurfaceData );
if ( m_hSurfaceData )
{
g_pScriptVM->RemoveInstance( m_hSurfaceData );
}
}
void Init( csurface_t *surf )
@ -113,17 +115,6 @@ public:
}
}
void RegisterSurface()
{
m_surfaceHelper.Init( &surface );
m_surfaceAccessor = g_pScriptVM->RegisterInstance( &m_surfaceHelper );
}
void RegisterPlane()
{
m_planeAccessor = g_pScriptVM->RegisterInstance( &plane );
}
public:
float FractionLeftSolid() const { return fractionleftsolid; }
int HitGroup() const { return hitgroup; }
@ -143,8 +134,24 @@ public:
bool AllSolid() const { return allsolid; }
bool StartSolid() const { return startsolid; }
HSCRIPT Surface() const { return m_surfaceAccessor; }
HSCRIPT Plane() const { return m_planeAccessor; }
HSCRIPT Surface()
{
if ( !m_surfaceAccessor )
{
m_surfaceHelper.Init( &surface );
m_surfaceAccessor = g_pScriptVM->RegisterInstance( &m_surfaceHelper );
}
return m_surfaceAccessor;
}
HSCRIPT Plane()
{
if ( !m_planeAccessor )
m_planeAccessor = g_pScriptVM->RegisterInstance( &plane );
return m_planeAccessor;
}
void Destroy() {}