Skip to content

Commit 2dbaa2c

Browse files
authored
Merge pull request #5 from ReDucTor/wip/vscript_support
WIP: vscript support
2 parents af85131 + 1210dee commit 2dbaa2c

206 files changed

Lines changed: 33799 additions & 135 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sp/src/game/client/c_baseanimating.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ BEGIN_DATADESC( C_ClientRagdoll )
281281

282282
END_DATADESC()
283283

284+
BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-side" )
285+
DEFINE_SCRIPTFUNC_NAMED( ScriptSetPoseParameter, "SetPoseParameter", "Set the specified pose parameter to the specified value" )
286+
DEFINE_SCRIPTFUNC( IsSequenceFinished, "Ask whether the main sequence is done playing" )
287+
END_SCRIPTDESC();
288+
284289
C_ClientRagdoll::C_ClientRagdoll( bool bRestoring )
285290
{
286291
m_iCurrentFriction = 0;
@@ -1403,6 +1408,15 @@ float C_BaseAnimating::ClampCycle( float flCycle, bool isLooping )
14031408
return flCycle;
14041409
}
14051410

1411+
void C_BaseAnimating::ScriptSetPoseParameter(const char* szName, float fValue)
1412+
{
1413+
CStudioHdr* pHdr = GetModelPtr();
1414+
if (pHdr == NULL)
1415+
return;
1416+
1417+
int iPoseParam = LookupPoseParameter(pHdr, szName);
1418+
SetPoseParameter(pHdr, iPoseParam, fValue);
1419+
}
14061420

14071421
void C_BaseAnimating::GetCachedBoneMatrix( int boneIndex, matrix3x4_t &out )
14081422
{

sp/src/game/client/c_baseanimating.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
9595
DECLARE_CLIENTCLASS();
9696
DECLARE_PREDICTABLE();
9797
DECLARE_INTERPOLATION();
98+
DECLARE_ENT_SCRIPTDESC();
9899

99100
enum
100101
{
@@ -445,6 +446,7 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
445446

446447
virtual bool IsViewModel() const;
447448

449+
void ScriptSetPoseParameter(const char* szName, float fValue);
448450
protected:
449451
// View models scale their attachment positions to account for FOV. To get the unmodified
450452
// attachment position (like if you're rendering something else during the view model's DrawModel call),

sp/src/game/client/c_baseentity.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "viewrender.h"
4545
#endif
4646

47+
#include "gamestringpool.h"
48+
4749
// memdbgon must be the last include file in a .cpp file!!!
4850
#include "tier0/memdbgon.h"
4951

@@ -423,6 +425,13 @@ BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_AnimTimeMustBeFirst )
423425
RecvPropInt( RECVINFO(m_flAnimTime), 0, RecvProxy_AnimTime ),
424426
END_RECV_TABLE()
425427

428+
BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities" )
429+
DEFINE_SCRIPTFUNC_NAMED( GetAbsOrigin, "GetOrigin", "" )
430+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetForward, "GetForwardVector", "Get the forward vector of the entity" )
431+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetLeft, "GetLeftVector", "Get the left vector of the entity" )
432+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetUp, "GetUpVector", "Get the up vector of the entity" )
433+
DEFINE_SCRIPTFUNC( GetTeamNumber, "Gets this entity's team" )
434+
END_SCRIPTDESC();
426435

427436
#ifndef NO_ENTITY_PREDICTION
428437
BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_PredictableId )
@@ -466,6 +475,8 @@ BEGIN_RECV_TABLE_NOBASE(C_BaseEntity, DT_BaseEntity)
466475
RecvPropInt( RECVINFO_NAME(m_hNetworkMoveParent, moveparent), 0, RecvProxy_IntToMoveParent ),
467476
RecvPropInt( RECVINFO( m_iParentAttachment ) ),
468477

478+
RecvPropString(RECVINFO(m_iName)),
479+
469480
RecvPropInt( "movetype", 0, SIZEOF_IGNORE, 0, RecvProxy_MoveType ),
470481
RecvPropInt( "movecollide", 0, SIZEOF_IGNORE, 0, RecvProxy_MoveCollide ),
471482
RecvPropDataTable( RECVINFO_DT( m_Collision ), 0, &REFERENCE_RECV_TABLE(DT_CollisionProperty) ),
@@ -1095,6 +1106,8 @@ bool C_BaseEntity::Init( int entnum, int iSerialNum )
10951106

