Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: vscript support #5

Merged
merged 10 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sp/src/game/client/c_baseanimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ BEGIN_DATADESC( C_ClientRagdoll )

END_DATADESC()

BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-side" )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetPoseParameter, "SetPoseParameter", "Set the specified pose parameter to the specified value" )
DEFINE_SCRIPTFUNC( IsSequenceFinished, "Ask whether the main sequence is done playing" )
END_SCRIPTDESC();

C_ClientRagdoll::C_ClientRagdoll( bool bRestoring )
{
m_iCurrentFriction = 0;
Expand Down Expand Up @@ -1403,6 +1408,15 @@ float C_BaseAnimating::ClampCycle( float flCycle, bool isLooping )
return flCycle;
}

void C_BaseAnimating::ScriptSetPoseParameter(const char* szName, float fValue)
{
CStudioHdr* pHdr = GetModelPtr();
if (pHdr == NULL)
return;

int iPoseParam = LookupPoseParameter(pHdr, szName);
SetPoseParameter(pHdr, iPoseParam, fValue);
}

void C_BaseAnimating::GetCachedBoneMatrix( int boneIndex, matrix3x4_t &out )
{
Expand Down
2 changes: 2 additions & 0 deletions sp/src/game/client/c_baseanimating.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
DECLARE_CLIENTCLASS();
DECLARE_PREDICTABLE();
DECLARE_INTERPOLATION();
DECLARE_ENT_SCRIPTDESC();

enum
{
Expand Down Expand Up @@ -445,6 +446,7 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback

virtual bool IsViewModel() const;

void ScriptSetPoseParameter(const char* szName, float fValue);
protected:
// View models scale their attachment positions to account for FOV. To get the unmodified
// attachment position (like if you're rendering something else during the view model's DrawModel call),
Expand Down
38 changes: 38 additions & 0 deletions sp/src/game/client/c_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "viewrender.h"
#endif

#include "gamestringpool.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

Expand Down Expand Up @@ -423,6 +425,13 @@ BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_AnimTimeMustBeFirst )
RecvPropInt( RECVINFO(m_flAnimTime), 0, RecvProxy_AnimTime ),
END_RECV_TABLE()

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

#ifndef NO_ENTITY_PREDICTION
BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_PredictableId )
Expand Down Expand Up @@ -466,6 +475,8 @@ BEGIN_RECV_TABLE_NOBASE(C_BaseEntity, DT_BaseEntity)
RecvPropInt( RECVINFO_NAME(m_hNetworkMoveParent, moveparent), 0, RecvProxy_IntToMoveParent ),
RecvPropInt( RECVINFO( m_iParentAttachment ) ),

RecvPropString(RECVINFO(m_iName)),

RecvPropInt( "movetype", 0, SIZEOF_IGNORE, 0, RecvProxy_MoveType ),
RecvPropInt( "movecollide", 0, SIZEOF_IGNORE, 0, RecvProxy_MoveCollide ),
RecvPropDataTable( RECVINFO_DT( m_Collision ), 0, &REFERENCE_RECV_TABLE(DT_CollisionProperty) ),
Expand Down Expand Up @@ -1165,6 +1176,7 @@ void C_BaseEntity::Term()
g_Predictables.RemoveFromPredictablesList( GetClientHandle() );
}


// If it's play simulated, remove from simulation list if the player still exists...
if ( IsPlayerSimulated() && C_BasePlayer::GetLocalPlayer() )
{
Expand Down Expand Up @@ -1201,6 +1213,12 @@ void C_BaseEntity::Term()
RemoveFromLeafSystem();

RemoveFromAimEntsList();

if ( m_hScriptInstance )
{
g_pScriptVM->RemoveInstance( m_hScriptInstance );
m_hScriptInstance = NULL;
}
}


Expand Down Expand Up @@ -6442,6 +6460,26 @@ int C_BaseEntity::GetCreationTick() const
return m_nCreationTick;
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
HSCRIPT C_BaseEntity::GetScriptInstance()
{
if (!m_hScriptInstance)
{
if (m_iszScriptId == NULL_STRING)
{
char* szName = (char*)stackalloc(1024);
g_pScriptVM->GenerateUniqueKey((m_iName != NULL_STRING) ? STRING(GetEntityName()) : GetClassname(), szName, 1024);
m_iszScriptId = AllocPooledString(szName);
}

m_hScriptInstance = g_pScriptVM->RegisterInstance(GetScriptDesc(), this);
g_pScriptVM->SetInstanceUniqeId(m_hScriptInstance, STRING(m_iszScriptId));
}
return m_hScriptInstance;
}