10961107
m_nCreationTick = gpGlobals->tickcount;
10971108

1109+
m_hScriptInstance = NULL;
1110+
10981111
return true;
10991112
}
11001113

@@ -1165,6 +1178,7 @@ void C_BaseEntity::Term()
11651178
g_Predictables.RemoveFromPredictablesList( GetClientHandle() );
11661179
}
11671180

1181+
11681182
// If it's play simulated, remove from simulation list if the player still exists...
11691183
if ( IsPlayerSimulated() && C_BasePlayer::GetLocalPlayer() )
11701184
{
@@ -1201,6 +1215,12 @@ void C_BaseEntity::Term()
12011215
RemoveFromLeafSystem();
12021216

12031217
RemoveFromAimEntsList();
1218+
1219+
if ( m_hScriptInstance )
1220+
{
1221+
g_pScriptVM->RemoveInstance( m_hScriptInstance );
1222+
m_hScriptInstance = NULL;
1223+
}
12041224
}
12051225

12061226

@@ -6442,6 +6462,26 @@ int C_BaseEntity::GetCreationTick() const
64426462
return m_nCreationTick;
64436463
}
64446464

6465+
//-----------------------------------------------------------------------------
6466+
//
6467+
//-----------------------------------------------------------------------------
6468+
HSCRIPT C_BaseEntity::GetScriptInstance()
6469+
{
6470+
if (!m_hScriptInstance)
6471+
{
6472+
if (m_iszScriptId == NULL_STRING)
6473+
{
6474+
char* szName = (char*)stackalloc(1024);
6475+
g_pScriptVM->GenerateUniqueKey((m_iName != NULL_STRING) ? STRING(GetEntityName()) : GetClassname(), szName, 1024);
6476+
m_iszScriptId = AllocPooledString(szName);
6477+
}
6478+
6479+
m_hScriptInstance = g_pScriptVM->RegisterInstance(GetScriptDesc(), this);
6480+
g_pScriptVM->SetInstanceUniqeId(m_hScriptInstance, STRING(m_iszScriptId));
6481+
}
6482+
return m_hScriptInstance;
6483+
}
6484+
64456485
//------------------------------------------------------------------------------
64466486
void CC_CL_Find_Ent( const CCommand& args )
64476487
{

sp/src/game/client/c_baseentity.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include "toolframework/itoolentity.h"
3737
#include "tier0/threadtools.h"
3838

39+
#include "vscript/ivscript.h"
40+
#include "vscript_shared.h"
41+
3942
class C_Team;
4043
class IPhysicsObject;
4144
class IClientVehicle;
@@ -183,6 +186,8 @@ class C_BaseEntity : public IClientEntity
183186
DECLARE_DATADESC();
184187
DECLARE_CLIENTCLASS();
185188
DECLARE_PREDICTABLE();
189+
// script description
190+
DECLARE_ENT_SCRIPTDESC();
186191

187192
C_BaseEntity();
188193
virtual ~C_BaseEntity();
@@ -256,6 +261,11 @@ class C_BaseEntity : public IClientEntity
256261

257262
string_t m_iClassname;
258263

264+
HSCRIPT GetScriptInstance();
265+
266+
HSCRIPT m_hScriptInstance;
267+
string_t m_iszScriptId;
268+
259269
// IClientUnknown overrides.
260270
public:
261271

@@ -1119,6 +1129,10 @@ class C_BaseEntity : public IClientEntity
11191129
virtual int GetBody() { return 0; }
11201130
virtual int GetSkin() { return 0; }
11211131

1132+
const Vector& ScriptGetForward(void) { static Vector vecForward; GetVectors(&vecForward, NULL, NULL); return vecForward; }
1133+
const Vector& ScriptGetLeft(void) { static Vector vecLeft; GetVectors(NULL, &vecLeft, NULL); return vecLeft; }
1134+
const Vector& ScriptGetUp(void) { static Vector vecUp; GetVectors(NULL, NULL, &vecUp); return vecUp; }
1135+
11221136
// Stubs on client
11231137
void NetworkStateManualMode( bool activate ) { }
11241138
void NetworkStateChanged() { }
@@ -1266,6 +1280,7 @@ class C_BaseEntity : public IClientEntity
12661280
void SetRenderMode( RenderMode_t nRenderMode, bool bForceUpdate = false );
12671281
RenderMode_t GetRenderMode() const;
12681282

1283+
const char* GetEntityName();
12691284
public:
12701285

12711286
// Determine what entity this corresponds to
@@ -1648,6 +1663,8 @@ class C_BaseEntity : public IClientEntity
16481663
// The owner!
16491664
EHANDLE m_hOwnerEntity;
16501665
EHANDLE m_hEffectEntity;
1666+
1667+
char m_iName[MAX_PATH];
16511668

16521669
// This is a random seed used by the networking code to allow client - side prediction code
16531670
// randon number generators to spit out the same random numbers on both sides for a particular
@@ -2203,6 +2220,12 @@ inline bool C_BaseEntity::ShouldRecordInTools() const
22032220
#endif
22042221
}
22052222

2223+
inline const char *C_BaseEntity::GetEntityName()
2224+
{
2225+
return m_iName;
2226+
}
2227+
2228+
22062229
C_BaseEntity *CreateEntityByName( const char *className );
22072230

22082231
#endif // C_BASEENTITY_H

sp/src/game/client/c_baseflex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ bool C_BaseFlex::ClearSceneEvent( CSceneEventInfo *info, bool fastKill, bool can
14801480
// expression -
14811481
// duration -
14821482
//-----------------------------------------------------------------------------
1483-
void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseEntity *pTarget, bool bClientSide )
1483+
void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseEntity *pTarget, bool bClientSide, C_SceneEntity* pSceneEntity)
14841484
{
14851485
if ( !scene || !event )
14861486
{
@@ -1505,6 +1505,7 @@ void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseE
15051505
info.m_hTarget = pTarget;
15061506
info.m_bStarted = false;
15071507
info.m_bClientSide = bClientSide;
1508+
info.m_hSceneEntity = pSceneEntity;
15081509

15091510
if (StartSceneEvent( &info, scene, event, actor, pTarget ))
15101511
{

sp/src/game/client/c_baseflex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class C_BaseFlex : public C_BaseAnimatingOverlay, public IHasLocalToGlobalFlexSe
214214
virtual bool ClearSceneEvent( CSceneEventInfo *info, bool fastKill, bool canceled );
215215

216216
// Add the event to the queue for this actor
217-
void AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, C_BaseEntity *pTarget = NULL, bool bClientSide = false );
217+
void AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, C_BaseEntity *pTarget = NULL, bool bClientSide = false, C_SceneEntity* pSceneEntity = NULL);
218218

219219
// Remove the event from the queue for this actor
220220
void RemoveSceneEvent( CChoreoScene *scene, CChoreoEvent *event, bool fastKill );

sp/src/game/client/c_sceneentity.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ void C_SceneEntity::DispatchStartSpeak( CChoreoScene *scene, C_BaseFlex *actor,
674674
es.m_pSoundName = event->GetParameters();
675675

676676
EmitSound( filter, actor->entindex(), es );
677-
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
677+
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
678678

679679
// Close captioning only on master token no matter what...
680680
if ( event->GetCloseCaptionType() == CChoreoEvent::CC_MASTER )
@@ -964,7 +964,7 @@ void C_SceneEntity::UnloadScene( void )
964964
//-----------------------------------------------------------------------------
965965
void C_SceneEntity::DispatchStartFlexAnimation( CChoreoScene *scene, C_BaseFlex *actor, CChoreoEvent *event )
966966
{
967-
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
967+
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
968968
}
969969

970970
//-----------------------------------------------------------------------------
@@ -984,7 +984,7 @@ void C_SceneEntity::DispatchEndFlexAnimation( CChoreoScene *scene, C_BaseFlex *a
984984
//-----------------------------------------------------------------------------
985985
void C_SceneEntity::DispatchStartExpression( CChoreoScene *scene, C_BaseFlex *actor, CChoreoEvent *event )
986986
{
987-
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
987+
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
988988
}
989989

990990
//-----------------------------------------------------------------------------
@@ -1008,7 +1008,7 @@ void C_SceneEntity::DispatchStartGesture( CChoreoScene *scene, C_BaseFlex *actor
10081008
if ( !Q_stricmp( event->GetName(), "NULL" ) )
10091009
return;
10101010

1011-
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
1011+
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
10121012
}
10131013

10141014
//-----------------------------------------------------------------------------
@@ -1023,7 +1023,7 @@ void C_SceneEntity::DispatchProcessGesture( CChoreoScene *scene, C_BaseFlex *act
10231023
return;
10241024

10251025
actor->RemoveSceneEvent( scene, event, false );
1026-
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
1026+
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
10271027
}
10281028

10291029
//-----------------------------------------------------------------------------
@@ -1046,7 +1046,7 @@ void C_SceneEntity::DispatchEndGesture( CChoreoScene *scene, C_BaseFlex *actor,
10461046
//-----------------------------------------------------------------------------
10471047
void C_SceneEntity::DispatchStartSequence( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event )
10481048
{
1049-
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
1049+
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
10501050
}
10511051

10521052
//-----------------------------------------------------------------------------
@@ -1056,7 +1056,7 @@ void C_SceneEntity::DispatchStartSequence( CChoreoScene *scene, CBaseFlex *actor
10561056
void C_SceneEntity::DispatchProcessSequence( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event )
10571057
{
10581058
actor->RemoveSceneEvent( scene, event, false );
1059-
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
1059+
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
10601060
}
10611061

10621062
//-----------------------------------------------------------------------------

sp/src/game/client/cdll_client_int.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ IReplaySystem *g_pReplay = NULL;
223223
IVEngineServer *serverengine = NULL;
224224
#endif
225225

226+
IScriptManager *scriptmanager = NULL;
227+
226228
IHaptics* haptics = NULL;// NVNT haptics system interface singleton
227229

228230
//=============================================================================
@@ -964,6 +966,16 @@ int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physi
964966
if (!g_pMatSystemSurface)
965967
return false;
966968

969+
if ( !CommandLine()->CheckParm( "-noscripting") )
970+
{
971+
scriptmanager = (IScriptManager *)appSystemFactory( VSCRIPT_INTERFACE_VERSION, NULL );
972+
973+
if (scriptmanager == nullptr)
974+
{
975+
scriptmanager = (IScriptManager*)Sys_GetFactoryThis()(VSCRIPT_INTERFACE_VERSION, NULL);
976+
}
977+
}
978+
967979
#ifdef WORKSHOP_IMPORT_ENABLED
968980
if ( !ConnectDataModel( appSystemFactory ) )
969981
return false;

sp/src/game/client/client_base.vpc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ $Project
493493
$File "viewrender.cpp"
494494
$File "$SRCDIR\game\shared\voice_banmgr.cpp"
495495
$File "$SRCDIR\game\shared\voice_status.cpp"
496+
$File "vscript_client.cpp"
497+
$File "vscript_client.h"
498+
$File "vscript_client.nut"
499+
$File "$SRCDIR\game\shared\vscript_shared.cpp"
500+
$File "$SRCDIR\game\shared\vscript_shared.h"
496501
$File "warp_overlay.cpp"
497502
$File "WaterLODMaterialProxy.cpp"
498503
$File "$SRCDIR\game\shared\weapon_parse.cpp"

sp/src/game/client/client_mapbase.vpc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ $Configuration
1111
$PreprocessorDefinitions "$BASE;ASW_PROJECTED_TEXTURES;DYNAMIC_RTT_SHADOWS"
1212

1313
$PreprocessorDefinitions "$BASE;MAPBASE_RPC;DISCORD_RPC;STEAM_RPC" [$MAPBASE_RPC]
14+
15+
$PreprocessorDefinitions "$BASE;MAPBASE_VSCRIPT" [$MAPBASE_VSCRIPT]
1416
}
1517
}
1618

@@ -51,4 +53,9 @@ $Project
5153
}
5254
}
5355
}
56+
57+
$Folder "Link Libraries"
58+
{
59+
$Lib "vscript" [$MAPBASE_VSCRIPT]
60+
}
5461
}

0 commit comments

Comments
 (0)