//------------------------------------------------------------------------------
void CC_CL_Find_Ent( const CCommand& args )
{
Expand Down
23 changes: 23 additions & 0 deletions sp/src/game/client/c_baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include "toolframework/itoolentity.h"
#include "tier0/threadtools.h"

#include "vscript/ivscript.h"
#include "vscript_shared.h"

class C_Team;
class IPhysicsObject;
class IClientVehicle;
Expand Down Expand Up @@ -183,6 +186,8 @@ class C_BaseEntity : public IClientEntity
DECLARE_DATADESC();
DECLARE_CLIENTCLASS();
DECLARE_PREDICTABLE();
// script description
DECLARE_ENT_SCRIPTDESC();

C_BaseEntity();
virtual ~C_BaseEntity();
Expand Down Expand Up @@ -256,6 +261,11 @@ class C_BaseEntity : public IClientEntity

string_t m_iClassname;

HSCRIPT GetScriptInstance();

HSCRIPT m_hScriptInstance;
string_t m_iszScriptId;

// IClientUnknown overrides.
public:

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

const Vector& ScriptGetForward(void) { static Vector vecForward; GetVectors(&vecForward, NULL, NULL); return vecForward; }
const Vector& ScriptGetLeft(void) { static Vector vecLeft; GetVectors(NULL, &vecLeft, NULL); return vecLeft; }
const Vector& ScriptGetUp(void) { static Vector vecUp; GetVectors(NULL, NULL, &vecUp); return vecUp; }

// Stubs on client
void NetworkStateManualMode( bool activate ) { }
void NetworkStateChanged() { }
Expand Down Expand Up @@ -1266,6 +1280,7 @@ class C_BaseEntity : public IClientEntity
void SetRenderMode( RenderMode_t nRenderMode, bool bForceUpdate = false );
RenderMode_t GetRenderMode() const;

const char* GetEntityName();
public:

// Determine what entity this corresponds to
Expand Down Expand Up @@ -1648,6 +1663,8 @@ class C_BaseEntity : public IClientEntity
// The owner!
EHANDLE m_hOwnerEntity;
EHANDLE m_hEffectEntity;

char m_iName[MAX_PATH];

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

inline const char *C_BaseEntity::GetEntityName()
{
return m_iName;
}


C_BaseEntity *CreateEntityByName( const char *className );

#endif // C_BASEENTITY_H
3 changes: 2 additions & 1 deletion sp/src/game/client/c_baseflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ bool C_BaseFlex::ClearSceneEvent( CSceneEventInfo *info, bool fastKill, bool can
// expression -
// duration -
//-----------------------------------------------------------------------------
void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseEntity *pTarget, bool bClientSide )
void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseEntity *pTarget, bool bClientSide, C_SceneEntity* pSceneEntity)
{
if ( !scene || !event )
{
Expand All @@ -1505,6 +1505,7 @@ void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseE
info.m_hTarget = pTarget;
info.m_bStarted = false;
info.m_bClientSide = bClientSide;
info.m_hSceneEntity = pSceneEntity;

if (StartSceneEvent( &info, scene, event, actor, pTarget ))
{
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/client/c_baseflex.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class C_BaseFlex : public C_BaseAnimatingOverlay, public IHasLocalToGlobalFlexSe
virtual bool ClearSceneEvent( CSceneEventInfo *info, bool fastKill, bool canceled );

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

// Remove the event from the queue for this actor
void RemoveSceneEvent( CChoreoScene *scene, CChoreoEvent *event, bool fastKill );
Expand Down
14 changes: 7 additions & 7 deletions sp/src/game/client/c_sceneentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ void C_SceneEntity::DispatchStartSpeak( CChoreoScene *scene, C_BaseFlex *actor,
es.m_pSoundName = event->GetParameters();

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

// Close captioning only on master token no matter what...
if ( event->GetCloseCaptionType() == CChoreoEvent::CC_MASTER )
Expand Down Expand Up @@ -964,7 +964,7 @@ void C_SceneEntity::UnloadScene( void )
//-----------------------------------------------------------------------------
void C_SceneEntity::DispatchStartFlexAnimation( CChoreoScene *scene, C_BaseFlex *actor, CChoreoEvent *event )
{
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
}

//-----------------------------------------------------------------------------
Expand All @@ -984,7 +984,7 @@ void C_SceneEntity::DispatchEndFlexAnimation( CChoreoScene *scene, C_BaseFlex *a
//-----------------------------------------------------------------------------
void C_SceneEntity::DispatchStartExpression( CChoreoScene *scene, C_BaseFlex *actor, CChoreoEvent *event )
{
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
}

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

actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
}

//-----------------------------------------------------------------------------
Expand All @@ -1023,7 +1023,7 @@ void C_SceneEntity::DispatchProcessGesture( CChoreoScene *scene, C_BaseFlex *act
return;

actor->RemoveSceneEvent( scene, event, false );
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
}

//-----------------------------------------------------------------------------
Expand All @@ -1046,7 +1046,7 @@ void C_SceneEntity::DispatchEndGesture( CChoreoScene *scene, C_BaseFlex *actor,
//-----------------------------------------------------------------------------
void C_SceneEntity::DispatchStartSequence( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event )
{
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
}

//-----------------------------------------------------------------------------
Expand All @@ -1056,7 +1056,7 @@ void C_SceneEntity::DispatchStartSequence( CChoreoScene *scene, CBaseFlex *actor
void C_SceneEntity::DispatchProcessSequence( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event )
{
actor->RemoveSceneEvent( scene, event, false );
actor->AddSceneEvent( scene, event, NULL, IsClientOnly() );
actor->AddSceneEvent( scene, event, NULL, IsClientOnly(), this );
}

//-----------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions sp/src/game/client/cdll_client_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ IReplaySystem *g_pReplay = NULL;
IVEngineServer *serverengine = NULL;
#endif

IScriptManager *scriptmanager = NULL;

IHaptics* haptics = NULL;// NVNT haptics system interface singleton

//=============================================================================
Expand Down Expand Up @@ -964,6 +966,16 @@ int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physi
if (!g_pMatSystemSurface)
return false;

if ( !CommandLine()->CheckParm( "-noscripting") )
{
scriptmanager = (IScriptManager *)appSystemFactory( VSCRIPT_INTERFACE_VERSION, NULL );

if (scriptmanager == nullptr)
{
scriptmanager = (IScriptManager*)Sys_GetFactoryThis()(VSCRIPT_INTERFACE_VERSION, NULL);
}
}

#ifdef WORKSHOP_IMPORT_ENABLED
if ( !ConnectDataModel( appSystemFactory ) )
return false;
Expand Down
5 changes: 5 additions & 0 deletions sp/src/game/client/client_base.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ $Project
$File "viewrender.cpp"
$File "$SRCDIR\game\shared\voice_banmgr.cpp"
$File "$SRCDIR\game\shared\voice_status.cpp"
$File "vscript_client.cpp"
$File "vscript_client.h"
$File "vscript_client.nut"
$File "$SRCDIR\game\shared\vscript_shared.cpp"
$File "$SRCDIR\game\shared\vscript_shared.h"
$File "warp_overlay.cpp"
$File "WaterLODMaterialProxy.cpp"
$File "$SRCDIR\game\shared\weapon_parse.cpp"
Expand Down
7 changes: 7 additions & 0 deletions sp/src/game/client/client_mapbase.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ $Configuration
$PreprocessorDefinitions "$BASE;ASW_PROJECTED_TEXTURES;DYNAMIC_RTT_SHADOWS"

$PreprocessorDefinitions "$BASE;MAPBASE_RPC;DISCORD_RPC;STEAM_RPC" [$MAPBASE_RPC]

$PreprocessorDefinitions "$BASE;MAPBASE_VSCRIPT" [$MAPBASE_VSCRIPT]
}
}

Expand Down Expand Up @@ -51,4 +53,9 @@ $Project
}
}
}

$Folder "Link Libraries"
{
$Lib "vscript" [$MAPBASE_VSCRIPT]
}
}
Loading