mirror of
https://github.com/mapbase-source/source-sdk-2013.git
synced 2025-02-03 09:10:40 +03:00
Mapbase v6.2 - Merge pull request #94 from mapbase-source/develop
This commit is contained in:
commit
fd600b53aa
9
README
9
README
@ -83,6 +83,7 @@ interchangeable arms; this may change in the future)
|
||||
- https://developer.valvesoftware.com/wiki/Npc_clawscanner#Strider_Scout_Issue (npc_clawscanner strider scout fix)
|
||||
- https://developer.valvesoftware.com/wiki/Ambient_generic:_stop_and_toggle_fix (Fixes for stopping/toggling ambient_generic)
|
||||
- https://developer.valvesoftware.com/wiki/Func_clip_vphysics ("Start Disabled" keyvalue fix)
|
||||
- https://developer.valvesoftware.com/wiki/Importing_CSS_Weapons_Into_HL2 (CS:S viewmodel chirality)
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -91,9 +92,8 @@ Direct contributions:
|
||||
- https://github.com/mapbase-source/source-sdk-2013/pull/5 (Custom VScript implementation by ReDucTor; was placed into feature branch before being merged in a subsequent PR)
|
||||
- https://github.com/mapbase-source/source-sdk-2013/pull/3 ("playvideo" command playback fix from Avantate)
|
||||
- https://github.com/mapbase-source/source-sdk-2013/pull/21 (Various GCC/Linux fixes from z33ky)
|
||||
- https://github.com/mapbase-source/source-sdk-2013/pull/47 (VScript utility/consistency changes from samisalreadytaken)
|
||||
- https://github.com/mapbase-source/source-sdk-2013/pull/59 (New VScript functions and singletons from samisalreadytaken based on API documentation in later Source/Source 2 games)
|
||||
- https://github.com/mapbase-source/source-sdk-2013/pull/60 (Adjustment by RoyaleNoir to one of Saul's VDC changes)
|
||||
- https://github.com/mapbase-source/source-sdk-2013/pull/84 (CS:S viewmodel chirality from 1upD)
|
||||
- Demo autorecord code provided by Klems
|
||||
- cc_emit crash fix provided by 1upD
|
||||
- Custom HL2 ammo crate models created by Rara (Textures created by Blixibon; This is asset-based and, aside from the SLAM crate, not reflected in the code)
|
||||
@ -101,6 +101,11 @@ Direct contributions:
|
||||
- npc_vehicledriver fixes provided by CrAzY
|
||||
- npc_combine cover behavior patches provided by iohnnyboy
|
||||
|
||||
== Contributions from samisalreadytaken:
|
||||
=-- https://github.com/mapbase-source/source-sdk-2013/pull/47 (VScript utility/consistency changes)
|
||||
=-- https://github.com/mapbase-source/source-sdk-2013/pull/59 (New VScript functions and singletons based on API documentation in later Source/Source 2 games)
|
||||
=-- https://github.com/mapbase-source/source-sdk-2013/pull/80 (More VScript changes, including support for extremely flexible client/server messaging)
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Other sources:
|
||||
|
@ -813,7 +813,11 @@ bool GameData::RemapNameField( const char *pszInValue, char *pszOutValue, TNameF
|
||||
{
|
||||
strcpy( pszOutValue, pszInValue );
|
||||
|
||||
#ifdef MAPBASE
|
||||
if ( pszInValue[ 0 ] && pszInValue[ 0 ] != '@' && pszInValue[ 0 ] != '!' )
|
||||
#else
|
||||
if ( pszInValue[ 0 ] && pszInValue[ 0 ] != '@' )
|
||||
#endif
|
||||
{ // ! at the start of a value means it is global and should not be remaped
|
||||
switch( NameFixup )
|
||||
{
|
||||
|
@ -281,6 +281,20 @@ BEGIN_DATADESC( C_ClientRagdoll )
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
BEGIN_ENT_SCRIPTDESC( C_ClientRagdoll, C_BaseAnimating, "Client-side ragdolls" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( SUB_Remove, "FadeOut", "Fades out the ragdoll and removes it from the client." )
|
||||
|
||||
// TODO: Proper shared ragdoll funcs?
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRagdollObject, "GetRagdollObject", "Gets the ragdoll object of the specified index." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRagdollObjectCount, "GetRagdollObjectCount", "Gets the number of ragdoll objects on this ragdoll." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
|
||||
ScriptHook_t C_BaseAnimating::g_Hook_OnClientRagdoll;
|
||||
#endif
|
||||
|
||||
BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-side" )
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetPoseParameter, "GetPoseParameter", "Get the specified pose parameter's value" )
|
||||
@ -288,6 +302,14 @@ BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-si
|
||||
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" )
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptLookupAttachment, "LookupAttachment", "Get the named attachement id" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAttachmentOrigin, "GetAttachmentOrigin", "Get the attachement id's origin vector" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAttachmentAngles, "GetAttachmentAngles", "Get the attachement id's angles as a p,y,r vector" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAttachmentMatrix, "GetAttachmentMatrix", "Get the attachement id's matrix transform" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( LookupBone, "Get the named bone id" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoneTransform, "GetBoneTransform", "Get the transform for the specified bone" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( SetBodygroup, "Sets a bodygroup")
|
||||
DEFINE_SCRIPTFUNC( GetBodygroup, "Gets a bodygroup" )
|
||||
DEFINE_SCRIPTFUNC( GetBodygroupName, "Gets a bodygroup name" )
|
||||
@ -302,7 +324,28 @@ BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-si
|
||||
DEFINE_SCRIPTFUNC( LookupActivity, "Gets the ID of the specified activity name" )
|
||||
DEFINE_SCRIPTFUNC( GetSequenceName, "Gets the name of the specified sequence index" )
|
||||
DEFINE_SCRIPTFUNC( GetSequenceActivityName, "Gets the activity name of the specified sequence index" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetSequenceMoveDist, "GetSequenceMoveDist", "Gets the move distance of the specified sequence" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetSequenceActivity, "GetSequenceActivity", "Gets the activity ID of the specified sequence index" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSelectWeightedSequence, "SelectWeightedSequence", "Selects a sequence for the specified activity ID" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetPlaybackRate, "" )
|
||||
DEFINE_SCRIPTFUNC( SetPlaybackRate, "" )
|
||||
DEFINE_SCRIPTFUNC( GetCycle, "" )
|
||||
DEFINE_SCRIPTFUNC( SetCycle, "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetSkin, "GetSkin", "Gets the model's skin" )
|
||||
DEFINE_SCRIPTFUNC( SetSkin, "Sets the model's skin" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetForceBone, "Gets the entity's force bone, which is used to determine which bone a ragdoll should apply its force to." )
|
||||
DEFINE_SCRIPTFUNC( SetForceBone, "Sets the entity's force bone, which is used to determine which bone a ragdoll should apply its force to." )
|
||||
DEFINE_SCRIPTFUNC( GetRagdollForce, "Gets the entity's ragdoll force, which is used to apply velocity to a ragdoll." )
|
||||
DEFINE_SCRIPTFUNC( SetRagdollForce, "Sets the entity's ragdoll force, which is used to apply velocity to a ragdoll." )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptBecomeRagdollOnClient, "BecomeRagdollOnClient", "" )
|
||||
DEFINE_SCRIPTFUNC( IsRagdoll, "" )
|
||||
|
||||
BEGIN_SCRIPTHOOK( C_BaseAnimating::g_Hook_OnClientRagdoll, "OnClientRagdoll", FIELD_VOID, "Called when this entity turns into a client-side ragdoll." )
|
||||
DEFINE_SCRIPTHOOK_PARAM( "ragdoll", FIELD_HSCRIPT )
|
||||
END_SCRIPTHOOK()
|
||||
#endif
|
||||
END_SCRIPTDESC();
|
||||
|
||||
@ -666,6 +709,24 @@ void C_ClientRagdoll::Release( void )
|
||||
BaseClass::Release();
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
HSCRIPT C_ClientRagdoll::ScriptGetRagdollObject( int iIndex )
|
||||
{
|
||||
if (iIndex < 0 || iIndex > m_pRagdoll->RagdollBoneCount())
|
||||
{
|
||||
Warning("%s GetRagdollObject: Index %i not valid (%i objects)\n", GetDebugName(), iIndex, m_pRagdoll->RagdollBoneCount());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_pScriptVM->RegisterInstance( m_pRagdoll->GetElement(iIndex) );
|
||||
}
|
||||
|
||||
int C_ClientRagdoll::ScriptGetRagdollObjectCount()
|
||||
{
|
||||
return m_pRagdoll->RagdollBoneCount();
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Incremented each frame in InvalidateModelBones. Models compare this value to what it
|
||||
// was last time they setup their bones to determine if they need to re-setup their bones.
|
||||
@ -1429,6 +1490,61 @@ float C_BaseAnimating::ClampCycle( float flCycle, bool isLooping )
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns the world location and world angles of an attachment to vscript caller
|
||||
// Input : attachment name
|
||||
// Output : location and angles
|
||||
//-----------------------------------------------------------------------------
|
||||
const Vector& C_BaseAnimating::ScriptGetAttachmentOrigin( int iAttachment )
|
||||
{
|
||||
|
||||
static Vector absOrigin;
|
||||
static QAngle qa;
|
||||
|
||||
C_BaseAnimating::GetAttachment( iAttachment, absOrigin, qa );
|
||||
|
||||
return absOrigin;
|
||||
}
|
||||
|
||||
const Vector& C_BaseAnimating::ScriptGetAttachmentAngles( int iAttachment )
|
||||
{
|
||||
|
||||
static Vector absOrigin;
|
||||
static Vector absAngles;
|
||||
static QAngle qa;
|
||||
|
||||
C_BaseAnimating::GetAttachment( iAttachment, absOrigin, qa );
|
||||
absAngles.x = qa.x;
|
||||
absAngles.y = qa.y;
|
||||
absAngles.z = qa.z;
|
||||
return absAngles;
|
||||
}
|
||||
|
||||
HSCRIPT C_BaseAnimating::ScriptGetAttachmentMatrix( int iAttachment )
|
||||
{
|
||||
static matrix3x4_t matrix;
|
||||
|
||||
C_BaseAnimating::GetAttachment( iAttachment, matrix );
|
||||
return g_pScriptVM->RegisterInstance( &matrix );
|
||||
}
|
||||
|
||||
void C_BaseAnimating::ScriptGetBoneTransform( int iBone, HSCRIPT hTransform )
|
||||
{
|
||||
if (hTransform == NULL)
|
||||
return;
|
||||
|
||||
GetBoneTransform( iBone, *HScriptToClass<matrix3x4_t>( hTransform ) );
|
||||
}
|
||||
|
||||
HSCRIPT C_BaseAnimating::ScriptBecomeRagdollOnClient()
|
||||
{
|
||||
C_BaseAnimating *pRagdoll = BecomeRagdollOnClient();
|
||||
if (!pRagdoll)
|
||||
return NULL;
|
||||
|
||||
return pRagdoll->GetScriptInstance();
|
||||
}
|
||||
|
||||
float C_BaseAnimating::ScriptGetPoseParameter( const char* szName )
|
||||
{
|
||||
CStudioHdr* pHdr = GetModelPtr();
|
||||
@ -4736,6 +4852,17 @@ C_BaseAnimating *C_BaseAnimating::BecomeRagdollOnClient()
|
||||
const float boneDt = 0.1f;
|
||||
GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt );
|
||||
pRagdoll->InitAsClientRagdoll( boneDelta0, boneDelta1, currentBones, boneDt );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
// Hook for ragdolling
|
||||
if (m_ScriptScope.IsInitialized() && g_Hook_OnClientRagdoll.CanRunInScope( m_ScriptScope ))
|
||||
{
|
||||
// ragdoll
|
||||
ScriptVariant_t args[] = { ScriptVariant_t( pRagdoll->GetScriptInstance() ) };
|
||||
g_Hook_OnClientRagdoll.Call( m_ScriptScope, NULL, args );
|
||||
}
|
||||
#endif
|
||||
|
||||
return pRagdoll;
|
||||
}
|
||||
|
||||
|
@ -454,6 +454,30 @@ public:
|
||||
virtual bool IsViewModel() const;
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
int ScriptLookupAttachment( const char *pAttachmentName ) { return LookupAttachment( pAttachmentName ); }
|
||||
const Vector& ScriptGetAttachmentOrigin(int iAttachment);
|
||||
const Vector& ScriptGetAttachmentAngles(int iAttachment);
|
||||
HSCRIPT ScriptGetAttachmentMatrix(int iAttachment);
|
||||
|
||||
void ScriptGetBoneTransform( int iBone, HSCRIPT hTransform );
|
||||
|
||||
int ScriptGetSequenceActivity( int iSequence ) { return GetSequenceActivity( iSequence ); }
|
||||
float ScriptGetSequenceMoveDist( int iSequence ) { return GetSequenceMoveDist( GetModelPtr(), iSequence ); }
|
||||
int ScriptSelectWeightedSequence( int activity ) { return SelectWeightedSequence( (Activity)activity ); }
|
||||
|
||||
// For VScript
|
||||
int ScriptGetSkin() { return GetSkin(); }
|
||||
void SetSkin( int iSkin ) { m_nSkin = iSkin; }
|
||||
|
||||
int GetForceBone() { return m_nForceBone; }
|
||||
void SetForceBone( int iBone ) { m_nForceBone = iBone; }
|
||||
const Vector& GetRagdollForce() { return m_vecForce; }
|
||||
void SetRagdollForce( const Vector &vecForce ) { m_vecForce = vecForce; }
|
||||
|
||||
HSCRIPT ScriptBecomeRagdollOnClient();
|
||||
|
||||
static ScriptHook_t g_Hook_OnClientRagdoll;
|
||||
|
||||
float ScriptGetPoseParameter(const char* szName);
|
||||
#endif
|
||||
void ScriptSetPoseParameter(const char* szName, float fValue);
|
||||
@ -475,10 +499,6 @@ protected:
|
||||
|
||||
virtual bool CalcAttachments();
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
int ScriptGetSequenceActivity( int iSequence ) { return GetSequenceActivity( iSequence ); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
// This method should return true if the bones have changed + SetupBones needs to be called
|
||||
virtual float LastBoneChangedTime() { return FLT_MAX; }
|
||||
@ -667,6 +687,9 @@ public:
|
||||
C_ClientRagdoll( bool bRestoring = true );
|
||||
DECLARE_CLASS( C_ClientRagdoll, C_BaseAnimating );
|
||||
DECLARE_DATADESC();
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DECLARE_ENT_SCRIPTDESC();
|
||||
#endif
|
||||
|
||||
// inherited from IPVSNotify
|
||||
virtual void OnPVSStatusChanged( bool bInPVS );
|
||||
@ -688,6 +711,11 @@ public:
|
||||
void FadeOut( void );
|
||||
virtual float LastBoneChangedTime();
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
HSCRIPT ScriptGetRagdollObject( int iIndex );
|
||||
int ScriptGetRagdollObjectCount();
|
||||
#endif
|
||||
|
||||
bool m_bFadeOut;
|
||||
bool m_bImportant;
|
||||
float m_flEffectTime;
|
||||
|
@ -429,6 +429,7 @@ BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_AnimTimeMustBeFirst )
|
||||
END_RECV_TABLE()
|
||||
|
||||
BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities" )
|
||||
DEFINE_SCRIPT_INSTANCE_HELPER( &g_BaseEntityScriptInstanceHelper )
|
||||
DEFINE_SCRIPTFUNC_NAMED( GetAbsOrigin, "GetOrigin", "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetForward, "GetForwardVector", "Get the forward vector of the entity" )
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
@ -442,6 +443,7 @@ BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DEFINE_SCRIPTFUNC( ValidateScriptScope, "Ensure that an entity's script scope has been created" )
|
||||
DEFINE_SCRIPTFUNC( GetOrCreatePrivateScriptScope, "Create and retrieve the script-side data associated with an entity" )
|
||||
DEFINE_SCRIPTFUNC( GetScriptScope, "Retrieve the script-side data associated with an entity" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetHealth, "" )
|
||||
@ -456,23 +458,92 @@ BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities
|
||||
DEFINE_SCRIPTFUNC( GetClassname, "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( GetEntityName, "GetName", "" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( SetAbsOrigin, "SetOrigin", "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetForward, "SetForwardVector", "Set the orientation of the entity to have this forward vector" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetLocalOrigin, "GetLocalOrigin" )
|
||||
DEFINE_SCRIPTFUNC( SetLocalOrigin, "SetLocalOrigin" )
|
||||
DEFINE_SCRIPTFUNC( GetLocalAngles, "GetLocalAngles" )
|
||||
DEFINE_SCRIPTFUNC( SetLocalAngles, "SetLocalAngles" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( WorldSpaceCenter, "GetCenter", "Get vector to center of object - absolute coords" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptEyePosition, "EyePosition", "Get vector to eye position - absolute coords" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAngles, "GetAngles", "Get entity pitch, yaw, roll as a vector" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptEyeAngles, "EyeAngles", "Get eye pitch, yaw, roll as a vector" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( GetAbsAngles, "GetAngles", "Get entity pitch, yaw, roll as a vector" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( SetAbsAngles, "SetAngles", "Set entity pitch, yaw, roll" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoundingMins, "GetBoundingMins", "Get a vector containing min bounds, centered on object" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoundingMaxs, "GetBoundingMaxs", "Get a vector containing max bounds, centered on object" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptEntityToWorldTransform, "EntityToWorldTransform", "Get the entity's transform" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetPhysicsObject, "GetPhysicsObject", "Get the entity's physics object if it has one" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetWaterLevel, "Get current level of water submergence" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetParent, "SetParent", "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetMoveParent, "GetMoveParent", "If in hierarchy, retrieves the entity's parent" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRootMoveParent, "GetRootMoveParent", "If in hierarchy, walks up the hierarchy to find the root parent" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptFirstMoveChild, "FirstMoveChild", "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptNextMovePeer, "NextMovePeer", "" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptFollowEntity, "FollowEntity", "Begin following the specified entity. This makes this entity non-solid, parents it to the target entity, and teleports it to the specified entity's origin. The second parameter is whether or not to use bonemerging while following." )
|
||||
DEFINE_SCRIPTFUNC( StopFollowingEntity, "Stops following an entity if we're following one." )
|
||||
DEFINE_SCRIPTFUNC( IsFollowingEntity, "Returns true if this entity is following another entity." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetFollowedEntity, "GetFollowedEntity", "Get the entity we're following." )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( GetScriptOwnerEntity, "GetOwner", "Gets this entity's owner" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( SetScriptOwnerEntity, "SetOwner", "Sets this entity's owner" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorVector, "GetRenderColorVector", "Get the render color as a vector" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorR, "GetRenderColorR", "Get the render color's R value" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorG, "GetRenderColorG", "Get the render color's G value" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorB, "GetRenderColorB", "Get the render color's B value" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAlpha, "GetRenderAlpha", "Get the render color's alpha value" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColorVector, "SetRenderColorVector", "Set the render color as a vector" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColor, "SetRenderColor", "Set the render color" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColorR, "SetRenderColorR", "Set the render color's R value" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColorG, "SetRenderColorG", "Set the render color's G value" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColorB, "SetRenderColorB", "Set the render color's B value" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetAlpha, "SetRenderAlpha", "Set the render color's alpha value" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRenderMode, "GetRenderMode", "Get render mode" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetRenderMode, "SetRenderMode", "Set render mode" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetEffects, "Get effects" )
|
||||
DEFINE_SCRIPTFUNC( AddEffects, "Add effect(s)" )
|
||||
DEFINE_SCRIPTFUNC( RemoveEffects, "Remove effect(s)" )
|
||||
DEFINE_SCRIPTFUNC( ClearEffects, "Clear effect(s)" )
|
||||
DEFINE_SCRIPTFUNC( SetEffects, "Set effect(s)" )
|
||||
DEFINE_SCRIPTFUNC( IsEffectActive, "Check if an effect is active" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetFlags, "Get flags" )
|
||||
DEFINE_SCRIPTFUNC( AddFlag, "Add flag" )
|
||||
DEFINE_SCRIPTFUNC( RemoveFlag, "Remove flag" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetEFlags, "Get Eflags" )
|
||||
DEFINE_SCRIPTFUNC( AddEFlags, "Add Eflags" )
|
||||
DEFINE_SCRIPTFUNC( RemoveEFlags, "Remove Eflags" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetMoveType, "GetMoveType", "Get the move type" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetMoveType, "SetMoveType", "Set the move type" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetCollisionGroup, "Get the collision group" )
|
||||
DEFINE_SCRIPTFUNC( SetCollisionGroup, "Set the collision group" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetSolidFlags, "Get solid flags" )
|
||||
DEFINE_SCRIPTFUNC( AddSolidFlags, "Add solid flags" )
|
||||
DEFINE_SCRIPTFUNC( RemoveSolidFlags, "Remove solid flags" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( IsPlayer, "Returns true if this entity is a player." )
|
||||
DEFINE_SCRIPTFUNC( IsNPC, "Returns true if this entity is a NPC." )
|
||||
//DEFINE_SCRIPTFUNC( IsCombatCharacter, "Returns true if this entity is a combat character (player or NPC)." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( IsBaseCombatWeapon, "IsWeapon", "Returns true if this entity is a weapon." )
|
||||
DEFINE_SCRIPTFUNC( IsWorld, "Returns true if this entity is the world." )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( GetEntityIndex, "entindex", "" )
|
||||
#endif
|
||||
|
||||
END_SCRIPTDESC();
|
||||
|
||||
#ifndef NO_ENTITY_PREDICTION
|
||||
@ -6060,6 +6131,9 @@ BEGIN_DATADESC_NO_BASE( C_BaseEntity )
|
||||
DEFINE_FIELD( m_angAbsRotation, FIELD_VECTOR ),
|
||||
DEFINE_ARRAY( m_rgflCoordinateFrame, FIELD_FLOAT, 12 ), // NOTE: MUST BE IN LOCAL SPACE, NOT POSITION_VECTOR!!! (see CBaseEntity::Restore)
|
||||
DEFINE_FIELD( m_fFlags, FIELD_INTEGER ),
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DEFINE_FIELD( m_iszScriptId, FIELD_STRING ),
|
||||
#endif
|
||||
END_DATADESC()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -266,6 +266,7 @@ public:
|
||||
bool ValidateScriptScope();
|
||||
bool CallScriptFunction( const char* pFunctionName, ScriptVariant_t* pFunctionReturn );
|
||||
|
||||
HSCRIPT GetOrCreatePrivateScriptScope();
|
||||
HSCRIPT GetScriptScope() { return m_ScriptScope; }
|
||||
|
||||
HSCRIPT LookupScriptFunction(const char* pFunctionName);
|
||||
@ -275,6 +276,9 @@ public:
|
||||
bool RunScript( const char* pScriptText, const char* pDebugFilename = "C_BaseEntity::RunScript" );
|
||||
#endif
|
||||
|
||||
HSCRIPT GetScriptOwnerEntity();
|
||||
virtual void SetScriptOwnerEntity(HSCRIPT pOwner);
|
||||
|
||||
HSCRIPT GetScriptInstance();
|
||||
|
||||
HSCRIPT m_hScriptInstance;
|
||||
@ -1149,6 +1153,11 @@ public:
|
||||
bool IsFollowingEntity();
|
||||
CBaseEntity *GetFollowedEntity();
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
void ScriptFollowEntity( HSCRIPT hBaseEntity, bool bBoneMerge );
|
||||
HSCRIPT ScriptGetFollowedEntity();
|
||||
#endif
|
||||
|
||||
// For shadows rendering the correct body + sequence...
|
||||
virtual int GetBody() { return 0; }
|
||||
virtual int GetSkin() { return 0; }
|
||||
@ -1170,15 +1179,39 @@ public:
|
||||
void VScriptPrecacheScriptSound(const char* soundname);
|
||||
|
||||
const Vector& ScriptEyePosition(void) { static Vector vec; vec = EyePosition(); return vec; }
|
||||
const Vector& ScriptGetAngles(void) { static Vector vec; QAngle qa = GetAbsAngles(); vec.x = qa.x; vec.y = qa.y; vec.z = qa.z; return vec; }
|
||||
const QAngle& ScriptEyeAngles(void) { static QAngle ang; ang = EyeAngles(); return ang; }
|
||||
void ScriptSetForward( const Vector& v ) { QAngle angles; VectorAngles( v, angles ); SetAbsAngles( angles ); }
|
||||
|
||||
const Vector& ScriptGetBoundingMins( void ) { return m_Collision.OBBMins(); }
|
||||
const Vector& ScriptGetBoundingMaxs( void ) { return m_Collision.OBBMaxs(); }
|
||||
|
||||
HSCRIPT ScriptEntityToWorldTransform( void );
|
||||
|
||||
HSCRIPT ScriptGetPhysicsObject( void );
|
||||
|
||||
void ScriptSetParent( HSCRIPT hParent, const char *szAttachment );
|
||||
HSCRIPT ScriptGetMoveParent( void );
|
||||
HSCRIPT ScriptGetRootMoveParent();
|
||||
HSCRIPT ScriptFirstMoveChild( void );
|
||||
HSCRIPT ScriptNextMovePeer( void );
|
||||
|
||||
const Vector& ScriptGetColorVector();
|
||||
int ScriptGetColorR() { return m_clrRender.GetR(); }
|
||||
int ScriptGetColorG() { return m_clrRender.GetG(); }
|
||||
int ScriptGetColorB() { return m_clrRender.GetB(); }
|
||||
int ScriptGetAlpha() { return m_clrRender.GetA(); }
|
||||
void ScriptSetColorVector( const Vector& vecColor );
|
||||
void ScriptSetColor( int r, int g, int b );
|
||||
void ScriptSetColorR( int iVal ) { SetRenderColorR( iVal ); }
|
||||
void ScriptSetColorG( int iVal ) { SetRenderColorG( iVal ); }
|
||||
void ScriptSetColorB( int iVal ) { SetRenderColorB( iVal ); }
|
||||
void ScriptSetAlpha( int iVal ) { SetRenderColorA( iVal ); }
|
||||
|
||||
int ScriptGetRenderMode() { return GetRenderMode(); }
|
||||
void ScriptSetRenderMode( int nRenderMode ) { SetRenderMode( (RenderMode_t)nRenderMode ); }
|
||||
|
||||
int ScriptGetMoveType() { return GetMoveType(); }
|
||||
void ScriptSetMoveType( int iMoveType ) { SetMoveType( (MoveType_t)iMoveType ); }
|
||||
#endif
|
||||
|
||||
// Stubs on client
|
||||
|
@ -492,14 +492,14 @@ C_BasePlayer::~C_BasePlayer()
|
||||
if ( this == s_pLocalPlayer )
|
||||
{
|
||||
s_pLocalPlayer = NULL;
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if ( IsLocalPlayer() && g_pScriptVM )
|
||||
{
|
||||
g_pScriptVM->SetValue( "player", SCRIPT_VARIANT_NULL );
|
||||
}
|
||||
if ( g_pScriptVM )
|
||||
{
|
||||
g_pScriptVM->SetValue( "player", SCRIPT_VARIANT_NULL );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
delete m_pFlashlight;
|
||||
}
|
||||
@ -855,6 +855,14 @@ void C_BasePlayer::PostDataUpdate( DataUpdateType_t updateType )
|
||||
// changed level, which would cause the snd_soundmixer to be left modified.
|
||||
ConVar *pVar = (ConVar *)cvar->FindVar( "snd_soundmixer" );
|
||||
pVar->Revert();
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
// Moved here from LevelInitPostEntity, which is executed before local player is spawned.
|
||||
if ( g_pScriptVM )
|
||||
{
|
||||
g_pScriptVM->SetValue( "player", GetScriptInstance() );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#ifdef CSTRIKE_DLL
|
||||
#if defined(CSTRIKE_DLL) || defined (MAPBASE)
|
||||
ConVar cl_righthand( "cl_righthand", "1", FCVAR_ARCHIVE, "Use right-handed view models." );
|
||||
#endif
|
||||
|
||||
@ -194,7 +194,7 @@ bool C_BaseViewModel::Interpolate( float currentTime )
|
||||
|
||||
inline bool C_BaseViewModel::ShouldFlipViewModel()
|
||||
{
|
||||
#ifdef CSTRIKE_DLL
|
||||
#if defined(CSTRIKE_DLL) || defined (MAPBASE)
|
||||
// If cl_righthand is set, then we want them all right-handed.
|
||||
CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
|
||||
if ( pWeapon )
|
||||
|
@ -24,6 +24,11 @@ BEGIN_NETWORK_TABLE( CDynamicProp, DT_DynamicProp )
|
||||
RecvPropBool(RECVINFO(m_bUseHitboxesForRenderBox)),
|
||||
END_NETWORK_TABLE()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
// Allows client-side VScript to create dynamic props via CreateProp()
|
||||
LINK_ENTITY_TO_CLASS( prop_dynamic, C_DynamicProp );
|
||||
#endif
|
||||
|
||||
C_DynamicProp::C_DynamicProp( void )
|
||||
{
|
||||
m_iCachedFrameCount = -1;
|
||||
|
@ -13,6 +13,9 @@
|
||||
#include "ivieweffects.h"
|
||||
#include "shake.h"
|
||||
#include "eventlist.h"
|
||||
#ifdef MAPBASE
|
||||
#include "mapentities_shared.h"
|
||||
#endif
|
||||
// NVNT haptic include for notification of world precache
|
||||
#include "haptics/haptic_utils.h"
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
@ -62,9 +65,6 @@ BEGIN_RECV_TABLE( C_World, DT_World )
|
||||
#ifdef MAPBASE
|
||||
RecvPropString(RECVINFO(m_iszChapterTitle)),
|
||||
#endif
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
RecvPropInt(RECVINFO(m_iScriptLanguageClient)),
|
||||
#endif
|
||||
END_RECV_TABLE()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
@ -86,6 +86,11 @@ bool C_World::Init( int entnum, int iSerialNum )
|
||||
ActivityList_Init();
|
||||
EventList_Init();
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
m_iScriptLanguageServer = SL_NONE;
|
||||
m_iScriptLanguageClient = SL_NONE;
|
||||
#endif
|
||||
|
||||
return BaseClass::Init( entnum, iSerialNum );
|
||||
}
|
||||
|
||||
@ -129,11 +134,6 @@ void C_World::OnDataChanged( DataUpdateType_t updateType )
|
||||
engine->SetOcclusionParameters( params );
|
||||
|
||||
modelinfo->SetLevelScreenFadeRange( m_flMinPropScreenSpaceWidth, m_flMaxPropScreenSpaceWidth );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
// This is now here so that C_World has time to receive the selected script language
|
||||
VScriptClientInit();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,6 +199,72 @@ void C_World::Spawn( void )
|
||||
Precache();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Parse data from a map file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool C_World::KeyValue( const char *szKeyName, const char *szValue )
|
||||
{
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if ( FStrEq( szKeyName, "vscriptlanguage" ) )
|
||||
{
|
||||
m_iScriptLanguageServer = atoi( szValue );
|
||||
}
|
||||
else if ( FStrEq( szKeyName, "vscriptlanguage_client" ) )
|
||||
{
|
||||
m_iScriptLanguageClient = atoi( szValue );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return BaseClass::KeyValue( szKeyName, szValue );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef MAPBASE
|
||||
//-----------------------------------------------------------------------------
|
||||
// Parses worldspawn data from BSP on the client
|
||||
//-----------------------------------------------------------------------------
|
||||
void C_World::ParseWorldMapData( const char *pMapData )
|
||||
{
|
||||
char szTokenBuffer[MAPKEY_MAXLENGTH];
|
||||
for ( ; true; pMapData = MapEntity_SkipToNextEntity(pMapData, szTokenBuffer) )
|
||||
{
|
||||
//
|
||||
// Parse the opening brace.
|
||||
//
|
||||
char token[MAPKEY_MAXLENGTH];
|
||||
pMapData = MapEntity_ParseToken( pMapData, token );
|
||||
|
||||
//
|
||||
// Check to see if we've finished or not.
|
||||
//
|
||||
if (!pMapData)
|
||||
break;
|
||||
|
||||
if (token[0] != '{')
|
||||
{
|
||||
Error( "MapEntity_ParseAllEntities: found %s when expecting {", token);
|
||||
continue;
|
||||
}
|
||||
|
||||
CEntityMapData entData( (char*)pMapData );
|
||||
char className[MAPKEY_MAXLENGTH];
|
||||
|
||||
if (!entData.ExtractValue( "classname", className ))
|
||||
{
|
||||
Error( "classname missing from entity!\n" );
|
||||
}
|
||||
|
||||
if ( !Q_strcmp( className, "worldspawn" ) )
|
||||
{
|
||||
// Set up keyvalues.
|
||||
ParseMapData( &entData );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
C_World *GetClientWorldEntity()
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
|
||||
virtual void Precache();
|
||||
virtual void Spawn();
|
||||
virtual bool KeyValue( const char *szKeyName, const char *szValue );
|
||||
|
||||
// Don't worry about adding the world to the collision list; it's already there
|
||||
virtual CollideType_t GetCollideType( void ) { return ENTITY_SHOULD_NOT_COLLIDE; }
|
||||
@ -41,8 +42,15 @@ public:
|
||||
float GetWaveHeight() const;
|
||||
const char *GetDetailSpriteMaterial() const;
|
||||
|
||||
#ifdef MAPBASE
|
||||
// A special function which parses map data for the client world entity before LevelInitPreEntity().
|
||||
// This can be used to access keyvalues early and without transmitting from the server.
|
||||
void ParseWorldMapData( const char *pMapData );
|
||||
#endif
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
ScriptLanguage_t GetScriptLanguage() { return (ScriptLanguage_t)m_iScriptLanguageClient; }
|
||||
// -2 = Use server language
|
||||
ScriptLanguage_t GetScriptLanguage() { return (ScriptLanguage_t)(m_iScriptLanguageClient != -2 ? m_iScriptLanguageClient : m_iScriptLanguageServer); }
|
||||
#endif
|
||||
|
||||
public:
|
||||
@ -64,6 +72,7 @@ public:
|
||||
char m_iszChapterTitle[64];
|
||||
#endif
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
int m_iScriptLanguageServer;
|
||||
int m_iScriptLanguageClient;
|
||||
#endif
|
||||
|
||||
|
@ -147,6 +147,10 @@
|
||||
#include "fbxsystem/fbxsystem.h"
|
||||
#endif
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
#include "vscript_client.h"
|
||||
#endif
|
||||
|
||||
extern vgui::IInputInternal *g_InputInternal;
|
||||
|
||||
//=============================================================================
|
||||
@ -1104,6 +1108,9 @@ int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physi
|
||||
g_pGameSaveRestoreBlockSet->AddBlockHandler( GetEntitySaveRestoreBlockHandler() );
|
||||
g_pGameSaveRestoreBlockSet->AddBlockHandler( GetPhysSaveRestoreBlockHandler() );
|
||||
g_pGameSaveRestoreBlockSet->AddBlockHandler( GetViewEffectsRestoreBlockHandler() );
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
g_pGameSaveRestoreBlockSet->AddBlockHandler( GetVScriptSaveRestoreBlockHandler() );
|
||||
#endif
|
||||
|
||||
ClientWorldFactoryInit();
|
||||
|
||||
@ -1216,6 +1223,9 @@ void CHLClient::Shutdown( void )
|
||||
g_pGameSaveRestoreBlockSet->RemoveBlockHandler( GetViewEffectsRestoreBlockHandler() );
|
||||
g_pGameSaveRestoreBlockSet->RemoveBlockHandler( GetPhysSaveRestoreBlockHandler() );
|
||||
g_pGameSaveRestoreBlockSet->RemoveBlockHandler( GetEntitySaveRestoreBlockHandler() );
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
g_pGameSaveRestoreBlockSet->RemoveBlockHandler( GetVScriptSaveRestoreBlockHandler() );
|
||||
#endif
|
||||
|
||||
ClientVoiceMgr_Shutdown();
|
||||
|
||||
@ -1635,6 +1645,10 @@ void CHLClient::LevelInitPreEntity( char const* pMapName )
|
||||
tempents->LevelInit();
|
||||
ResetToneMapping(1.0);
|
||||
|
||||
#ifdef MAPBASE
|
||||
GetClientWorldEntity()->ParseWorldMapData( engine->GetMapEntitiesString() );
|
||||
#endif
|
||||
|
||||
IGameSystem::LevelInitPreEntityAllSystems(pMapName);
|
||||
|
||||
#ifdef USES_ECON_ITEMS
|
||||
|
@ -35,6 +35,7 @@ $Project
|
||||
$Folder "Mapbase"
|
||||
{
|
||||
$File "$SRCDIR\game\shared\mapbase\mapbase_shared.cpp"
|
||||
$File "$SRCDIR\game\shared\mapbase\mapbase_usermessages.cpp"
|
||||
$File "$SRCDIR\game\shared\mapbase\mapbase_rpc.cpp"
|
||||
$File "$SRCDIR\game\shared\mapbase\mapbase_game_log.cpp"
|
||||
$File "$SRCDIR\game\shared\mapbase\MapEdit.cpp"
|
||||
@ -50,6 +51,7 @@ $Project
|
||||
$File "$SRCDIR\game\shared\mapbase\vscript_consts_weapons.cpp" [$MAPBASE_VSCRIPT]
|
||||
$File "$SRCDIR\game\shared\mapbase\weapon_custom_scripted.cpp" [$MAPBASE_VSCRIPT]
|
||||
$File "$SRCDIR\game\shared\mapbase\weapon_custom_scripted.h" [$MAPBASE_VSCRIPT]
|
||||
$File "$SRCDIR\game\shared\mapbase\logic_script_client.cpp" [$MAPBASE_VSCRIPT]
|
||||
|
||||
$File "mapbase\c_func_clientclip.cpp"
|
||||
$File "mapbase\c_func_fake_worldportal.cpp"
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "proxyentity.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "materialsystem/imaterialvar.h"
|
||||
#include "mapbase/vscript_singletons.h"
|
||||
#endif
|
||||
|
||||
extern IScriptManager *scriptmanager;
|
||||
@ -46,6 +47,11 @@ extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
|
||||
class CScriptClientEntityIterator
|
||||
{
|
||||
public:
|
||||
HSCRIPT GetLocalPlayer()
|
||||
{
|
||||
return ToHScript( C_BasePlayer::GetLocalPlayer() );
|
||||
}
|
||||
|
||||
HSCRIPT First() { return Next(NULL); }
|
||||
|
||||
HSCRIPT Next( HSCRIPT hStartEntity )
|
||||
@ -94,6 +100,7 @@ private:
|
||||
} g_ScriptEntityIterator;
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptClientEntityIterator, "CEntities", SCRIPT_SINGLETON "The global list of entities" )
|
||||
DEFINE_SCRIPTFUNC( GetLocalPlayer, "Get local player" )
|
||||
DEFINE_SCRIPTFUNC( First, "Begin an iteration over the list of entities" )
|
||||
DEFINE_SCRIPTFUNC( Next, "Continue an iteration over the list of entities, providing reference to a previously found entity" )
|
||||
DEFINE_SCRIPTFUNC( CreateByClassname, "Creates an entity by classname" )
|
||||
@ -169,7 +176,16 @@ private:
|
||||
HSCRIPT m_hFuncOnBind;
|
||||
};
|
||||
|
||||
class CMaterialProxyScriptInstanceHelper : public IScriptInstanceHelper
|
||||
{
|
||||
bool ToString( void *p, char *pBuf, int bufSize );
|
||||
void *BindOnRead( HSCRIPT hInstance, void *pOld, const char *pszId );
|
||||
};
|
||||
|
||||
CMaterialProxyScriptInstanceHelper g_MaterialProxyScriptInstanceHelper;
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptMaterialProxy, "CScriptMaterialProxy", "Material proxy for VScript" )
|
||||
DEFINE_SCRIPT_INSTANCE_HELPER( &g_MaterialProxyScriptInstanceHelper )
|
||||
DEFINE_SCRIPTFUNC( GetVarString, "Gets a material var's string value" )
|
||||
DEFINE_SCRIPTFUNC( GetVarInt, "Gets a material var's int value" )
|
||||
DEFINE_SCRIPTFUNC( GetVarFloat, "Gets a material var's float value" )
|
||||
@ -399,7 +415,20 @@ void CScriptMaterialProxy::SetVarVector( int i, const Vector &value )
|
||||
}
|
||||
|
||||
EXPOSE_INTERFACE( CScriptMaterialProxy, IMaterialProxy, "VScriptProxy" IMATERIAL_PROXY_INTERFACE_VERSION );
|
||||
#endif
|
||||
|
||||
bool CMaterialProxyScriptInstanceHelper::ToString( void *p, char *pBuf, int bufSize )
|
||||
{
|
||||
CScriptMaterialProxy *pProxy = (CScriptMaterialProxy *)p;
|
||||
V_snprintf( pBuf, bufSize, "(proxy: %s)", pProxy->GetMaterial() != NULL ? pProxy->GetMaterial()->GetName() : "<no material>" );
|
||||
return true;
|
||||
}
|
||||
|
||||
void *CMaterialProxyScriptInstanceHelper::BindOnRead( HSCRIPT hInstance, void *pOld, const char *pszId )
|
||||
{
|
||||
// TODO: Material proxy save/restore?
|
||||
return NULL;
|
||||
}
|
||||
#endif // MAPBASE_VSCRIPT
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
@ -431,6 +460,66 @@ bool DoIncludeScript( const char *pszScript, HSCRIPT hScope )
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
static bool Con_IsVisible()
|
||||
{
|
||||
return engine->Con_IsVisible();
|
||||
}
|
||||
|
||||
static bool IsWindowedMode()
|
||||
{
|
||||
return engine->IsWindowedMode();
|
||||
}
|
||||
|
||||
int ScreenTransform( const Vector& point, Vector& screen );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Input array [x,y], set normalised screen space pos. Return true if on screen
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool ScriptScreenTransform( const Vector &pos, HSCRIPT hArray )
|
||||
{
|
||||
if ( g_pScriptVM->GetNumTableEntries(hArray) >= 2 )
|
||||
{
|
||||
Vector v;
|
||||
bool r = ScreenTransform( pos, v );
|
||||
float x = 0.5f * ( 1.0f + v[0] );
|
||||
float y = 0.5f * ( 1.0f - v[1] );
|
||||
|
||||
g_pScriptVM->SetValue( hArray, ScriptVariant_t(0), x );
|
||||
g_pScriptVM->SetValue( hArray, 1, y );
|
||||
return !r;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Creates a client-side prop
|
||||
HSCRIPT CreateProp( const char *pszEntityName, const Vector &vOrigin, const char *pszModelName, int iAnim )
|
||||
{
|
||||
C_BaseAnimating *pBaseEntity = (C_BaseAnimating *)CreateEntityByName( pszEntityName );
|
||||
if (!pBaseEntity)
|
||||
return NULL;
|
||||
|
||||
pBaseEntity->SetAbsOrigin( vOrigin );
|
||||
pBaseEntity->SetModelName( pszModelName );
|
||||
if (!pBaseEntity->InitializeAsClientEntity( pszModelName, RENDER_GROUP_OPAQUE_ENTITY ))
|
||||
{
|
||||
Warning("Can't initialize %s as client entity\n", pszEntityName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pBaseEntity->SetPlaybackRate( 1.0f );
|
||||
|
||||
int iSequence = pBaseEntity->SelectWeightedSequence( (Activity)iAnim );
|
||||
|
||||
if ( iSequence != -1 )
|
||||
{
|
||||
pBaseEntity->SetSequence( iSequence );
|
||||
}
|
||||
|
||||
return ToHScript( pBaseEntity );
|
||||
}
|
||||
#endif
|
||||
|
||||
bool VScriptClientInit()
|
||||
{
|
||||
VMPROF_START
|
||||
@ -493,8 +582,19 @@ bool VScriptClientInit()
|
||||
#endif
|
||||
ScriptRegisterFunction( g_pScriptVM, GetMapName, "Get the name of the map.");
|
||||
ScriptRegisterFunction( g_pScriptVM, Time, "Get the current server time" );
|
||||
ScriptRegisterFunction( g_pScriptVM, DoUniqueString, SCRIPT_ALIAS( "UniqueString", "Generate a string guaranteed to be unique across the life of the script VM, with an optional root string." ) );
|
||||
ScriptRegisterFunction( g_pScriptVM, DoIncludeScript, "Execute a script (internal)" );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
ScriptRegisterFunction( g_pScriptVM, Con_IsVisible, "Returns true if the console is visible" );
|
||||
ScriptRegisterFunction( g_pScriptVM, ScreenWidth, "Width of the screen in pixels" );
|
||||
ScriptRegisterFunction( g_pScriptVM, ScreenHeight, "Height of the screen in pixels" );
|
||||
ScriptRegisterFunction( g_pScriptVM, IsWindowedMode, "" );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptScreenTransform, "ScreenTransform", "Get the x & y positions of a world position in screen space. Returns true if it's onscreen" );
|
||||
|
||||
ScriptRegisterFunction( g_pScriptVM, CreateProp, "Create an animating prop" );
|
||||
#endif
|
||||
|
||||
|
||||
if ( GameRules() )
|
||||
{
|
||||
GameRules()->RegisterScriptFunctions();
|
||||
@ -519,6 +619,7 @@ bool VScriptClientInit()
|
||||
g_pScriptVM->Run( g_Script_vscript_client );
|
||||
}
|
||||
|
||||
VScriptRunScript( "vscript_client", true );
|
||||
VScriptRunScript( "mapspawn", false );
|
||||
|
||||
VMPROF_SHOW( pszScriptLanguage, "virtual machine startup" );
|
||||
@ -530,6 +631,12 @@ bool VScriptClientInit()
|
||||
CGWarning( 1, CON_GROUP_VSCRIPT, "VM Did not start!\n" );
|
||||
}
|
||||
}
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
else
|
||||
{
|
||||
CGMsg( 0, CON_GROUP_VSCRIPT, "VSCRIPT CLIENT: Not starting because language is set to 'none'\n" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -571,28 +678,19 @@ public:
|
||||
virtual void LevelInitPreEntity( void )
|
||||
{
|
||||
m_bAllowEntityCreationInScripts = true;
|
||||
#ifndef MAPBASE_VSCRIPT // Now initted in C_World
|
||||
VScriptClientInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void LevelInitPostEntity( void )
|
||||
{
|
||||
m_bAllowEntityCreationInScripts = false;
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if (g_pScriptVM)
|
||||
{
|
||||
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
|
||||
if (pPlayer)
|
||||
{
|
||||
g_pScriptVM->SetValue( "player", pPlayer->GetScriptInstance() );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void LevelShutdownPostEntity( void )
|
||||
{
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
g_ScriptNetMsg->LevelShutdownPreVM();
|
||||
#endif
|
||||
VScriptClientTerm();
|
||||
}
|
||||
|
||||
|
@ -282,6 +282,10 @@ IMPLEMENT_SERVERCLASS_ST(CBaseAnimating, DT_BaseAnimating)
|
||||
|
||||
END_SEND_TABLE()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
ScriptHook_t CBaseAnimating::g_Hook_OnServerRagdoll;
|
||||
#endif
|
||||
|
||||
BEGIN_ENT_SCRIPTDESC( CBaseAnimating, CBaseEntity, "Animating models" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( LookupAttachment, "Get the named attachement id" )
|
||||
@ -333,6 +337,11 @@ BEGIN_ENT_SCRIPTDESC( CBaseAnimating, CBaseEntity, "Animating models" )
|
||||
DEFINE_SCRIPTFUNC( BecomeRagdollOnClient, "" )
|
||||
DEFINE_SCRIPTFUNC( IsRagdoll, "" )
|
||||
DEFINE_SCRIPTFUNC( CanBecomeRagdoll, "" )
|
||||
|
||||
BEGIN_SCRIPTHOOK( CBaseAnimating::g_Hook_OnServerRagdoll, "OnServerRagdoll", FIELD_VOID, "Called when this entity creates/turns into a server-side ragdoll." )
|
||||
DEFINE_SCRIPTHOOK_PARAM( "ragdoll", FIELD_HSCRIPT )
|
||||
DEFINE_SCRIPTHOOK_PARAM( "submodel", FIELD_BOOLEAN )
|
||||
END_SCRIPTHOOK()
|
||||
#endif
|
||||
END_SCRIPTDESC();
|
||||
|
||||
|
@ -209,6 +209,8 @@ public:
|
||||
// For VScript
|
||||
int GetSkin() { return m_nSkin; }
|
||||
void SetSkin( int iSkin ) { m_nSkin = iSkin; }
|
||||
|
||||
static ScriptHook_t g_Hook_OnServerRagdoll;
|
||||
#endif
|
||||
|
||||
// These return the attachment in the space of the entity
|
||||
|
@ -623,18 +623,6 @@ CBaseEntity *CBaseEntity::GetFollowedEntity()
|
||||
return GetMoveParent();
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
void CBaseEntity::ScriptFollowEntity( HSCRIPT hBaseEntity, bool bBoneMerge )
|
||||
{
|
||||
FollowEntity( ToEnt( hBaseEntity ), bBoneMerge );
|
||||
}
|
||||
|
||||
HSCRIPT CBaseEntity::ScriptGetFollowedEntity()
|
||||
{
|
||||
return ToHScript( GetFollowedEntity() );
|
||||
}
|
||||
#endif
|
||||
|
||||
void CBaseEntity::SetClassname( const char *className )
|
||||
{
|
||||
m_iClassname = AllocPooledString( className );
|
||||
@ -2190,7 +2178,7 @@ BEGIN_DATADESC_NO_BASE( CBaseEntity )
|
||||
DEFINE_THINKFUNC( ShadowCastDistThink ),
|
||||
DEFINE_THINKFUNC( ScriptThink ),
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DEFINE_THINKFUNC( ScriptThinkH ),
|
||||
DEFINE_THINKFUNC( ScriptContextThink ),
|
||||
#endif
|
||||
|
||||
#ifdef MAPBASE
|
||||
@ -2360,6 +2348,7 @@ BEGIN_ENT_SCRIPTDESC_ROOT( CBaseEntity, "Root class of all server-side entities"
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColorB, "SetRenderColorB", "Set the render color's B value" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetAlpha, "SetRenderAlpha", "Set the render color's alpha value" )
|
||||
|
||||
// LEGACY
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorVector, "GetColorVector", SCRIPT_HIDE )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorR, "GetColorR", SCRIPT_HIDE )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorG, "GetColorG", SCRIPT_HIDE )
|
||||
@ -2370,6 +2359,7 @@ BEGIN_ENT_SCRIPTDESC_ROOT( CBaseEntity, "Root class of all server-side entities"
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColorG, "SetColorG", SCRIPT_HIDE )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColorB, "SetColorB", SCRIPT_HIDE )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetAlpha, "SetAlpha", SCRIPT_HIDE )
|
||||
// END LEGACY
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRenderMode, "GetRenderMode", "Get render mode" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetRenderMode, "SetRenderMode", "Set render mode" )
|
||||
@ -2442,6 +2432,7 @@ BEGIN_ENT_SCRIPTDESC_ROOT( CBaseEntity, "Root class of all server-side entities"
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetThinkFunction, "SetThinkFunction", "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptStopThinkFunction, "StopThinkFunction", "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetContextThink, "SetContextThink", "Set a think function on this entity." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetThink, "SetThink", "" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptStopThink, "StopThink", "" )
|
||||
|
||||
@ -2590,11 +2581,12 @@ void CBaseEntity::UpdateOnRemove( void )
|
||||
m_hScriptInstance = NULL;
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if ( m_hfnThink )
|
||||
FOR_EACH_VEC( m_ScriptThinkFuncs, i )
|
||||
{
|
||||
g_pScriptVM->ReleaseScript( m_hfnThink );
|
||||
m_hfnThink = NULL;
|
||||
HSCRIPT h = m_ScriptThinkFuncs[i].m_hfnThink;
|
||||
if ( h ) g_pScriptVM->ReleaseScript( h );
|
||||
}
|
||||
m_ScriptThinkFuncs.Purge();
|
||||
#endif // MAPBASE_VSCRIPT
|
||||
}
|
||||
}
|
||||
@ -8653,60 +8645,172 @@ void CBaseEntity::ScriptStopThinkFunction()
|
||||
SetContextThink( NULL, TICK_NEVER_THINK, "ScriptThink" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseEntity::ScriptThinkH()
|
||||
|
||||
static inline void ScriptStopContextThink( scriptthinkfunc_t *context )
|
||||
{
|
||||
ScriptVariant_t varThinkRetVal;
|
||||
if ( g_pScriptVM->ExecuteFunction(m_hfnThink, NULL, 0, &varThinkRetVal, NULL, true) == SCRIPT_ERROR )
|
||||
{
|
||||
DevWarning("%s FAILED to call script think function (invalid closure)!\n", GetDebugName());
|
||||
ScriptStopThink();
|
||||
return;
|
||||
}
|
||||
|
||||
float flThinkFrequency = 0.f;
|
||||
if ( !varThinkRetVal.AssignTo(&flThinkFrequency) )
|
||||
{
|
||||
// no return value stops thinking
|
||||
ScriptStopThink();
|
||||
return;
|
||||
}
|
||||
|
||||
SetNextThink( gpGlobals->curtime + flThinkFrequency, "ScriptThinkH" );
|
||||
g_pScriptVM->ReleaseScript( context->m_hfnThink );
|
||||
context->m_hfnThink = NULL;
|
||||
context->m_nNextThinkTick = TICK_NEVER_THINK;
|
||||
}
|
||||
|
||||
void CBaseEntity::ScriptSetThink( HSCRIPT hFunc, float flTime )
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseEntity::ScriptContextThink()
|
||||
{
|
||||
if ( hFunc )
|
||||
float flNextThink = FLT_MAX;
|
||||
int nScheduledTick = 0;
|
||||
|
||||
for ( int i = m_ScriptThinkFuncs.Count(); i--; )
|
||||
{
|
||||
if ( m_hfnThink )
|
||||
scriptthinkfunc_t *cur = &m_ScriptThinkFuncs[i];
|
||||
|
||||
if ( cur->m_nNextThinkTick == TICK_NEVER_THINK )
|
||||
continue;
|
||||
|
||||
if ( cur->m_nNextThinkTick > gpGlobals->tickcount )
|
||||
{
|
||||
// release old func
|
||||
ScriptStopThink();
|
||||
// There is more to execute, don't stop thinking if the rest are done.
|
||||
|
||||
// also find the shortest schedule
|
||||
if ( !nScheduledTick || nScheduledTick > cur->m_nNextThinkTick )
|
||||
{
|
||||
nScheduledTick = cur->m_nNextThinkTick;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// no type check here, print error on call instead
|
||||
m_hfnThink = hFunc;
|
||||
ScriptVariant_t varReturn;
|
||||
|
||||
flTime = max( 0, flTime );
|
||||
SetContextThink( &CBaseEntity::ScriptThinkH, gpGlobals->curtime + flTime, "ScriptThinkH" );
|
||||
if ( cur->m_bNoParam )
|
||||
{
|
||||
if ( g_pScriptVM->Call( cur->m_hfnThink, NULL, true, &varReturn ) == SCRIPT_ERROR )
|
||||
{
|
||||
ScriptStopContextThink(cur);
|
||||
m_ScriptThinkFuncs.Remove(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( g_pScriptVM->Call( cur->m_hfnThink, NULL, true, &varReturn, m_hScriptInstance ) == SCRIPT_ERROR )
|
||||
{
|
||||
ScriptStopContextThink(cur);
|
||||
m_ScriptThinkFuncs.Remove(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
float flReturn;
|
||||
if ( !varReturn.AssignTo( &flReturn ) )
|
||||
{
|
||||
ScriptStopContextThink(cur);
|
||||
m_ScriptThinkFuncs.Remove(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( flReturn < 0.0f )
|
||||
{
|
||||
ScriptStopContextThink(cur);
|
||||
m_ScriptThinkFuncs.Remove(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
// find the shortest delay
|
||||
if ( flReturn < flNextThink )
|
||||
{
|
||||
flNextThink = flReturn;
|
||||
}
|
||||
|
||||
cur->m_nNextThinkTick = TIME_TO_TICKS( gpGlobals->curtime + flReturn );
|
||||
}
|
||||
|
||||
if ( flNextThink < FLT_MAX )
|
||||
{
|
||||
SetNextThink( gpGlobals->curtime + flNextThink, "ScriptContextThink" );
|
||||
}
|
||||
else if ( nScheduledTick )
|
||||
{
|
||||
SetNextThink( TICKS_TO_TIME( nScheduledTick ), "ScriptContextThink" );
|
||||
}
|
||||
else
|
||||
{
|
||||
ScriptStopThink();
|
||||
SetNextThink( TICK_NEVER_THINK, "ScriptContextThink" );
|
||||
}
|
||||
}
|
||||
|
||||
// see ScriptSetThink
|
||||
static bool s_bScriptContextThinkNoParam = false;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseEntity::ScriptSetContextThink( const char* szContext, HSCRIPT hFunc, float flTime )
|
||||
{
|
||||
scriptthinkfunc_t th;
|
||||
V_memset( &th, 0x0, sizeof(scriptthinkfunc_t) );
|
||||
unsigned short hash = ( szContext && *szContext ) ? HashString( szContext ) : 0;
|
||||
bool bFound = false;
|
||||
|
||||
FOR_EACH_VEC( m_ScriptThinkFuncs, i )
|
||||
{
|
||||
scriptthinkfunc_t f = m_ScriptThinkFuncs[i];
|
||||
if ( hash == f.m_iContextHash )
|
||||
{
|
||||
th = f;
|
||||
m_ScriptThinkFuncs.Remove(i); // reorder
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( hFunc )
|
||||
{
|
||||
float nextthink = gpGlobals->curtime + flTime;
|
||||
|
||||
th.m_bNoParam = s_bScriptContextThinkNoParam;
|
||||
th.m_hfnThink = hFunc;
|
||||
th.m_iContextHash = hash;
|
||||
th.m_nNextThinkTick = TIME_TO_TICKS( nextthink );
|
||||
|
||||
m_ScriptThinkFuncs.AddToHead( th );
|
||||
|
||||
int nexttick = GetNextThinkTick( RegisterThinkContext( "ScriptContextThink" ) );
|
||||
|
||||
// sooner than next think
|
||||
if ( nexttick <= 0 || nexttick > th.m_nNextThinkTick )
|
||||
{
|
||||
SetContextThink( &CBaseEntity::ScriptContextThink, nextthink, "ScriptContextThink" );
|
||||
}
|
||||
}
|
||||
// null func input, think exists
|
||||
else if ( bFound )
|
||||
{
|
||||
ScriptStopContextThink( &th );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// m_bNoParam and s_bScriptContextThinkNoParam exist only to keep backwards compatibility
|
||||
// and are an alternative to this script closure:
|
||||
//
|
||||
// function CBaseEntity::SetThink( func, time )
|
||||
// {
|
||||
// SetContextThink( "", function(_){ return func() }, time )
|
||||
// }
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseEntity::ScriptSetThink( HSCRIPT hFunc, float time )
|
||||
{
|
||||
s_bScriptContextThinkNoParam = true;
|
||||
ScriptSetContextThink( NULL, hFunc, time );
|
||||
s_bScriptContextThinkNoParam = false;
|
||||
}
|
||||
|
||||
void CBaseEntity::ScriptStopThink()
|
||||
{
|
||||
if (m_hfnThink)
|
||||
{
|
||||
g_pScriptVM->ReleaseScript(m_hfnThink);
|
||||
m_hfnThink = NULL;
|
||||
}
|
||||
SetContextThink( NULL, TICK_NEVER_THINK, "ScriptThinkH" );
|
||||
ScriptSetContextThink( NULL, NULL, 0.0f );
|
||||
}
|
||||
|
||||
#endif // MAPBASE_VSCRIPT
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -8735,51 +8839,6 @@ HSCRIPT CBaseEntity::GetScriptScope()
|
||||
return m_ScriptScope;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
HSCRIPT CBaseEntity::GetOrCreatePrivateScriptScope()
|
||||
{
|
||||
ValidateScriptScope();
|
||||
return m_ScriptScope;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseEntity::ScriptSetParent(HSCRIPT hParent, const char *szAttachment)
|
||||
{
|
||||
CBaseEntity *pParent = ToEnt(hParent);
|
||||
if ( !pParent )
|
||||
{
|
||||
SetParent(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
// if an attachment is specified, the parent needs to be CBaseAnimating
|
||||
if ( szAttachment && szAttachment[0] != '\0' )
|
||||
{
|
||||
CBaseAnimating *pAnimating = pParent->GetBaseAnimating();
|
||||
if ( !pAnimating )
|
||||
{
|
||||
Warning("ERROR: Tried to set parent for entity %s (%s), but its parent has no model.\n", GetClassname(), GetDebugName());
|
||||
return;
|
||||
}
|
||||
|
||||
int iAttachment = pAnimating->LookupAttachment(szAttachment);
|
||||
if ( iAttachment <= 0 )
|
||||
{
|
||||
Warning("ERROR: Tried to set parent for entity %s (%s), but it has no attachment named %s.\n", GetClassname(), GetDebugName(), szAttachment);
|
||||
return;
|
||||
}
|
||||
|
||||
SetParent(pParent, iAttachment);
|
||||
SetMoveType(MOVETYPE_NONE);
|
||||
return;
|
||||
}
|
||||
|
||||
SetParent(pParent);
|
||||
}
|
||||
#endif
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
HSCRIPT CBaseEntity::ScriptGetMoveParent(void)
|
||||
@ -10029,6 +10088,7 @@ void CBaseEntity::RunOnPostSpawnScripts(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef MAPBASE_VSCRIPT // This is shared now
|
||||
HSCRIPT CBaseEntity::GetScriptOwnerEntity()
|
||||
{
|
||||
return ToHScript(GetOwnerEntity());
|
||||
@ -10038,6 +10098,7 @@ void CBaseEntity::SetScriptOwnerEntity(HSCRIPT pOwner)
|
||||
{
|
||||
SetOwnerEntity(ToEnt(pOwner));
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// VScript access to model's key values
|
||||
@ -10204,46 +10265,6 @@ const char *CBaseEntity::ScriptGetKeyValue( const char *pszKeyName )
|
||||
return szValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
const Vector& CBaseEntity::ScriptGetColorVector()
|
||||
{
|
||||
static Vector vecColor;
|
||||
vecColor.Init( m_clrRender.GetR(), m_clrRender.GetG(), m_clrRender.GetB() );
|
||||
return vecColor;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseEntity::ScriptSetColorVector( const Vector& vecColor )
|
||||
{
|
||||
SetRenderColor( vecColor.x, vecColor.y, vecColor.z );
|
||||
}
|
||||
|
||||
void CBaseEntity::ScriptSetColor( int r, int g, int b )
|
||||
{
|
||||
SetRenderColor( r, g, b );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vscript: Gets the entity matrix transform
|
||||
//-----------------------------------------------------------------------------
|
||||
HSCRIPT CBaseEntity::ScriptEntityToWorldTransform( void )
|
||||
{
|
||||
return g_pScriptVM->RegisterInstance( &EntityToWorldTransform() );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vscript: Gets the entity's physics object if it has one
|
||||
//-----------------------------------------------------------------------------
|
||||
HSCRIPT CBaseEntity::ScriptGetPhysicsObject( void )
|
||||
{
|
||||
if (VPhysicsGetObject())
|
||||
return g_pScriptVM->RegisterInstance( VPhysicsGetObject() );
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vscript: Dispatch an interaction to the entity
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -338,6 +338,16 @@ struct thinkfunc_t
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
};
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
struct scriptthinkfunc_t
|
||||
{
|
||||
HSCRIPT m_hfnThink;
|
||||
unsigned short m_iContextHash;
|
||||
int m_nNextThinkTick;
|
||||
bool m_bNoParam;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct EmitSound_t;
|
||||
struct rotatingpushmove_t;
|
||||
|
||||
@ -1988,11 +1998,12 @@ public:
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
void ScriptSetThinkFunction(const char *szFunc, float time);
|
||||
void ScriptStopThinkFunction();
|
||||
void ScriptSetThink(HSCRIPT hFunc, float time);
|
||||
void ScriptSetContextThink( const char* szContext, HSCRIPT hFunc, float time );
|
||||
void ScriptSetThink( HSCRIPT hFunc, float time );
|
||||
void ScriptStopThink();
|
||||
void ScriptThinkH();
|
||||
void ScriptContextThink();
|
||||
private:
|
||||
HSCRIPT m_hfnThink;
|
||||
CUtlVector< scriptthinkfunc_t > m_ScriptThinkFuncs;
|
||||
public:
|
||||
#endif
|
||||
const char* GetScriptId();
|
||||
|
@ -960,18 +960,6 @@ void CFuncRotating::UpdateSpeed( float flNewSpeed )
|
||||
RampPitchVol();
|
||||
}
|
||||
|
||||
#ifdef MAPBASE
|
||||
QAngle angNormalizedAngles = GetLocalAngles();
|
||||
if (m_vecMoveAng.x)
|
||||
angNormalizedAngles.x = AngleNormalize( angNormalizedAngles.x );
|
||||
if (m_vecMoveAng.y)
|
||||
angNormalizedAngles.y = AngleNormalize( angNormalizedAngles.y );
|
||||
if (m_vecMoveAng.z)
|
||||
angNormalizedAngles.z = AngleNormalize( angNormalizedAngles.z );
|
||||
|
||||
SetLocalAngles(angNormalizedAngles);
|
||||
#endif
|
||||
|
||||
SetLocalAngularVelocity( m_vecMoveAng * m_flSpeed );
|
||||
}
|
||||
|
||||
@ -1102,6 +1090,18 @@ void CFuncRotating::RotateMove( void )
|
||||
{
|
||||
SetMoveDoneTime( 10 );
|
||||
|
||||
#ifdef MAPBASE
|
||||
QAngle angNormalizedAngles = GetLocalAngles();
|
||||
if (m_vecMoveAng.x)
|
||||
angNormalizedAngles.x = AngleNormalize( angNormalizedAngles.x );
|
||||
if (m_vecMoveAng.y)
|
||||
angNormalizedAngles.y = AngleNormalize( angNormalizedAngles.y );
|
||||
if (m_vecMoveAng.z)
|
||||
angNormalizedAngles.z = AngleNormalize( angNormalizedAngles.z );
|
||||
|
||||
SetLocalAngles(angNormalizedAngles);
|
||||
#endif
|
||||
|
||||
if ( m_bStopAtStartPos )
|
||||
{
|
||||
SetMoveDoneTime( GetNextMoveInterval() );
|
||||
|
@ -906,7 +906,7 @@ CEventQueue::AddEvent( CBaseEntity *target, const char *targetInput, variant_t V
|
||||
AddEvent( newEvent );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
return reinterpret_cast<intptr_t>(newEvent);
|
||||
return reinterpret_cast<intptr_t>(newEvent); // POINTER_TO_INT
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1257,7 +1257,10 @@ void ServiceEventQueue( void )
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
//-----------------------------------------------------------------------------
|
||||
// Remove events on entity by input.
|
||||
// Remove pending events on entity by input.
|
||||
//
|
||||
// Also removes events that were targeted with their debug name (classname when unnamed).
|
||||
// E.g. CancelEventsByInput( pRelay, "Trigger" ) removes all pending logic_relay "Trigger" events.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CEventQueue::CancelEventsByInput( CBaseEntity *pTarget, const char *szInput )
|
||||
{
|
||||
@ -1292,9 +1295,6 @@ void CEventQueue::CancelEventsByInput( CBaseEntity *pTarget, const char *szInput
|
||||
|
||||
bool CEventQueue::RemoveEvent( intptr_t event )
|
||||
{
|
||||
if ( !event )
|
||||
return false;
|
||||
|
||||
EventQueuePrioritizedEvent_t *pe = reinterpret_cast<EventQueuePrioritizedEvent_t*>(event); // INT_TO_POINTER
|
||||
|
||||
for ( EventQueuePrioritizedEvent_t *pCur = m_Events.m_pNext; pCur; pCur = pCur->m_pNext )
|
||||
@ -1312,9 +1312,6 @@ bool CEventQueue::RemoveEvent( intptr_t event )
|
||||
|
||||
float CEventQueue::GetTimeLeft( intptr_t event )
|
||||
{
|
||||
if ( !event )
|
||||
return 0.f;
|
||||
|
||||
EventQueuePrioritizedEvent_t *pe = reinterpret_cast<EventQueuePrioritizedEvent_t*>(event); // INT_TO_POINTER
|
||||
|
||||
for ( EventQueuePrioritizedEvent_t *pCur = m_Events.m_pNext; pCur; pCur = pCur->m_pNext )
|
||||
|
@ -3196,7 +3196,11 @@ float CServerGameClients::ProcessUsercmds( edict_t *player, bf_read *buf, int nu
|
||||
for ( i = totalcmds - 1; i >= 0; i-- )
|
||||
{
|
||||
to = &cmds[ i ];
|
||||
#if defined( MAPBASE_VSCRIPT )
|
||||
ReadUsercmd( buf, to, from, pPlayer ); // Tell whose UserCmd it is
|
||||
#else
|
||||
ReadUsercmd( buf, to, from );
|
||||
#endif
|
||||
from = to;
|
||||
}
|
||||
|
||||
|
@ -908,7 +908,7 @@ bool CZombie::IsSquashed( const CTakeDamageInfo &info )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( info.GetDamageType() & DMG_CRUSH )
|
||||
if( info.GetDamageType() & DMG_CRUSH && info.GetInflictor() ) // Mapbase - Fixes a crash with inflictor-less crush damage
|
||||
{
|
||||
IPhysicsObject *pCrusher = info.GetInflictor()->VPhysicsGetObject();
|
||||
if( pCrusher && pCrusher->GetMass() >= ZOMBIE_SQUASH_MASS && info.GetInflictor()->WorldSpaceCenter().z > EyePosition().z )
|
||||
|
@ -56,6 +56,9 @@ const float ATTACHED_DAMPING_SCALE = 50.0f;
|
||||
#define SF_RAGDOLLPROP_MOTIONDISABLED 0x4000
|
||||
#define SF_RAGDOLLPROP_ALLOW_STRETCH 0x8000
|
||||
#define SF_RAGDOLLPROP_STARTASLEEP 0x10000
|
||||
#ifdef MAPBASE
|
||||
#define SF_RAGDOLLPROP_FIXED_CONSTRAINTS 0x20000
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Networking
|
||||
@ -166,6 +169,7 @@ BEGIN_ENT_SCRIPTDESC( CRagdollProp, CBaseAnimating, "Ragdoll physics prop." )
|
||||
DEFINE_SCRIPTFUNC( SetSourceClassName, "Sets the ragdoll's source classname." )
|
||||
DEFINE_SCRIPTFUNC( HasPhysgunInteraction, "Checks if the ragdoll has the specified interaction." )
|
||||
|
||||
// TODO: Proper shared ragdoll funcs?
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRagdollObject, "GetRagdollObject", "Gets the ragdoll object of the specified index." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRagdollObjectCount, "GetRagdollObjectCount", "Gets the number of ragdoll objects on this ragdoll." )
|
||||
|
||||
@ -758,7 +762,11 @@ void CRagdollProp::InitRagdoll( const Vector &forceVector, int forceBone, const
|
||||
params.pCurrentBones = pBoneToWorld;
|
||||
params.jointFrictionScale = 1.0;
|
||||
params.allowStretch = HasSpawnFlags(SF_RAGDOLLPROP_ALLOW_STRETCH);
|
||||
#ifdef MAPBASE
|
||||
params.fixedConstraints = HasSpawnFlags(SF_RAGDOLLPROP_FIXED_CONSTRAINTS);
|
||||
#else
|
||||
params.fixedConstraints = false;
|
||||
#endif
|
||||
RagdollCreate( m_ragdoll, params, physenv );
|
||||
RagdollApplyAnimationAsVelocity( m_ragdoll, pPrevBones, pBoneToWorld, dt );
|
||||
if ( m_anglesOverrideString != NULL_STRING && Q_strlen(m_anglesOverrideString.ToCStr()) > 0 )
|
||||
@ -1353,6 +1361,16 @@ CBaseAnimating *CreateServerRagdollSubmodel( CBaseAnimating *pOwner, const char
|
||||
matrix3x4_t pBoneToWorld[MAXSTUDIOBONES], pBoneToWorldNext[MAXSTUDIOBONES];
|
||||
pRagdoll->ResetSequence( 0 );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
// Hook for pre-spawn ragdolling
|
||||
if (pOwner->m_ScriptScope.IsInitialized() && CBaseAnimating::g_Hook_OnServerRagdoll.CanRunInScope( pOwner->m_ScriptScope ))
|
||||
{
|
||||
// ragdoll, submodel
|
||||
ScriptVariant_t args[] = { ScriptVariant_t( pRagdoll->GetScriptInstance() ), true };
|
||||
CBaseAnimating::g_Hook_OnServerRagdoll.Call( pOwner->m_ScriptScope, NULL, args );
|
||||
}
|
||||
#endif
|
||||
|
||||
// let bone merging do the work of copying everything over for us
|
||||
pRagdoll->SetParent( pOwner );
|
||||
pRagdoll->SetupBones( pBoneToWorld, BONE_USED_BY_ANYTHING );
|
||||
@ -1377,6 +1395,16 @@ CBaseEntity *CreateServerRagdoll( CBaseAnimating *pAnimating, int forceBone, con
|
||||
pRagdoll->CopyAnimationDataFrom( pAnimating );
|
||||
pRagdoll->SetOwnerEntity( pAnimating );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
// Hook for pre-spawn ragdolling
|
||||
if (pAnimating->m_ScriptScope.IsInitialized() && CBaseAnimating::g_Hook_OnServerRagdoll.CanRunInScope( pAnimating->m_ScriptScope ))
|
||||
{
|
||||
// ragdoll, submodel
|
||||
ScriptVariant_t args[] = { ScriptVariant_t( pRagdoll->GetScriptInstance() ), false };
|
||||
CBaseAnimating::g_Hook_OnServerRagdoll.Call( pAnimating->m_ScriptScope, NULL, args );
|
||||
}
|
||||
#endif
|
||||
|
||||
pRagdoll->InitRagdollAnimation();
|
||||
matrix3x4_t pBoneToWorld[MAXSTUDIOBONES], pBoneToWorldNext[MAXSTUDIOBONES];
|
||||
|
||||
|
@ -31,6 +31,7 @@ $Project
|
||||
$Folder "Mapbase"
|
||||
{
|
||||
$File "$SRCDIR\game\shared\mapbase\mapbase_shared.cpp"
|
||||
$File "$SRCDIR\game\shared\mapbase\mapbase_usermessages.cpp"
|
||||
$File "$SRCDIR\game\shared\mapbase\mapbase_rpc.cpp"
|
||||
$File "$SRCDIR\game\shared\mapbase\mapbase_game_log.cpp"
|
||||
$File "$SRCDIR\game\shared\mapbase\MapEdit.cpp"
|
||||
@ -46,6 +47,7 @@ $Project
|
||||
$File "$SRCDIR\game\shared\mapbase\vscript_consts_weapons.cpp" [$MAPBASE_VSCRIPT]
|
||||
$File "$SRCDIR\game\shared\mapbase\weapon_custom_scripted.cpp" [$MAPBASE_VSCRIPT]
|
||||
$File "$SRCDIR\game\shared\mapbase\weapon_custom_scripted.h" [$MAPBASE_VSCRIPT]
|
||||
$File "$SRCDIR\game\shared\mapbase\logic_script_client.cpp" [$MAPBASE_VSCRIPT]
|
||||
|
||||
$File "mapbase\ai_grenade.cpp"
|
||||
$File "mapbase\ai_grenade.h"
|
||||
|
@ -13,11 +13,11 @@
|
||||
#include "eventqueue.h"
|
||||
#include "characterset.h"
|
||||
#include "sceneentity.h" // for exposing scene precache function
|
||||
#include "isaverestore.h"
|
||||
#include "gamerules.h"
|
||||
#include "vscript_server.nut"
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
#include "world.h"
|
||||
#include "mapbase/vscript_singletons.h"
|
||||
#endif
|
||||
|
||||
extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
|
||||
@ -246,451 +246,6 @@ CScriptKeyValues::~CScriptKeyValues( )
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
#define RETURN_IF_CANNOT_DRAW_OVERLAY\
|
||||
if (engine->IsPaused())\
|
||||
{\
|
||||
CGWarning( 1, CON_GROUP_VSCRIPT, "debugoverlay: cannot draw while the game is paused!\n");\
|
||||
return;\
|
||||
}
|
||||
class CDebugOverlayScriptHelper
|
||||
{
|
||||
public:
|
||||
|
||||
void Box(const Vector &origin, const Vector &mins, const Vector &maxs, int r, int g, int b, int a, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddBoxOverlay(origin, mins, maxs, vec3_angle, r, g, b, a, flDuration);
|
||||
}
|
||||
}
|
||||
void BoxDirection(const Vector &origin, const Vector &mins, const Vector &maxs, const Vector &forward, int r, int g, int b, int a, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
QAngle f_angles = vec3_angle;
|
||||
f_angles.y = UTIL_VecToYaw(forward);
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddBoxOverlay(origin, mins, maxs, f_angles, r, g, b, a, flDuration);
|
||||
}
|
||||
}
|
||||
void BoxAngles(const Vector &origin, const Vector &mins, const Vector &maxs, const QAngle &angles, int r, int g, int b, int a, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddBoxOverlay(origin, mins, maxs, angles, r, g, b, a, flDuration);
|
||||
}
|
||||
}
|
||||
void SweptBox(const Vector& start, const Vector& end, const Vector& mins, const Vector& maxs, const QAngle & angles, int r, int g, int b, int a, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddSweptBoxOverlay(start, end, mins, maxs, angles, r, g, b, a, flDuration);
|
||||
}
|
||||
}
|
||||
void EntityBounds(HSCRIPT pEntity, int r, int g, int b, int a, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
CBaseEntity *pEnt = ToEnt(pEntity);
|
||||
if (!pEnt)
|
||||
return;
|
||||
|
||||
const CCollisionProperty *pCollide = pEnt->CollisionProp();
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddBoxOverlay(pCollide->GetCollisionOrigin(), pCollide->OBBMins(), pCollide->OBBMaxs(), pCollide->GetCollisionAngles(), r, g, b, a, flDuration);
|
||||
}
|
||||
}
|
||||
void Line(const Vector &origin, const Vector &target, int r, int g, int b, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddLineOverlay(origin, target, r, g, b, noDepthTest, flDuration);
|
||||
}
|
||||
}
|
||||
void Triangle(const Vector &p1, const Vector &p2, const Vector &p3, int r, int g, int b, int a, bool noDepthTest, float duration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddTriangleOverlay(p1, p2, p3, r, g, b, a, noDepthTest, duration);
|
||||
}
|
||||
}
|
||||
void EntityText(int entityID, int text_offset, const char *text, float flDuration, int r, int g, int b, int a)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddEntityTextOverlay(entityID, text_offset, flDuration,
|
||||
(int)clamp(r * 255.f, 0.f, 255.f), (int)clamp(g * 255.f, 0.f, 255.f), (int)clamp(b * 255.f, 0.f, 255.f),
|
||||
(int)clamp(a * 255.f, 0.f, 255.f), text);
|
||||
}
|
||||
}
|
||||
void EntityTextAtPosition(const Vector &origin, int text_offset, const char *text, float flDuration, int r, int g, int b, int a)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddTextOverlayRGB(origin, text_offset, flDuration, r, g, b, a, "%s", text);
|
||||
}
|
||||
}
|
||||
void Grid(const Vector &vPosition)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddGridOverlay(vPosition);
|
||||
}
|
||||
}
|
||||
void Text(const Vector &origin, const char *text, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddTextOverlay(origin, flDuration, "%s", text);
|
||||
}
|
||||
}
|
||||
void ScreenText(float fXpos, float fYpos, const char *text, int r, int g, int b, int a, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->AddScreenTextOverlay(fXpos, fYpos, flDuration, r, g, b, a, text);
|
||||
}
|
||||
}
|
||||
void Cross3D(const Vector &position, float size, int r, int g, int b, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
Line( position + Vector(size,0,0), position - Vector(size,0,0), r, g, b, noDepthTest, flDuration );
|
||||
Line( position + Vector(0,size,0), position - Vector(0,size,0), r, g, b, noDepthTest, flDuration );
|
||||
Line( position + Vector(0,0,size), position - Vector(0,0,size), r, g, b, noDepthTest, flDuration );
|
||||
}
|
||||
void Cross3DOriented(const Vector &position, const QAngle &angles, float size, int r, int g, int b, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
Vector forward, right, up;
|
||||
AngleVectors( angles, &forward, &right, &up );
|
||||
|
||||
forward *= size;
|
||||
right *= size;
|
||||
up *= size;
|
||||
|
||||
Line( position + right, position - right, r, g, b, noDepthTest, flDuration );
|
||||
Line( position + forward, position - forward, r, g, b, noDepthTest, flDuration );
|
||||
Line( position + up, position - up, r, g, b, noDepthTest, flDuration );
|
||||
}
|
||||
void DrawTickMarkedLine(const Vector &startPos, const Vector &endPos, float tickDist, int tickTextDist, int r, int g, int b, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
Vector lineDir = (endPos - startPos);
|
||||
float lineDist = VectorNormalize(lineDir);
|
||||
int numTicks = lineDist / tickDist;
|
||||
|
||||
Vector upVec = Vector(0,0,4);
|
||||
Vector sideDir;
|
||||
Vector tickPos = startPos;
|
||||
int tickTextCnt = 0;
|
||||
|
||||
CrossProduct(lineDir, upVec, sideDir);
|
||||
|
||||
Line(startPos, endPos, r, g, b, noDepthTest, flDuration);
|
||||
|
||||
for (int i = 0; i<numTicks + 1; i++)
|
||||
{
|
||||
Vector tickLeft = tickPos - sideDir;
|
||||
Vector tickRight = tickPos + sideDir;
|
||||
|
||||
if (tickTextCnt == tickTextDist)
|
||||
{
|
||||
char text[25];
|
||||
Q_snprintf(text, sizeof(text), "%i", i);
|
||||
Vector textPos = tickLeft + Vector(0, 0, 8);
|
||||
Line(tickLeft, tickRight, 255, 255, 255, noDepthTest, flDuration);
|
||||
Text(textPos, text, flDuration);
|
||||
tickTextCnt = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Line(tickLeft, tickRight, r, g, b, noDepthTest, flDuration);
|
||||
}
|
||||
|
||||
tickTextCnt++;
|
||||
|
||||
tickPos = tickPos + (tickDist * lineDir);
|
||||
}
|
||||
}
|
||||
void HorzArrow(const Vector &startPos, const Vector &endPos, float width, int r, int g, int b, int a, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
Vector lineDir = (endPos - startPos);
|
||||
VectorNormalize( lineDir );
|
||||
Vector upVec = Vector( 0, 0, 1 );
|
||||
Vector sideDir;
|
||||
float radius = width / 2.0;
|
||||
|
||||
CrossProduct(lineDir, upVec, sideDir);
|
||||
|
||||
Vector p1 = startPos - sideDir * radius;
|
||||
Vector p2 = endPos - lineDir * width - sideDir * radius;
|
||||
Vector p3 = endPos - lineDir * width - sideDir * width;
|
||||
Vector p4 = endPos;
|
||||
Vector p5 = endPos - lineDir * width + sideDir * width;
|
||||
Vector p6 = endPos - lineDir * width + sideDir * radius;
|
||||
Vector p7 = startPos + sideDir * radius;
|
||||
|
||||
Line(p1, p2, r,g,b,noDepthTest,flDuration);
|
||||
Line(p2, p3, r,g,b,noDepthTest,flDuration);
|
||||
Line(p3, p4, r,g,b,noDepthTest,flDuration);
|
||||
Line(p4, p5, r,g,b,noDepthTest,flDuration);
|
||||
Line(p5, p6, r,g,b,noDepthTest,flDuration);
|
||||
Line(p6, p7, r,g,b,noDepthTest,flDuration);
|
||||
|
||||
if ( a > 0 )
|
||||
{
|
||||
Triangle( p5, p4, p3, r, g, b, a, noDepthTest, flDuration );
|
||||
Triangle( p1, p7, p6, r, g, b, a, noDepthTest, flDuration );
|
||||
Triangle( p6, p2, p1, r, g, b, a, noDepthTest, flDuration );
|
||||
|
||||
Triangle( p3, p4, p5, r, g, b, a, noDepthTest, flDuration );
|
||||
Triangle( p6, p7, p1, r, g, b, a, noDepthTest, flDuration );
|
||||
Triangle( p1, p2, p6, r, g, b, a, noDepthTest, flDuration );
|
||||
}
|
||||
}
|
||||
void YawArrow(const Vector &startPos, float yaw, float length, float width, int r, int g, int b, int a, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
Vector forward = UTIL_YawToVector( yaw );
|
||||
HorzArrow( startPos, startPos + forward * length, width, r, g, b, a, noDepthTest, flDuration );
|
||||
}
|
||||
void VertArrow(const Vector &startPos, const Vector &endPos, float width, int r, int g, int b, int a, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
Vector lineDir = (endPos - startPos);
|
||||
VectorNormalize( lineDir );
|
||||
Vector upVec;
|
||||
Vector sideDir;
|
||||
float radius = width / 2.0;
|
||||
|
||||
VectorVectors( lineDir, sideDir, upVec );
|
||||
|
||||
Vector p1 = startPos - upVec * radius;
|
||||
Vector p2 = endPos - lineDir * width - upVec * radius;
|
||||
Vector p3 = endPos - lineDir * width - upVec * width;
|
||||
Vector p4 = endPos;
|
||||
Vector p5 = endPos - lineDir * width + upVec * width;
|
||||
Vector p6 = endPos - lineDir * width + upVec * radius;
|
||||
Vector p7 = startPos + upVec * radius;
|
||||
|
||||
Line(p1, p2, r,g,b,noDepthTest,flDuration);
|
||||
Line(p2, p3, r,g,b,noDepthTest,flDuration);
|
||||
Line(p3, p4, r,g,b,noDepthTest,flDuration);
|
||||
Line(p4, p5, r,g,b,noDepthTest,flDuration);
|
||||
Line(p5, p6, r,g,b,noDepthTest,flDuration);
|
||||
Line(p6, p7, r,g,b,noDepthTest,flDuration);
|
||||
|
||||
if ( a > 0 )
|
||||
{
|
||||
Triangle( p5, p4, p3, r, g, b, a, noDepthTest, flDuration );
|
||||
Triangle( p1, p7, p6, r, g, b, a, noDepthTest, flDuration );
|
||||
Triangle( p6, p2, p1, r, g, b, a, noDepthTest, flDuration );
|
||||
|
||||
Triangle( p3, p4, p5, r, g, b, a, noDepthTest, flDuration );
|
||||
Triangle( p6, p7, p1, r, g, b, a, noDepthTest, flDuration );
|
||||
Triangle( p1, p2, p6, r, g, b, a, noDepthTest, flDuration );
|
||||
}
|
||||
}
|
||||
void Axis(const Vector &position, const QAngle &angles, float size, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
Vector xvec, yvec, zvec;
|
||||
AngleVectors( angles, &xvec, &yvec, &zvec );
|
||||
|
||||
xvec = position + (size * xvec);
|
||||
yvec = position - (size * yvec);
|
||||
zvec = position + (size * zvec);
|
||||
|
||||
Line( position, xvec, 255, 0, 0, noDepthTest, flDuration );
|
||||
Line( position, yvec, 0, 255, 0, noDepthTest, flDuration );
|
||||
Line( position, zvec, 0, 0, 255, noDepthTest, flDuration );
|
||||
}
|
||||
void Sphere(const Vector ¢er, float radius, int r, int g, int b, bool noDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
Vector edge, lastEdge;
|
||||
|
||||
float axisSize = radius;
|
||||
Line( center + Vector( 0, 0, -axisSize ), center + Vector( 0, 0, axisSize ), r, g, b, noDepthTest, flDuration );
|
||||
Line( center + Vector( 0, -axisSize, 0 ), center + Vector( 0, axisSize, 0 ), r, g, b, noDepthTest, flDuration );
|
||||
Line( center + Vector( -axisSize, 0, 0 ), center + Vector( axisSize, 0, 0 ), r, g, b, noDepthTest, flDuration );
|
||||
|
||||
lastEdge = Vector( radius + center.x, center.y, center.z );
|
||||
float angle;
|
||||
for( angle=0.0f; angle <= 360.0f; angle += 22.5f )
|
||||
{
|
||||
edge.x = radius * cosf( angle / 180.0f * M_PI ) + center.x;
|
||||
edge.y = center.y;
|
||||
edge.z = radius * sinf( angle / 180.0f * M_PI ) + center.z;
|
||||
|
||||
Line( edge, lastEdge, r, g, b, noDepthTest, flDuration );
|
||||
|
||||
lastEdge = edge;
|
||||
}
|
||||
|
||||
lastEdge = Vector( center.x, radius + center.y, center.z );
|
||||
for( angle=0.0f; angle <= 360.0f; angle += 22.5f )
|
||||
{
|
||||
edge.x = center.x;
|
||||
edge.y = radius * cosf( angle / 180.0f * M_PI ) + center.y;
|
||||
edge.z = radius * sinf( angle / 180.0f * M_PI ) + center.z;
|
||||
|
||||
Line( edge, lastEdge, r, g, b, noDepthTest, flDuration );
|
||||
|
||||
lastEdge = edge;
|
||||
}
|
||||
|
||||
lastEdge = Vector( center.x, radius + center.y, center.z );
|
||||
for( angle=0.0f; angle <= 360.0f; angle += 22.5f )
|
||||
{
|
||||
edge.x = radius * cosf( angle / 180.0f * M_PI ) + center.x;
|
||||
edge.y = radius * sinf( angle / 180.0f * M_PI ) + center.y;
|
||||
edge.z = center.z;
|
||||
|
||||
Line( edge, lastEdge, r, g, b, noDepthTest, flDuration );
|
||||
|
||||
lastEdge = edge;
|
||||
}
|
||||
}
|
||||
void CircleOriented(const Vector &position, const QAngle &angles, float radius, int r, int g, int b, int a, bool bNoDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
matrix3x4_t xform;
|
||||
AngleMatrix(angles, position, xform);
|
||||
Vector xAxis, yAxis;
|
||||
MatrixGetColumn(xform, 2, xAxis);
|
||||
MatrixGetColumn(xform, 1, yAxis);
|
||||
Circle(position, xAxis, yAxis, radius, r, g, b, a, bNoDepthTest, flDuration);
|
||||
}
|
||||
void Circle(const Vector &position, const Vector &xAxis, const Vector &yAxis, float radius, int r, int g, int b, int a, bool bNoDepthTest, float flDuration)
|
||||
{
|
||||
RETURN_IF_CANNOT_DRAW_OVERLAY
|
||||
|
||||
const unsigned int nSegments = 16;
|
||||
const float flRadStep = (M_PI*2.0f) / (float) nSegments;
|
||||
|
||||
Vector vecLastPosition;
|
||||
Vector vecStart = position + xAxis * radius;
|
||||
Vector vecPosition = vecStart;
|
||||
|
||||
for ( int i = 1; i <= nSegments; i++ )
|
||||
{
|
||||
vecLastPosition = vecPosition;
|
||||
|
||||
float flSin, flCos;
|
||||
SinCos( flRadStep*i, &flSin, &flCos );
|
||||
vecPosition = position + (xAxis * flCos * radius) + (yAxis * flSin * radius);
|
||||
|
||||
Line( vecLastPosition, vecPosition, r, g, b, bNoDepthTest, flDuration );
|
||||
|
||||
if ( a && i > 1 )
|
||||
{
|
||||
debugoverlay->AddTriangleOverlay( vecStart, vecLastPosition, vecPosition, r, g, b, a, bNoDepthTest, flDuration );
|
||||
}
|
||||
}
|
||||
}
|
||||
void SetDebugBits(HSCRIPT hEntity, int bit) // DebugOverlayBits_t
|
||||
{
|
||||
CBaseEntity *pEnt = ToEnt(hEntity);
|
||||
if (!pEnt)
|
||||
return;
|
||||
|
||||
if (pEnt->m_debugOverlays & bit)
|
||||
{
|
||||
pEnt->m_debugOverlays &= ~bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
pEnt->m_debugOverlays |= bit;
|
||||
|
||||
#ifdef AI_MONITOR_FOR_OSCILLATION
|
||||
if (pEnt->IsNPC())
|
||||
{
|
||||
pEnt->MyNPCPointer()->m_ScheduleHistory.RemoveAll();
|
||||
}
|
||||
#endif//AI_MONITOR_FOR_OSCILLATION
|
||||
}
|
||||
}
|
||||
void ClearAllOverlays()
|
||||
{
|
||||
// Clear all entities of their debug overlays
|
||||
for (CBaseEntity *pEntity = gEntList.FirstEnt(); pEntity; pEntity = gEntList.NextEnt(pEntity))
|
||||
{
|
||||
pEntity->m_debugOverlays = 0;
|
||||
}
|
||||
|
||||
if (debugoverlay)
|
||||
{
|
||||
debugoverlay->ClearAllOverlays();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
} g_ScriptDebugOverlay;
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT(CDebugOverlayScriptHelper, SCRIPT_SINGLETON "CDebugOverlayScriptHelper")
|
||||
DEFINE_SCRIPTFUNC( Box, "Draws a world-space axis-aligned box. Specify bounds in world space." )
|
||||
DEFINE_SCRIPTFUNC( BoxDirection, "Draw box oriented to a Vector direction" )
|
||||
DEFINE_SCRIPTFUNC( BoxAngles, "Draws an oriented box at the origin. Specify bounds in local space." )
|
||||
DEFINE_SCRIPTFUNC( SweptBox, "Draws a swept box. Specify endpoints in world space and the bounds in local space." )
|
||||
DEFINE_SCRIPTFUNC( EntityBounds, "Draws bounds of an entity" )
|
||||
DEFINE_SCRIPTFUNC( Line, "Draws a line between two points" )
|
||||
DEFINE_SCRIPTFUNC( Triangle, "Draws a filled triangle. Specify vertices in world space." )
|
||||
DEFINE_SCRIPTFUNC( EntityText, "Draws text on an entity" )
|
||||
DEFINE_SCRIPTFUNC( EntityTextAtPosition, "Draw entity text overlay at a specific position" )
|
||||
DEFINE_SCRIPTFUNC( Grid, "Add grid overlay" )
|
||||
DEFINE_SCRIPTFUNC( Text, "Draws 2D text. Specify origin in world space." )
|
||||
DEFINE_SCRIPTFUNC( ScreenText, "Draws 2D text. Specify coordinates in screen space." )
|
||||
DEFINE_SCRIPTFUNC( Cross3D, "Draws a world-aligned cross. Specify origin in world space." )
|
||||
DEFINE_SCRIPTFUNC( Cross3DOriented, "Draws an oriented cross. Specify origin in world space." )
|
||||
DEFINE_SCRIPTFUNC( DrawTickMarkedLine, "Draws a dashed line. Specify endpoints in world space." )
|
||||
DEFINE_SCRIPTFUNC( HorzArrow, "Draws a horizontal arrow. Specify endpoints in world space." )
|
||||
DEFINE_SCRIPTFUNC( YawArrow, "Draws a arrow associated with a specific yaw. Specify endpoints in world space." )
|
||||
DEFINE_SCRIPTFUNC( VertArrow, "Draws a vertical arrow. Specify endpoints in world space." )
|
||||
DEFINE_SCRIPTFUNC( Axis, "Draws an axis. Specify origin + orientation in world space." )
|
||||
DEFINE_SCRIPTFUNC( Sphere, "Draws a wireframe sphere. Specify center in world space." )
|
||||
DEFINE_SCRIPTFUNC( CircleOriented, "Draws a circle oriented. Specify center in world space." )
|
||||
DEFINE_SCRIPTFUNC( Circle, "Draws a circle. Specify center in world space." )
|
||||
DEFINE_SCRIPTFUNC( SetDebugBits, "Set debug bits on entity" )
|
||||
DEFINE_SCRIPTFUNC( ClearAllOverlays, "Clear all debug overlays at once" )
|
||||
END_SCRIPTDESC();
|
||||
#endif // MAPBASE_VSCRIPT
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1010,9 +565,7 @@ bool VScriptServerInit()
|
||||
}
|
||||
|
||||
g_pScriptVM->RegisterInstance( &g_ScriptEntityIterator, "Entities" );
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
g_pScriptVM->RegisterInstance( &g_ScriptDebugOverlay, "debugoverlay" );
|
||||
#endif // MAPBASE_VSCRIPT
|
||||
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
g_pScriptVM->RegisterAllClasses();
|
||||
@ -1029,6 +582,7 @@ bool VScriptServerInit()
|
||||
g_pScriptVM->Run( g_Script_vscript_server );
|
||||
}
|
||||
|
||||
VScriptRunScript( "vscript_server", true );
|
||||
VScriptRunScript( "mapspawn", false );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
@ -1046,6 +600,12 @@ bool VScriptServerInit()
|
||||
CGWarning( 1, CON_GROUP_VSCRIPT, "VM Did not start!\n" );
|
||||
}
|
||||
}
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
else
|
||||
{
|
||||
CGMsg( 0, CON_GROUP_VSCRIPT, "VSCRIPT SERVER: Not starting because language is set to 'none'\n" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1192,6 +752,9 @@ public:
|
||||
|
||||
virtual void LevelShutdownPostEntity( void )
|
||||
{
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
g_ScriptNetMsg->LevelShutdownPreVM();
|
||||
#endif
|
||||
VScriptServerTerm();
|
||||
}
|
||||
|
||||
@ -1219,172 +782,3 @@ bool IsEntityCreationAllowedInScripts( void )
|
||||
|
||||
return g_VScriptGameSystem.m_bAllowEntityCreationInScripts;
|
||||
}
|
||||
|
||||
static short VSCRIPT_SERVER_SAVE_RESTORE_VERSION = 2;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class CVScriptSaveRestoreBlockHandler : public CDefSaveRestoreBlockHandler
|
||||
{
|
||||
public:
|
||||
CVScriptSaveRestoreBlockHandler() :
|
||||
m_InstanceMap( DefLessFunc(const char *) )
|
||||
{
|
||||
}
|
||||
const char *GetBlockName()
|
||||
{
|
||||
return "VScriptServer";
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
void Save( ISave *pSave )
|
||||
{
|
||||
pSave->StartBlock();
|
||||
|
||||
int temp = g_pScriptVM != NULL;
|
||||
pSave->WriteInt( &temp );
|
||||
if ( g_pScriptVM )
|
||||
{
|
||||
temp = g_pScriptVM->GetLanguage();
|
||||
pSave->WriteInt( &temp );
|
||||
CUtlBuffer buffer;
|
||||
g_pScriptVM->WriteState( &buffer );
|
||||
temp = buffer.TellPut();
|
||||
pSave->WriteInt( &temp );
|
||||
if ( temp > 0 )
|
||||
{
|
||||
pSave->WriteData( (const char *)buffer.Base(), temp );
|
||||
}
|
||||
}
|
||||
|
||||
pSave->EndBlock();
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
void WriteSaveHeaders( ISave *pSave )
|
||||
{
|
||||
pSave->WriteShort( &VSCRIPT_SERVER_SAVE_RESTORE_VERSION );
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
void ReadRestoreHeaders( IRestore *pRestore )
|
||||
{
|
||||
// No reason why any future version shouldn't try to retain backward compatability. The default here is to not do so.
|
||||
short version;
|
||||
pRestore->ReadShort( &version );
|
||||
m_fDoLoad = ( version == VSCRIPT_SERVER_SAVE_RESTORE_VERSION );
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
void Restore( IRestore *pRestore, bool createPlayers )
|
||||
{
|
||||
if ( !m_fDoLoad && g_pScriptVM )
|
||||
{
|
||||
return;
|
||||
}
|
||||
CBaseEntity *pEnt = gEntList.FirstEnt();
|
||||
while ( pEnt )
|
||||
{
|
||||
if ( pEnt->m_iszScriptId != NULL_STRING )
|
||||
{
|
||||
#ifndef MAPBASE_VSCRIPT
|
||||
g_pScriptVM->RegisterClass( pEnt->GetScriptDesc() );
|
||||
#endif
|
||||
m_InstanceMap.Insert( STRING( pEnt->m_iszScriptId ), pEnt );
|
||||
}
|
||||
pEnt = gEntList.NextEnt( pEnt );
|
||||
}
|
||||
|
||||
pRestore->StartBlock();
|
||||
if ( pRestore->ReadInt() && pRestore->ReadInt() == g_pScriptVM->GetLanguage() )
|
||||
{
|
||||
int nBytes = pRestore->ReadInt();
|
||||
if ( nBytes > 0 )
|
||||
{
|
||||
CUtlBuffer buffer;
|
||||
buffer.EnsureCapacity( nBytes );
|
||||
pRestore->ReadData( (char *)buffer.AccessForDirectRead( nBytes ), nBytes, 0 );
|
||||
g_pScriptVM->ReadState( &buffer );
|
||||
}
|
||||
}
|
||||
pRestore->EndBlock();
|
||||
}
|
||||
|
||||
void PostRestore( void )
|
||||
{
|
||||
for ( int i = m_InstanceMap.FirstInorder(); i != m_InstanceMap.InvalidIndex(); i = m_InstanceMap.NextInorder( i ) )
|
||||
{
|
||||
CBaseEntity *pEnt = m_InstanceMap[i];
|
||||
if ( pEnt->m_hScriptInstance )
|
||||
{
|
||||
ScriptVariant_t variant;
|
||||
if ( g_pScriptVM->GetValue( STRING(pEnt->m_iszScriptId), &variant ) && variant.m_type == FIELD_HSCRIPT )
|
||||
{
|
||||
pEnt->m_ScriptScope.Init( variant.m_hScript, false );
|
||||
pEnt->RunPrecacheScripts();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Script system probably has no internal references
|
||||
pEnt->m_iszScriptId = NULL_STRING;
|
||||
}
|
||||
}
|
||||
m_InstanceMap.Purge();
|
||||
}
|
||||
|
||||
|
||||
CUtlMap<const char *, CBaseEntity *> m_InstanceMap;
|
||||
|
||||
private:
|
||||
bool m_fDoLoad;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
CVScriptSaveRestoreBlockHandler g_VScriptSaveRestoreBlockHandler;
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
ISaveRestoreBlockHandler *GetVScriptSaveRestoreBlockHandler()
|
||||
{
|
||||
return &g_VScriptSaveRestoreBlockHandler;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool CBaseEntityScriptInstanceHelper::ToString( void *p, char *pBuf, int bufSize )
|
||||
{
|
||||
CBaseEntity *pEntity = (CBaseEntity *)p;
|
||||
if ( pEntity->GetEntityName() != NULL_STRING )
|
||||
{
|
||||
V_snprintf( pBuf, bufSize, "([%d] %s: %s)", pEntity->entindex(), STRING(pEntity->m_iClassname), STRING( pEntity->GetEntityName() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
V_snprintf( pBuf, bufSize, "([%d] %s)", pEntity->entindex(), STRING(pEntity->m_iClassname) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void *CBaseEntityScriptInstanceHelper::BindOnRead( HSCRIPT hInstance, void *pOld, const char *pszId )
|
||||
{
|
||||
int iEntity = g_VScriptSaveRestoreBlockHandler.m_InstanceMap.Find( pszId );
|
||||
if ( iEntity != g_VScriptSaveRestoreBlockHandler.m_InstanceMap.InvalidIndex() )
|
||||
{
|
||||
CBaseEntity *pEnt = g_VScriptSaveRestoreBlockHandler.m_InstanceMap[iEntity];
|
||||
pEnt->m_hScriptInstance = hInstance;
|
||||
return pEnt;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
CBaseEntityScriptInstanceHelper g_BaseEntityScriptInstanceHelper;
|
||||
|
||||
|
||||
|
@ -15,19 +15,7 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
class ISaveRestoreBlockHandler;
|
||||
|
||||
bool VScriptServerReplaceClosures( const char *pszScriptName, HSCRIPT hScope, bool bWarnMissing = false );
|
||||
ISaveRestoreBlockHandler *GetVScriptSaveRestoreBlockHandler();
|
||||
|
||||
|
||||
class CBaseEntityScriptInstanceHelper : public IScriptInstanceHelper
|
||||
{
|
||||
bool ToString( void *p, char *pBuf, int bufSize );
|
||||
void *BindOnRead( HSCRIPT hInstance, void *pOld, const char *pszId );
|
||||
};
|
||||
|
||||
extern CBaseEntityScriptInstanceHelper g_BaseEntityScriptInstanceHelper;
|
||||
|
||||
// Only allow scripts to create entities during map initialization
|
||||
bool IsEntityCreationAllowedInScripts( void );
|
||||
|
@ -5,13 +5,16 @@ static char g_Script_vscript_server[] = R"vscript(
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
function UniqueString( string = "" )
|
||||
{
|
||||
return ::DoUniqueString( string.tostring() );
|
||||
}
|
||||
|
||||
local DoEntFire = ::DoEntFire
|
||||
local DoEntFireByInstanceHandle = ::DoEntFireByInstanceHandle
|
||||
local DoDispatchParticleEffect = ::DoDispatchParticleEffect
|
||||
local DoUniqueString = ::DoUniqueString
|
||||
local ScriptGetClientConvarValue = ::ScriptGetClientConvarValue
|
||||
|
||||
function UniqueString( string = "" )
|
||||
{
|
||||
return DoUniqueString( string.tostring() );
|
||||
}
|
||||
|
||||
function EntFire( target, action, value = null, delay = 0.0, activator = null, caller = null )
|
||||
{
|
||||
@ -67,10 +70,10 @@ function DispatchParticleEffect( particleName, origin, angles, entity = null )
|
||||
// CConvars is declared within the library
|
||||
function CConvars::GetClientConvarValue(cvar,idx)
|
||||
{
|
||||
return ::ScriptGetClientConvarValue(cvar,idx);
|
||||
return ScriptGetClientConvarValue(cvar,idx);
|
||||
}
|
||||
|
||||
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." );
|
||||
__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." );
|
||||
|
||||
function __ReplaceClosures( script, scope )
|
||||
{
|
||||
|
@ -395,7 +395,7 @@ BEGIN_DATADESC( CWorld )
|
||||
DEFINE_KEYFIELD( m_iszDetailSpriteMaterial, FIELD_STRING, "detailmaterial" ),
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DEFINE_KEYFIELD( m_iScriptLanguage, FIELD_INTEGER, "vscriptlanguage" ),
|
||||
DEFINE_KEYFIELD( m_iScriptLanguageClient, FIELD_INTEGER, "vscriptlanguage_client" ),
|
||||
//DEFINE_KEYFIELD( m_iScriptLanguageClient, FIELD_INTEGER, "vscriptlanguage_client" ),
|
||||
#endif
|
||||
DEFINE_KEYFIELD( m_bColdWorld, FIELD_BOOLEAN, "coldworld" ),
|
||||
|
||||
@ -421,9 +421,6 @@ IMPLEMENT_SERVERCLASS_ST(CWorld, DT_WORLD)
|
||||
#ifdef MAPBASE
|
||||
SendPropStringT (SENDINFO(m_iszChapterTitle) ),
|
||||
#endif
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
SendPropInt (SENDINFO(m_iScriptLanguageClient), 4 ), // No SPROP_UNSIGNED to allow -1 (disabled)
|
||||
#endif
|
||||
END_SEND_TABLE()
|
||||
|
||||
//
|
||||
@ -485,7 +482,7 @@ CWorld::CWorld( )
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
m_iScriptLanguage = SL_NONE;
|
||||
m_iScriptLanguageClient = -2;
|
||||
//m_iScriptLanguageClient = -2;
|
||||
#endif
|
||||
|
||||
m_bColdWorld = false;
|
||||
@ -552,14 +549,6 @@ void CWorld::Spawn( void )
|
||||
Precache( );
|
||||
GlobalEntity_Add( "is_console", STRING(gpGlobals->mapname), ( IsConsole() ) ? GLOBAL_ON : GLOBAL_OFF );
|
||||
GlobalEntity_Add( "is_pc", STRING(gpGlobals->mapname), ( !IsConsole() ) ? GLOBAL_ON : GLOBAL_OFF );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if (m_iScriptLanguageClient.Get() == -2)
|
||||
{
|
||||
// Clientside language should be regular language by default
|
||||
m_iScriptLanguageClient.Set( m_iScriptLanguage );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *g_DefaultLightstyles[] =
|
||||
|
@ -90,7 +90,7 @@ private:
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
int m_iScriptLanguage;
|
||||
CNetworkVar( int, m_iScriptLanguageClient );
|
||||
//CNetworkVar( int, m_iScriptLanguageClient ); // Now entirely on client
|
||||
#endif
|
||||
|
||||
// start flags
|
||||
|
@ -132,6 +132,15 @@ void Hack_FixEscapeChars( char *str )
|
||||
|
||||
#ifdef MAPBASE
|
||||
static const ConVar *pHostTimescale;
|
||||
|
||||
static float GetSoundPitchScale()
|
||||
{
|
||||
static ConVarRef sv_cheats( "sv_cheats" );
|
||||
if (sv_cheats.GetBool())
|
||||
return pHostTimescale->GetFloat();
|
||||
|
||||
return 1.0f;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -534,7 +543,7 @@ public:
|
||||
(soundlevel_t)params.soundlevel,
|
||||
ep.m_nFlags,
|
||||
#ifdef MAPBASE
|
||||
pHostTimescale->GetFloat() != 0.0f ? params.pitch * pHostTimescale->GetFloat() : params.pitch,
|
||||
params.pitch * GetSoundPitchScale(),
|
||||
#else
|
||||
params.pitch,
|
||||
#endif
|
||||
@ -617,7 +626,7 @@ public:
|
||||
ep.m_SoundLevel,
|
||||
ep.m_nFlags,
|
||||
#ifdef MAPBASE
|
||||
pHostTimescale->GetFloat() != 0.0f ? ep.m_nPitch * pHostTimescale->GetFloat() : ep.m_nPitch,
|
||||
ep.m_nPitch * GetSoundPitchScale(),
|
||||
#else
|
||||
ep.m_nPitch,
|
||||
#endif
|
||||
@ -843,10 +852,7 @@ public:
|
||||
}
|
||||
|
||||
#ifdef MAPBASE
|
||||
if ( pHostTimescale->GetFloat() != 0.0f )
|
||||
{
|
||||
params.pitch *= pHostTimescale->GetFloat();
|
||||
}
|
||||
params.pitch *= GetSoundPitchScale();
|
||||
#endif
|
||||
|
||||
#if defined( CLIENT_DLL )
|
||||
@ -978,10 +984,7 @@ public:
|
||||
if ( pSample && ( Q_stristr( pSample, ".wav" ) || Q_stristr( pSample, ".mp3" )) )
|
||||
{
|
||||
#ifdef MAPBASE
|
||||
if ( pHostTimescale->GetFloat() != 0.0f )
|
||||
{
|
||||
pitch *= pHostTimescale->GetFloat();
|
||||
}
|
||||
pitch *= GetSoundPitchScale();
|
||||
#endif
|
||||
|
||||
#if defined( CLIENT_DLL )
|
||||
|
@ -2418,6 +2418,18 @@ void CBaseEntity::FollowEntity( CBaseEntity *pBaseEntity, bool bBoneMerge )
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
void CBaseEntity::ScriptFollowEntity( HSCRIPT hBaseEntity, bool bBoneMerge )
|
||||
{
|
||||
FollowEntity( ToEnt( hBaseEntity ), bBoneMerge );
|
||||
}
|
||||
|
||||
HSCRIPT CBaseEntity::ScriptGetFollowedEntity()
|
||||
{
|
||||
return ToHScript( GetFollowedEntity() );
|
||||
}
|
||||
#endif
|
||||
|
||||
void CBaseEntity::SetEffectEntity( CBaseEntity *pEffectEnt )
|
||||
{
|
||||
if ( m_hEffectEntity.Get() != pEffectEnt )
|
||||
@ -2607,3 +2619,97 @@ bool CBaseEntity::IsToolRecording() const
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
HSCRIPT CBaseEntity::GetOrCreatePrivateScriptScope()
|
||||
{
|
||||
ValidateScriptScope();
|
||||
return m_ScriptScope;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseEntity::ScriptSetParent(HSCRIPT hParent, const char *szAttachment)
|
||||
{
|
||||
CBaseEntity *pParent = ToEnt(hParent);
|
||||
if ( !pParent )
|
||||
{
|
||||
SetParent(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
// if an attachment is specified, the parent needs to be CBaseAnimating
|
||||
if ( szAttachment && szAttachment[0] != '\0' )
|
||||
{
|
||||
CBaseAnimating *pAnimating = pParent->GetBaseAnimating();
|
||||
if ( !pAnimating )
|
||||
{
|
||||
Warning("ERROR: Tried to set parent for entity %s (%s), but its parent has no model.\n", GetClassname(), GetDebugName());
|
||||
return;
|
||||
}
|
||||
|
||||
int iAttachment = pAnimating->LookupAttachment(szAttachment);
|
||||
if ( iAttachment <= 0 )
|
||||
{
|
||||
Warning("ERROR: Tried to set parent for entity %s (%s), but it has no attachment named %s.\n", GetClassname(), GetDebugName(), szAttachment);
|
||||
return;
|
||||
}
|
||||
|
||||
SetParent(pParent, iAttachment);
|
||||
SetMoveType(MOVETYPE_NONE);
|
||||
return;
|
||||
}
|
||||
|
||||
SetParent(pParent);
|
||||
}
|
||||
|
||||
HSCRIPT CBaseEntity::GetScriptOwnerEntity()
|
||||
{
|
||||
return ToHScript(GetOwnerEntity());
|
||||
}
|
||||
|
||||
void CBaseEntity::SetScriptOwnerEntity(HSCRIPT pOwner)
|
||||
{
|
||||
SetOwnerEntity(ToEnt(pOwner));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
const Vector& CBaseEntity::ScriptGetColorVector()
|
||||
{
|
||||
static Vector vecColor;
|
||||
vecColor.Init( m_clrRender.GetR(), m_clrRender.GetG(), m_clrRender.GetB() );
|
||||
return vecColor;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseEntity::ScriptSetColorVector( const Vector& vecColor )
|
||||
{
|
||||
SetRenderColor( vecColor.x, vecColor.y, vecColor.z );
|
||||
}
|
||||
|
||||
void CBaseEntity::ScriptSetColor( int r, int g, int b )
|
||||
{
|
||||
SetRenderColor( r, g, b );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vscript: Gets the entity matrix transform
|
||||
//-----------------------------------------------------------------------------
|
||||
HSCRIPT CBaseEntity::ScriptEntityToWorldTransform( void )
|
||||
{
|
||||
return g_pScriptVM->RegisterInstance( &EntityToWorldTransform() );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vscript: Gets the entity's physics object if it has one
|
||||
//-----------------------------------------------------------------------------
|
||||
HSCRIPT CBaseEntity::ScriptGetPhysicsObject( void )
|
||||
{
|
||||
if (VPhysicsGetObject())
|
||||
return g_pScriptVM->RegisterInstance( VPhysicsGetObject() );
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
258
sp/src/game/shared/mapbase/logic_script_client.cpp
Normal file
258
sp/src/game/shared/mapbase/logic_script_client.cpp
Normal file
@ -0,0 +1,258 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose: Custom client-side equivalent of logic_script.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "cbase.h"
|
||||
#include "vscript_shared.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
ConVar cl_script_think_interval( "cl_script_think_interval", "0.1" );
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: An entity that acts as a container for client-side game scripts.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define MAX_SCRIPT_GROUP_CLIENT 8
|
||||
|
||||
class CLogicScriptClient : public CBaseEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS( CLogicScriptClient, CBaseEntity );
|
||||
DECLARE_DATADESC();
|
||||
DECLARE_NETWORKCLASS();
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
void OnDataChanged( DataUpdateType_t type )
|
||||
{
|
||||
BaseClass::OnDataChanged( type );
|
||||
|
||||
if ( !m_ScriptScope.IsInitialized() )
|
||||
{
|
||||
RunVScripts();
|
||||
}
|
||||
}
|
||||
#else
|
||||
int UpdateTransmitState() { return SetTransmitState( FL_EDICT_ALWAYS ); }
|
||||
#endif
|
||||
|
||||
bool KeyValue( const char *szKeyName, const char *szValue )
|
||||
{
|
||||
if ( FStrEq( szKeyName, "vscripts" ) )
|
||||
{
|
||||
Q_strcpy( m_iszClientScripts.GetForModify(), szValue );
|
||||
}
|
||||
|
||||
return BaseClass::KeyValue( szKeyName, szValue );
|
||||
}
|
||||
|
||||
void RunVScripts()
|
||||
{
|
||||
#ifdef CLIENT_DLL
|
||||
if (m_iszClientScripts == NULL_STRING)
|
||||
{
|
||||
CGMsg( 0, CON_GROUP_VSCRIPT, "%s has no client scripts", GetDebugName() );
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_pScriptVM == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ValidateScriptScope();
|
||||
|
||||
// All functions we want to have call chained instead of overwritten
|
||||
// by other scripts in this entities list.
|
||||
static const char* sCallChainFunctions[] =
|
||||
{
|
||||
"OnPostSpawn",
|
||||
"Precache"
|
||||
};
|
||||
|
||||
ScriptLanguage_t language = g_pScriptVM->GetLanguage();
|
||||
|
||||
// Make a call chainer for each in this entities scope
|
||||
for (int j = 0; j < ARRAYSIZE( sCallChainFunctions ); ++j)
|
||||
{
|
||||
|
||||
if (language == SL_PYTHON)
|
||||
{
|
||||
// UNDONE - handle call chaining in python
|
||||
;
|
||||
}
|
||||
else if (language == SL_SQUIRREL)
|
||||
{
|
||||
//TODO: For perf, this should be precompiled and the %s should be passed as a parameter
|
||||
HSCRIPT hCreateChainScript = g_pScriptVM->CompileScript( CFmtStr( "%sCallChain <- CSimpleCallChainer(\"%s\", self.GetScriptScope(), true)", sCallChainFunctions[j], sCallChainFunctions[j] ) );
|
||||
g_pScriptVM->Run( hCreateChainScript, (HSCRIPT)m_ScriptScope );
|
||||
}
|
||||
}
|
||||
|
||||
char szScriptsList[255];
|
||||
Q_strcpy( szScriptsList, m_iszClientScripts.Get() );
|
||||
CUtlStringList szScripts;
|
||||
|
||||
V_SplitString( szScriptsList, " ", szScripts );
|
||||
|
||||
for (int i = 0; i < szScripts.Count(); i++)
|
||||
{
|
||||
CGMsg( 0, CON_GROUP_VSCRIPT, "%s executing script: %s\n", GetDebugName(), szScripts[i] );
|
||||
|
||||
RunScriptFile( szScripts[i], IsWorld() );
|
||||
|
||||
for (int j = 0; j < ARRAYSIZE( sCallChainFunctions ); ++j)
|
||||
{
|
||||
if (language == SL_PYTHON)
|
||||
{
|
||||
// UNDONE - handle call chaining in python
|
||||
;
|
||||
}
|
||||
else if (language == SL_SQUIRREL)
|
||||
{
|
||||
//TODO: For perf, this should be precompiled and the %s should be passed as a parameter.
|
||||
HSCRIPT hRunPostScriptExecute = g_pScriptVM->CompileScript( CFmtStr( "%sCallChain.PostScriptExecute()", sCallChainFunctions[j] ) );
|
||||
g_pScriptVM->Run( hRunPostScriptExecute, (HSCRIPT)m_ScriptScope );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bClientThink)
|
||||
{
|
||||
SetNextClientThink( CLIENT_THINK_ALWAYS );
|
||||
}
|
||||
#else
|
||||
// Avoids issues from having m_iszVScripts set without actually having a script scope
|
||||
ValidateScriptScope();
|
||||
|
||||
if (m_bRunOnServer)
|
||||
{
|
||||
BaseClass::RunVScripts();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
void ClientThink()
|
||||
{
|
||||
ScriptVariant_t varThinkRetVal;
|
||||
if (CallScriptFunction("ClientThink", &varThinkRetVal))
|
||||
{
|
||||
float flThinkFrequency = 0.0f;
|
||||
if (!varThinkRetVal.AssignTo(&flThinkFrequency))
|
||||
{
|
||||
// use default think interval if script think function doesn't provide one
|
||||
flThinkFrequency = cl_script_think_interval.GetFloat();
|
||||
}
|
||||
|
||||
if (flThinkFrequency == CLIENT_THINK_ALWAYS)
|
||||
SetNextClientThink( CLIENT_THINK_ALWAYS );
|
||||
else
|
||||
SetNextClientThink( gpGlobals->curtime + flThinkFrequency );
|
||||
}
|
||||
else
|
||||
{
|
||||
DevWarning("%s FAILED to call client script think function!\n", GetDebugName());
|
||||
}
|
||||
|
||||
BaseClass::ClientThink();
|
||||
}
|
||||
|
||||
void OnSave()
|
||||
{
|
||||
// HACKHACK: Save the next think in the VM since the VM is saved
|
||||
if (m_bClientThink)
|
||||
{
|
||||
g_pScriptVM->SetValue( m_ScriptScope, "__c_think", GetNextThink() );
|
||||
}
|
||||
|
||||
BaseClass::OnSave();
|
||||
}
|
||||
|
||||
void OnRestore()
|
||||
{
|
||||
// HACKHACK: See OnSave()
|
||||
if (m_bClientThink)
|
||||
{
|
||||
ScriptVariant_t flNextThink;
|
||||
if (g_pScriptVM->GetValue( m_ScriptScope, "__c_think", &flNextThink ))
|
||||
{
|
||||
SetNextClientThink( flNextThink );
|
||||
}
|
||||
}
|
||||
|
||||
BaseClass::OnRestore();
|
||||
}
|
||||
#else
|
||||
void InputCallScriptFunctionClient( inputdata_t &inputdata )
|
||||
{
|
||||
// TODO: Support for specific players?
|
||||
CBroadcastRecipientFilter filter;
|
||||
filter.MakeReliable();
|
||||
|
||||
const char *pszFunction = inputdata.value.String();
|
||||
if (strlen( pszFunction ) > 64)
|
||||
{
|
||||
Msg("%s CallScriptFunctionClient: \"%s\" is too long at %i characters, must be 64 or less\n", GetDebugName(), pszFunction, strlen(pszFunction));
|
||||
return;
|
||||
}
|
||||
|
||||
UserMessageBegin( filter, "CallClientScriptFunction" );
|
||||
WRITE_STRING( pszFunction ); // function
|
||||
WRITE_SHORT( entindex() ); // entity
|
||||
MessageEnd();
|
||||
}
|
||||
#endif
|
||||
|
||||
//CNetworkArray( string_t, m_iszGroupMembers, MAX_SCRIPT_GROUP_CLIENT );
|
||||
CNetworkString( m_iszClientScripts, 128 );
|
||||
CNetworkVar( bool, m_bClientThink );
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
bool m_bRunOnServer;
|
||||
#endif
|
||||
};
|
||||
|
||||
LINK_ENTITY_TO_CLASS( logic_script_client, CLogicScriptClient );
|
||||
|
||||
BEGIN_DATADESC( CLogicScriptClient )
|
||||
|
||||
// TODO: Does this need to be saved?
|
||||
//DEFINE_AUTO_ARRAY( m_iszClientScripts, FIELD_CHARACTER ),
|
||||
|
||||
//DEFINE_KEYFIELD( m_iszGroupMembers[0], FIELD_STRING, "Group00"),
|
||||
//DEFINE_KEYFIELD( m_iszGroupMembers[1], FIELD_STRING, "Group01"),
|
||||
//DEFINE_KEYFIELD( m_iszGroupMembers[2], FIELD_STRING, "Group02"),
|
||||
//DEFINE_KEYFIELD( m_iszGroupMembers[3], FIELD_STRING, "Group03"),
|
||||
//DEFINE_KEYFIELD( m_iszGroupMembers[4], FIELD_STRING, "Group04"),
|
||||
//DEFINE_KEYFIELD( m_iszGroupMembers[5], FIELD_STRING, "Group05"),
|
||||
//DEFINE_KEYFIELD( m_iszGroupMembers[6], FIELD_STRING, "Group06"),
|
||||
//DEFINE_KEYFIELD( m_iszGroupMembers[7], FIELD_STRING, "Group07"),
|
||||
|
||||
DEFINE_KEYFIELD( m_bClientThink, FIELD_BOOLEAN, "ClientThink" ),
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
DEFINE_KEYFIELD( m_bRunOnServer, FIELD_BOOLEAN, "RunOnServer" ),
|
||||
|
||||
DEFINE_INPUTFUNC( FIELD_STRING, "CallScriptFunctionClient", InputCallScriptFunctionClient ),
|
||||
#endif
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_NETWORKCLASS_DT( CLogicScriptClient, DT_LogicScriptClient )
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
//RecvPropArray( RecvPropString( RECVINFO( m_iszGroupMembers[0] ) ), m_iszGroupMembers ),
|
||||
RecvPropString( RECVINFO( m_iszClientScripts ) ),
|
||||
RecvPropBool( RECVINFO( m_bClientThink ) ),
|
||||
#else
|
||||
//SendPropArray( SendPropStringT( SENDINFO_ARRAY( m_iszGroupMembers ) ), m_iszGroupMembers ),
|
||||
SendPropString( SENDINFO( m_iszClientScripts ) ),
|
||||
SendPropBool( SENDINFO( m_bClientThink ) ),
|
||||
#endif
|
||||
|
||||
END_NETWORK_TABLE()
|
@ -16,10 +16,12 @@
|
||||
#include "saverestore_utlvector.h"
|
||||
#include "props_shared.h"
|
||||
#include "utlbuffer.h"
|
||||
#include "usermessages.h"
|
||||
#ifdef CLIENT_DLL
|
||||
#include "hud_closecaption.h"
|
||||
#include "panelmetaclassmgr.h"
|
||||
#include "c_soundscape.h"
|
||||
#include "hud_macros.h"
|
||||
#else
|
||||
#include "soundscape_system.h"
|
||||
#include "AI_ResponseSystem.h"
|
||||
@ -69,7 +71,7 @@ ConVar mapbase_load_actbusy("mapbase_load_actbusy", "1", FCVAR_ARCHIVE, "Should
|
||||
|
||||
#ifdef GAME_DLL
|
||||
// This cvar should change with each Mapbase update
|
||||
ConVar mapbase_version( "mapbase_version", "6.1", FCVAR_NONE, "The version of Mapbase currently being used in this mod." );
|
||||
ConVar mapbase_version( "mapbase_version", "6.2", FCVAR_NONE, "The version of Mapbase currently being used in this mod." );
|
||||
|
||||
extern void MapbaseGameLog_Init();
|
||||
|
||||
|
66
sp/src/game/shared/mapbase/mapbase_usermessages.cpp
Normal file
66
sp/src/game/shared/mapbase/mapbase_usermessages.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose: Mapbase-specific user messages.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "cbase.h"
|
||||
|
||||
#include "usermessages.h"
|
||||
#ifdef CLIENT_DLL
|
||||
#include "hud_macros.h"
|
||||
#endif
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
void __MsgFunc_CallClientScriptFunction( bf_read &msg )
|
||||
{
|
||||
char szFunction[64];
|
||||
if (!msg.ReadString( szFunction, sizeof( szFunction ) ))
|
||||
{
|
||||
CGMsg( 0, CON_GROUP_VSCRIPT, "Unable to read function string\n" );
|
||||
}
|
||||
|
||||
int idx = msg.ReadByte();
|
||||
C_BaseEntity *pEntity = CBaseEntity::Instance( idx );
|
||||
|
||||
if (pEntity)
|
||||
{
|
||||
if (pEntity->m_ScriptScope.IsInitialized())
|
||||
{
|
||||
//CGMsg( 0, CON_GROUP_VSCRIPT, "%s calling function \"%s\"\n", pEntity->GetDebugName(), szFunction );
|
||||
pEntity->CallScriptFunction( szFunction, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
CGMsg( 0, CON_GROUP_VSCRIPT, "%s scope not initialized\n", pEntity->GetDebugName() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CGMsg( 0, CON_GROUP_VSCRIPT, "Clientside entity not found for script function (index %i)\n", idx );
|
||||
}
|
||||
}
|
||||
|
||||
void HookMapbaseUserMessages( void )
|
||||
{
|
||||
// VScript
|
||||
HOOK_MESSAGE( CallClientScriptFunction );
|
||||
//HOOK_MESSAGE( ScriptMsg ); // Hooked in CNetMsgScriptHelper
|
||||
}
|
||||
#endif
|
||||
|
||||
void RegisterMapbaseUserMessages( void )
|
||||
{
|
||||
// VScript
|
||||
usermessages->Register( "CallClientScriptFunction", -1 );
|
||||
usermessages->Register( "ScriptMsg", -1 ); // CNetMsgScriptHelper
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
// TODO: Better placement?
|
||||
HookMapbaseUserMessages();
|
||||
#endif
|
||||
}
|
@ -852,10 +852,4 @@ void RegisterSharedScriptFunctions()
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptIsClient, "IsClient", "Returns true if the script is being run on the client." );
|
||||
|
||||
RegisterScriptSingletons();
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
VScriptRunScript( "vscript_client", true );
|
||||
#else
|
||||
VScriptRunScript( "vscript_server", true );
|
||||
#endif
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,12 +5,139 @@
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VSCRIPT_FUNCS_MATH
|
||||
#define VSCRIPT_FUNCS_MATH
|
||||
#ifndef VSCRIPT_SINGLETONS
|
||||
#define VSCRIPT_SINGLETONS
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
void RegisterScriptSingletons();
|
||||
|
||||
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
// usercmd
|
||||
#define SCRIPT_NETMSG_DATA_SIZE ( ( 1 << 11 ) - 1 )
|
||||
#else
|
||||
// usermsg
|
||||
#define SCRIPT_NETMSG_DATA_SIZE MAX_USER_MSG_DATA
|
||||
#endif
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
class CNetMsgScriptHelper : public CAutoGameSystem
|
||||
#else
|
||||
class CNetMsgScriptHelper
|
||||
#endif
|
||||
{
|
||||
private:
|
||||
#ifdef GAME_DLL
|
||||
CRecipientFilter m_filter;
|
||||
bf_read *m_MsgIn;
|
||||
#else
|
||||
bf_read m_MsgIn;
|
||||
#endif
|
||||
bf_write m_MsgOut;
|
||||
byte m_MsgData[ PAD_NUMBER( SCRIPT_NETMSG_DATA_SIZE, 4 ) ];
|
||||
HSCRIPT m_Hooks;
|
||||
|
||||
public:
|
||||
#ifdef CLIENT_DLL
|
||||
bool m_bWriteReady; // dt ready to send
|
||||
|
||||
CNetMsgScriptHelper() : m_Hooks(NULL), m_bWriteReady(false) {}
|
||||
#else
|
||||
CNetMsgScriptHelper() : m_Hooks(NULL) {}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#ifdef CLIENT_DLL
|
||||
bool Init(); // IGameSystem
|
||||
static void __MsgFunc_ScriptMsg( bf_read &msg );
|
||||
#endif
|
||||
void LevelShutdownPreVM(); // Executed in CVScriptGameSystem
|
||||
void InitPostVM();
|
||||
|
||||
#ifdef GAME_DLL
|
||||
void RecieveMessage( bf_read *msg, CBaseEntity *pPlayer );
|
||||
#else
|
||||
void RecieveMessage( bf_read &msg );
|
||||
#endif
|
||||
void WriteToBuffer( bf_write *bf );
|
||||
|
||||
public:
|
||||
inline void Reset();
|
||||
void Start( const char *msg );
|
||||
#ifdef GAME_DLL
|
||||
void Send( HSCRIPT player, bool bReliable );
|
||||
#else
|
||||
void Send();
|
||||
#endif
|
||||
void Recieve( const char *msg, HSCRIPT func );
|
||||
|
||||
#ifdef GAME_DLL
|
||||
inline void DoSendUserMsg( CRecipientFilter *filter, int type );
|
||||
inline void DoSendEntityMsg( CBaseEntity *entity, bool reliable );
|
||||
|
||||
void SendUserMessage( HSCRIPT hPlayer, const char *msg, bool bReliable );
|
||||
void SendEntityMessage( HSCRIPT hEnt, bool bReliable );
|
||||
#else // CLIENT_DLL
|
||||
void DispatchUserMessage( const char *msg );
|
||||
#endif
|
||||
|
||||
#ifdef GAME_DLL
|
||||
public:
|
||||
void AddRecipient( HSCRIPT player );
|
||||
void AddRecipientsByPVS( const Vector &pos );
|
||||
void AddRecipientsByPAS( const Vector &pos );
|
||||
void AddAllPlayers();
|
||||
#endif // GAME_DLL
|
||||
|
||||
public:
|
||||
void WriteInt( int iValue, int bits );
|
||||
void WriteUInt( int iValue, int bits );
|
||||
void WriteByte( int iValue ); // 8 bit unsigned char
|
||||
void WriteChar( int iValue ); // 8 bit char
|
||||
void WriteShort( int iValue ); // 16 bit short
|
||||
void WriteWord( int iValue ); // 16 bit unsigned short
|
||||
void WriteLong( int iValue ); // 32 bit long
|
||||
void WriteFloat( float flValue );
|
||||
void WriteNormal( float flValue ); // 12 bit
|
||||
void WriteAngle( float flValue ); // 8 bit unsigned char
|
||||
void WriteCoord( float flValue );
|
||||
void WriteVec3Coord( const Vector& rgflValue );
|
||||
void WriteVec3Normal( const Vector& rgflValue ); // 27 bit ( 3 + 2 * (1 + NORMAL_FRACTIONAL_BITS) )
|
||||
void WriteAngles( const QAngle& rgflValue );
|
||||
void WriteString( const char *sz ); // max 512 bytes at once
|
||||
void WriteBool( bool bValue ); // 1 bit
|
||||
void WriteEntity( HSCRIPT hEnt ); // 11 bit (entindex)
|
||||
void WriteEHandle( HSCRIPT hEnt ); // 32 bit long
|
||||
int ReadInt( int bits );
|
||||
int ReadUInt( int bits );
|
||||
int ReadByte();
|
||||
int ReadChar();
|
||||
int ReadShort();
|
||||
int ReadWord();
|
||||
int ReadLong();
|
||||
float ReadFloat();
|
||||
float ReadNormal();
|
||||
float ReadAngle();
|
||||
float ReadCoord();
|
||||
const Vector& ReadVec3Coord();
|
||||
const Vector& ReadVec3Normal();
|
||||
const QAngle& ReadAngles();
|
||||
const char* ReadString();
|
||||
bool ReadBool();
|
||||
HSCRIPT ReadEntity();
|
||||
HSCRIPT ReadEHandle();
|
||||
//int GetNumBitsLeft(); // unreliable on server because of usercmds. so just do away with it
|
||||
int GetNumBitsWritten();
|
||||
|
||||
};
|
||||
|
||||
extern CNetMsgScriptHelper *g_ScriptNetMsg;
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
void VScriptSaveRestoreUtil_OnVMRestore();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -174,6 +174,10 @@ void RagdollSetupAnimatedFriction( IPhysicsEnvironment *pPhysEnv, ragdoll_t *rag
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MAPBASE
|
||||
ConVar g_ragdoll_fixed_constraints_mass( "g_ragdoll_fixed_constraints_mass", "1000", FCVAR_REPLICATED );
|
||||
#endif
|
||||
|
||||
static void RagdollAddSolid( IPhysicsEnvironment *pPhysEnv, ragdoll_t &ragdoll, const ragdollparams_t ¶ms, solid_t &solid )
|
||||
{
|
||||
if ( solid.index >= 0 && solid.index < params.pCollide->solidCount)
|
||||
@ -186,7 +190,12 @@ static void RagdollAddSolid( IPhysicsEnvironment *pPhysEnv, ragdoll_t &ragdoll,
|
||||
{
|
||||
if ( params.fixedConstraints )
|
||||
{
|
||||
#ifdef MAPBASE
|
||||
if (g_ragdoll_fixed_constraints_mass.GetFloat() != -1)
|
||||
solid.params.mass = g_ragdoll_fixed_constraints_mass.GetFloat();
|
||||
#else
|
||||
solid.params.mass = 1000.f;
|
||||
#endif
|
||||
}
|
||||
|
||||
solid.params.rotInertiaLimit = 0.1;
|
||||
|
@ -10,12 +10,20 @@
|
||||
#include "bitbuf.h"
|
||||
#include "checksum_md5.h"
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
#include "mapbase/vscript_singletons.h"
|
||||
#endif
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
// TF2 specific, need enough space for OBJ_LAST items from tf_shareddefs.h
|
||||
#define WEAPON_SUBTYPE_BITS 6
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
extern CNetMsgScriptHelper *g_ScriptNetMsg;
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Write a delta compressed user command.
|
||||
// Input : *buf -
|
||||
@ -187,6 +195,22 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined( MAPBASE_VSCRIPT ) && defined( CLIENT_DLL )
|
||||
Assert( g_ScriptNetMsg );
|
||||
|
||||
if ( g_ScriptNetMsg->m_bWriteReady )
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
g_ScriptNetMsg->WriteToBuffer( buf );
|
||||
g_ScriptNetMsg->m_bWriteReady = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->WriteOneBit( 0 );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -196,7 +220,11 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
||||
// *from -
|
||||
// Output : static void ReadUsercmd
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( MAPBASE_VSCRIPT ) && defined( GAME_DLL )
|
||||
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from, CBaseEntity *pPlayer )
|
||||
#else
|
||||
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
||||
#endif
|
||||
{
|
||||
// Assume no change
|
||||
*move = *from;
|
||||
@ -303,4 +331,12 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined( MAPBASE_VSCRIPT ) && defined( GAME_DLL )
|
||||
if ( buf->ReadOneBit() )
|
||||
{
|
||||
g_ScriptNetMsg->RecieveMessage( buf, pPlayer );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -198,7 +198,11 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#if defined( MAPBASE_VSCRIPT ) && defined( GAME_DLL )
|
||||
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from, CBaseEntity *pPlayer );
|
||||
#else
|
||||
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from );
|
||||
#endif
|
||||
void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from );
|
||||
|
||||
#endif // USERCMD_H
|
||||
|
@ -13,6 +13,10 @@
|
||||
|
||||
void RegisterUserMessages( void );
|
||||
|
||||
#ifdef MAPBASE
|
||||
void RegisterMapbaseUserMessages( void );
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Force registration on .dll load
|
||||
// FIXME: Should this be a client/server system?
|
||||
@ -21,6 +25,11 @@ CUserMessages::CUserMessages()
|
||||
{
|
||||
// Game specific registration function;
|
||||
RegisterUserMessages();
|
||||
|
||||
#ifdef MAPBASE
|
||||
// Mapbase registration function;
|
||||
RegisterMapbaseUserMessages();
|
||||
#endif
|
||||
}
|
||||
|
||||
CUserMessages::~CUserMessages()
|
||||
|
@ -13,6 +13,9 @@
|
||||
#include "characterset.h"
|
||||
#include "isaverestore.h"
|
||||
#include "gamerules.h"
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
#include "mapbase/vscript_singletons.h"
|
||||
#endif
|
||||
|
||||
IScriptVM * g_pScriptVM;
|
||||
extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
|
||||
@ -142,6 +145,9 @@ bool VScriptRunScript( const char *pszScriptName, HSCRIPT hScope, bool bWarnMiss
|
||||
bool bSuccess = false;
|
||||
if ( hScript )
|
||||
{
|
||||
// player is not yet spawned, this block is always skipped.
|
||||
// It is registered in CBasePlayer instead.
|
||||
#ifndef MAPBASE
|
||||
#ifdef GAME_DLL
|
||||
if ( gpGlobals->maxClients == 1 )
|
||||
{
|
||||
@ -151,6 +157,7 @@ bool VScriptRunScript( const char *pszScriptName, HSCRIPT hScope, bool bWarnMiss
|
||||
g_pScriptVM->SetValue( "player", pPlayer->GetScriptInstance() );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
bSuccess = ( g_pScriptVM->Run( hScript, hScope ) != SCRIPT_ERROR );
|
||||
if ( !bSuccess )
|
||||
@ -262,7 +269,7 @@ CON_COMMAND_SHARED( script_help, "Output help for script functions, optionally w
|
||||
pszArg1 = args[1];
|
||||
}
|
||||
|
||||
g_pScriptVM->Run( CFmtStr( "PrintHelp( \"%s\" );", pszArg1 ) );
|
||||
g_pScriptVM->Run( CFmtStr( "__Documentation.PrintHelp( \"%s\" );", pszArg1 ) );
|
||||
}
|
||||
|
||||
CON_COMMAND_SHARED( script_dump_all, "Dump the state of the VM to the console" )
|
||||
@ -274,3 +281,187 @@ CON_COMMAND_SHARED( script_dump_all, "Dump the state of the VM to the console" )
|
||||
}
|
||||
g_pScriptVM->DumpState();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static short VSCRIPT_SERVER_SAVE_RESTORE_VERSION = 2;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class CVScriptSaveRestoreBlockHandler : public CDefSaveRestoreBlockHandler
|
||||
{
|
||||
public:
|
||||
CVScriptSaveRestoreBlockHandler() :
|
||||
m_InstanceMap( DefLessFunc(const char *) )
|
||||
{
|
||||
}
|
||||
const char *GetBlockName()
|
||||
{
|
||||
#ifdef CLIENT_DLL
|
||||
return "VScriptClient";
|
||||
#else
|
||||
return "VScriptServer";
|
||||
#endif
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
void Save( ISave *pSave )
|
||||
{
|
||||
pSave->StartBlock();
|
||||
|
||||
int temp = g_pScriptVM != NULL;
|
||||
pSave->WriteInt( &temp );
|
||||
if ( g_pScriptVM )
|
||||
{
|
||||
temp = g_pScriptVM->GetLanguage();
|
||||
pSave->WriteInt( &temp );
|
||||
CUtlBuffer buffer;
|
||||
g_pScriptVM->WriteState( &buffer );
|
||||
temp = buffer.TellPut();
|
||||
pSave->WriteInt( &temp );
|
||||
if ( temp > 0 )
|
||||
{
|
||||
pSave->WriteData( (const char *)buffer.Base(), temp );
|
||||
}
|
||||
}
|
||||
|
||||
pSave->EndBlock();
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
void WriteSaveHeaders( ISave *pSave )
|
||||
{
|
||||
pSave->WriteShort( &VSCRIPT_SERVER_SAVE_RESTORE_VERSION );
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
void ReadRestoreHeaders( IRestore *pRestore )
|
||||
{
|
||||
// No reason why any future version shouldn't try to retain backward compatability. The default here is to not do so.
|
||||
short version;
|
||||
pRestore->ReadShort( &version );
|
||||
m_fDoLoad = ( version == VSCRIPT_SERVER_SAVE_RESTORE_VERSION );
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
void Restore( IRestore *pRestore, bool createPlayers )
|
||||
{
|
||||
if ( !m_fDoLoad && g_pScriptVM )
|
||||
{
|
||||
return;
|
||||
}
|
||||
#ifdef CLIENT_DLL
|
||||
C_BaseEntity *pEnt = ClientEntityList().FirstBaseEntity();
|
||||
#else
|
||||
CBaseEntity *pEnt = gEntList.FirstEnt();
|
||||
#endif
|
||||
while ( pEnt )
|
||||
{
|
||||
if ( pEnt->m_iszScriptId != NULL_STRING )
|
||||
{
|
||||
#ifndef MAPBASE_VSCRIPT
|
||||
g_pScriptVM->RegisterClass( pEnt->GetScriptDesc() );
|
||||
#endif
|
||||
m_InstanceMap.Insert( STRING( pEnt->m_iszScriptId ), pEnt );
|
||||
}
|
||||
#ifdef CLIENT_DLL
|
||||
pEnt = ClientEntityList().NextBaseEntity( pEnt );
|
||||
#else
|
||||
pEnt = gEntList.NextEnt( pEnt );
|
||||
#endif
|
||||
}
|
||||
|
||||
pRestore->StartBlock();
|
||||
if ( pRestore->ReadInt() && pRestore->ReadInt() == g_pScriptVM->GetLanguage() )
|
||||
{
|
||||
int nBytes = pRestore->ReadInt();
|
||||
if ( nBytes > 0 )
|
||||
{
|
||||
CUtlBuffer buffer;
|
||||
buffer.EnsureCapacity( nBytes );
|
||||
pRestore->ReadData( (char *)buffer.AccessForDirectRead( nBytes ), nBytes, 0 );
|
||||
g_pScriptVM->ReadState( &buffer );
|
||||
}
|
||||
}
|
||||
pRestore->EndBlock();
|
||||
}
|
||||
|
||||
void PostRestore( void )
|
||||
{
|
||||
for ( int i = m_InstanceMap.FirstInorder(); i != m_InstanceMap.InvalidIndex(); i = m_InstanceMap.NextInorder( i ) )
|
||||
{
|
||||
CBaseEntity *pEnt = m_InstanceMap[i];
|
||||
if ( pEnt->m_hScriptInstance )
|
||||
{
|
||||
ScriptVariant_t variant;
|
||||
if ( g_pScriptVM->GetValue( STRING(pEnt->m_iszScriptId), &variant ) && variant.m_type == FIELD_HSCRIPT )
|
||||
{
|
||||
pEnt->m_ScriptScope.Init( variant.m_hScript, false );
|
||||
#ifndef CLIENT_DLL
|
||||
pEnt->RunPrecacheScripts();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Script system probably has no internal references
|
||||
pEnt->m_iszScriptId = NULL_STRING;
|
||||
}
|
||||
}
|
||||
m_InstanceMap.Purge();
|
||||
|
||||
#if defined(MAPBASE_VSCRIPT) && defined(CLIENT_DLL)
|
||||
VScriptSaveRestoreUtil_OnVMRestore();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
CUtlMap<const char *, CBaseEntity *> m_InstanceMap;
|
||||
|
||||
private:
|
||||
bool m_fDoLoad;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
CVScriptSaveRestoreBlockHandler g_VScriptSaveRestoreBlockHandler;
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
ISaveRestoreBlockHandler *GetVScriptSaveRestoreBlockHandler()
|
||||
{
|
||||
return &g_VScriptSaveRestoreBlockHandler;
|
||||
}
|
||||
|
||||
bool CBaseEntityScriptInstanceHelper::ToString( void *p, char *pBuf, int bufSize )
|
||||
{
|
||||
CBaseEntity *pEntity = (CBaseEntity *)p;
|
||||
if ( pEntity->GetEntityName() != NULL_STRING )
|
||||
{
|
||||
V_snprintf( pBuf, bufSize, "([%d] %s: %s)", pEntity->entindex(), STRING(pEntity->m_iClassname), STRING( pEntity->GetEntityName() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
V_snprintf( pBuf, bufSize, "([%d] %s)", pEntity->entindex(), STRING(pEntity->m_iClassname) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void *CBaseEntityScriptInstanceHelper::BindOnRead( HSCRIPT hInstance, void *pOld, const char *pszId )
|
||||
{
|
||||
int iEntity = g_VScriptSaveRestoreBlockHandler.m_InstanceMap.Find( pszId );
|
||||
if ( iEntity != g_VScriptSaveRestoreBlockHandler.m_InstanceMap.InvalidIndex() )
|
||||
{
|
||||
CBaseEntity *pEnt = g_VScriptSaveRestoreBlockHandler.m_InstanceMap[iEntity];
|
||||
pEnt->m_hScriptInstance = hInstance;
|
||||
return pEnt;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
CBaseEntityScriptInstanceHelper g_BaseEntityScriptInstanceHelper;
|
||||
|
@ -31,6 +31,17 @@ inline bool VScriptRunScript( const char *pszScriptName, bool bWarnMissing = fal
|
||||
// Only allow scripts to create entities during map initialization
|
||||
bool IsEntityCreationAllowedInScripts( void );
|
||||
|
||||
class ISaveRestoreBlockHandler;
|
||||
ISaveRestoreBlockHandler *GetVScriptSaveRestoreBlockHandler();
|
||||
|
||||
class CBaseEntityScriptInstanceHelper : public IScriptInstanceHelper
|
||||
{
|
||||
bool ToString( void *p, char *pBuf, int bufSize );
|
||||
void *BindOnRead( HSCRIPT hInstance, void *pOld, const char *pszId );
|
||||
};
|
||||
|
||||
extern CBaseEntityScriptInstanceHelper g_BaseEntityScriptInstanceHelper;
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
void RegisterSharedScriptConstants();
|
||||
void RegisterSharedScriptFunctions();
|
||||
|
@ -695,29 +695,16 @@ struct ScriptEnumDesc_t
|
||||
#define BEGIN_SCRIPTDESC( className, baseClass, description ) BEGIN_SCRIPTDESC_NAMED( className, baseClass, #className, description )
|
||||
#define BEGIN_SCRIPTDESC_ROOT( className, description ) BEGIN_SCRIPTDESC_ROOT_NAMED( className, #className, description )
|
||||
|
||||
#ifdef MSVC
|
||||
#define DEFINE_SCRIPTDESC_FUNCTION( className, baseClass ) \
|
||||
ScriptClassDesc_t * GetScriptDesc( className * )
|
||||
#else
|
||||
#define DEFINE_SCRIPTDESC_FUNCTION( className, baseClass ) \
|
||||
template <> ScriptClassDesc_t * GetScriptDesc<baseClass>( baseClass *); \
|
||||
template <> ScriptClassDesc_t * GetScriptDesc<className>( className *)
|
||||
#endif
|
||||
|
||||
#define BEGIN_SCRIPTDESC_NAMED( className, baseClass, scriptName, description ) \
|
||||
ScriptClassDesc_t g_##className##_ScriptDesc; \
|
||||
DEFINE_SCRIPTDESC_FUNCTION( className, baseClass ) \
|
||||
template <> ScriptClassDesc_t* GetScriptDesc<baseClass>(baseClass*); \
|
||||
template <> ScriptClassDesc_t* GetScriptDesc<className>(className*); \
|
||||
ScriptClassDesc_t & g_##className##_ScriptDesc = *GetScriptDesc<className>(nullptr); \
|
||||
template <> ScriptClassDesc_t* GetScriptDesc<className>(className*) \
|
||||
{ \
|
||||
static bool bInitialized; \
|
||||
if ( bInitialized ) \
|
||||
{ \
|
||||
return &g_##className##_ScriptDesc; \
|
||||
} \
|
||||
\
|
||||
bInitialized = true; \
|
||||
\
|
||||
static ScriptClassDesc_t g_##className##_ScriptDesc; \
|
||||
typedef className _className; \
|
||||
ScriptClassDesc_t *pDesc = &g_##className##_ScriptDesc; \
|
||||
if (pDesc->m_pszClassname) return pDesc; \
|
||||
pDesc->m_pszDescription = description; \
|
||||
ScriptInitClassDescNamed( pDesc, className, GetScriptDescForClass( baseClass ), scriptName ); \
|
||||
ScriptClassDesc_t *pInstanceHelperBase = pDesc->m_pBaseDesc; \
|
||||
@ -762,6 +749,9 @@ struct ScriptEnumDesc_t
|
||||
|
||||
#define DEFINE_SCRIPTHOOK_PARAM( paramName, type ) pHook->AddParameter( paramName, type );
|
||||
|
||||
// Define actual parameters instead of global variables
|
||||
#define DEFINE_SCRIPTHOOK_REALPARAM( paramName, type )
|
||||
|
||||
#define END_SCRIPTHOOK() \
|
||||
pDesc->m_Hooks.AddToTail(pHook); \
|
||||
}
|
||||
@ -932,6 +922,9 @@ public:
|
||||
virtual bool SetValue( HSCRIPT hScope, const char *pszKey, const char *pszValue ) = 0;
|
||||
virtual bool SetValue( HSCRIPT hScope, const char *pszKey, const ScriptVariant_t &value ) = 0;
|
||||
bool SetValue( const char *pszKey, const ScriptVariant_t &value ) { return SetValue(NULL, pszKey, value ); }
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
virtual bool SetValue( HSCRIPT hScope, const ScriptVariant_t& key, const ScriptVariant_t& val ) = 0;
|
||||
#endif
|
||||
|
||||
virtual void CreateTable( ScriptVariant_t &Table ) = 0;
|
||||
virtual int GetNumTableEntries( HSCRIPT hScope ) = 0;
|
||||
@ -939,10 +932,16 @@ public:
|
||||
|
||||
virtual bool GetValue( HSCRIPT hScope, const char *pszKey, ScriptVariant_t *pValue ) = 0;
|
||||
bool GetValue( const char *pszKey, ScriptVariant_t *pValue ) { return GetValue(NULL, pszKey, pValue ); }
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
virtual bool GetValue( HSCRIPT hScope, ScriptVariant_t key, ScriptVariant_t* pValue ) = 0;
|
||||
#endif
|
||||
virtual void ReleaseValue( ScriptVariant_t &value ) = 0;
|
||||
|
||||
virtual bool ClearValue( HSCRIPT hScope, const char *pszKey ) = 0;
|
||||
bool ClearValue( const char *pszKey) { return ClearValue( NULL, pszKey ); }
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
virtual bool ClearValue( HSCRIPT hScope, ScriptVariant_t pKey ) = 0;
|
||||
#endif
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
// virtual void CreateArray(ScriptVariant_t &arr, int size = 0) = 0;
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "squirrel/squirrel/sqvm.h"
|
||||
#include "squirrel/squirrel/sqclosure.h"
|
||||
|
||||
#include "color.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier1/mapbase_con_groups.h"
|
||||
|
||||
@ -79,25 +78,35 @@ struct ReadStateMap
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckCache(CUtlBuffer* pBuffer, HSQOBJECT** obj)
|
||||
bool CheckCache(CUtlBuffer* pBuffer, HSQUIRRELVM vm, int * outmarker)
|
||||
{
|
||||
int marker = pBuffer->GetInt();
|
||||
|
||||
auto idx = cache.Find(marker);
|
||||
if (idx != cache.InvalidIndex())
|
||||
{
|
||||
*obj = &cache[idx];
|
||||
sq_pushobject(vm, cache[idx]);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSQOBJECT temp;
|
||||
sq_resetobject(&temp);
|
||||
auto idx = cache.Insert(marker, temp);
|
||||
*obj = &cache[idx];
|
||||
*outmarker = marker;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void StoreInCache(int marker, HSQOBJECT& obj)
|
||||
{
|
||||
cache.Insert(marker, obj);
|
||||
}
|
||||
|
||||
void StoreTopInCache(int marker)
|
||||
{
|
||||
HSQOBJECT obj;
|
||||
sq_getstackobj(vm_, -1, &obj);
|
||||
sq_addref(vm_, &obj);
|
||||
cache.Insert(marker, obj);
|
||||
}
|
||||
};
|
||||
|
||||
class SquirrelVM : public IScriptVM
|
||||
@ -192,15 +201,18 @@ public:
|
||||
|
||||
virtual bool SetValue(HSCRIPT hScope, const char* pszKey, const char* pszValue) override;
|
||||
virtual bool SetValue(HSCRIPT hScope, const char* pszKey, const ScriptVariant_t& value) override;
|
||||
virtual bool SetValue(HSCRIPT hScope, const ScriptVariant_t& key, const ScriptVariant_t& val) override;
|
||||
|
||||
virtual void CreateTable(ScriptVariant_t& Table) override;
|
||||
virtual int GetNumTableEntries(HSCRIPT hScope) override;
|
||||
virtual int GetKeyValue(HSCRIPT hScope, int nIterator, ScriptVariant_t* pKey, ScriptVariant_t* pValue) override;
|
||||
|
||||
virtual bool GetValue(HSCRIPT hScope, const char* pszKey, ScriptVariant_t* pValue) override;
|
||||
virtual bool GetValue(HSCRIPT hScope, ScriptVariant_t key, ScriptVariant_t* pValue) override;
|
||||
virtual void ReleaseValue(ScriptVariant_t& value) override;
|
||||
|
||||
virtual bool ClearValue(HSCRIPT hScope, const char* pszKey) override;
|
||||
virtual bool ClearValue( HSCRIPT hScope, ScriptVariant_t pKey ) override;
|
||||
|
||||
// virtual void CreateArray(ScriptVariant_t &arr, int size = 0) override;
|
||||
virtual bool ArrayAppend(HSCRIPT hArray, const ScriptVariant_t &val) override;
|
||||
@ -1408,6 +1420,19 @@ const char * ScriptDataTypeToName(ScriptDataType_t datatype)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define PushDocumentationRegisterFunction( szName ) \
|
||||
sq_pushroottable(vm); \
|
||||
sq_pushstring(vm, "__Documentation", -1); \
|
||||
sq_get(vm, -2); \
|
||||
sq_pushstring(vm, szName, -1); \
|
||||
sq_get(vm, -2); \
|
||||
sq_push(vm, -2);
|
||||
|
||||
#define CallDocumentationRegisterFunction( paramcount ) \
|
||||
sq_call(vm, paramcount+1, SQFalse, SQFalse); \
|
||||
sq_pop(vm, 3);
|
||||
|
||||
void RegisterDocumentation(HSQUIRRELVM vm, const ScriptFuncDescriptor_t& pFuncDesc, ScriptClassDesc_t* pClassDesc = nullptr)
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm);
|
||||
@ -1440,16 +1465,11 @@ void RegisterDocumentation(HSQUIRRELVM vm, const ScriptFuncDescriptor_t& pFuncDe
|
||||
V_strcat_safe(signature, ")");
|
||||
|
||||
// RegisterHelp(name, signature, description)
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "RegisterHelp", -1);
|
||||
sq_get(vm, -2);
|
||||
sq_remove(vm, -2);
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, signature, -1);
|
||||
sq_pushstring(vm, pFuncDesc.m_pszDescription ? pFuncDesc.m_pszDescription : "", -1);
|
||||
sq_call(vm, 4, SQFalse, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
PushDocumentationRegisterFunction( "RegisterHelp" );
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, signature, -1);
|
||||
sq_pushstring(vm, pFuncDesc.m_pszDescription ? pFuncDesc.m_pszDescription : "", -1);
|
||||
CallDocumentationRegisterFunction( 3 );
|
||||
}
|
||||
|
||||
void RegisterClassDocumentation(HSQUIRRELVM vm, const ScriptClassDesc_t* pClassDesc)
|
||||
@ -1477,16 +1497,11 @@ void RegisterClassDocumentation(HSQUIRRELVM vm, const ScriptClassDesc_t* pClassD
|
||||
}
|
||||
|
||||
// RegisterClassHelp(name, base, description)
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "RegisterClassHelp", -1);
|
||||
sq_get(vm, -2);
|
||||
sq_remove(vm, -2);
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, base, -1);
|
||||
sq_pushstring(vm, description, -1);
|
||||
sq_call(vm, 4, SQFalse, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
PushDocumentationRegisterFunction( "RegisterClassHelp" );
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, base, -1);
|
||||
sq_pushstring(vm, description, -1);
|
||||
CallDocumentationRegisterFunction( 3 );
|
||||
}
|
||||
|
||||
void RegisterEnumDocumentation(HSQUIRRELVM vm, const ScriptEnumDesc_t* pClassDesc)
|
||||
@ -1499,16 +1514,11 @@ void RegisterEnumDocumentation(HSQUIRRELVM vm, const ScriptEnumDesc_t* pClassDes
|
||||
const char *name = pClassDesc->m_pszScriptName;
|
||||
|
||||
// RegisterEnumHelp(name, description)
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "RegisterEnumHelp", -1);
|
||||
sq_get(vm, -2);
|
||||
sq_remove(vm, -2);
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushinteger(vm, pClassDesc->m_ConstantBindings.Count());
|
||||
sq_pushstring(vm, pClassDesc->m_pszDescription ? pClassDesc->m_pszDescription : "", -1);
|
||||
sq_call(vm, 4, SQFalse, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
PushDocumentationRegisterFunction( "RegisterEnumHelp" );
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushinteger(vm, pClassDesc->m_ConstantBindings.Count());
|
||||
sq_pushstring(vm, pClassDesc->m_pszDescription ? pClassDesc->m_pszDescription : "", -1);
|
||||
CallDocumentationRegisterFunction( 3 );
|
||||
}
|
||||
|
||||
void RegisterConstantDocumentation( HSQUIRRELVM vm, const ScriptConstantBinding_t* pConstDesc, const char *pszAsString, ScriptEnumDesc_t* pEnumDesc = nullptr )
|
||||
@ -1532,16 +1542,11 @@ void RegisterConstantDocumentation( HSQUIRRELVM vm, const ScriptConstantBinding_
|
||||
V_snprintf(signature, sizeof(signature), "%s (%s)", pszAsString, ScriptDataTypeToName(pConstDesc->m_data.m_type));
|
||||
|
||||
// RegisterConstHelp(name, signature, description)
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "RegisterConstHelp", -1);
|
||||
sq_get(vm, -2);
|
||||
sq_remove(vm, -2);
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, signature, -1);
|
||||
sq_pushstring(vm, pConstDesc->m_pszDescription ? pConstDesc->m_pszDescription : "", -1);
|
||||
sq_call(vm, 4, SQFalse, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
PushDocumentationRegisterFunction( "RegisterConstHelp" );
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, signature, -1);
|
||||
sq_pushstring(vm, pConstDesc->m_pszDescription ? pConstDesc->m_pszDescription : "", -1);
|
||||
CallDocumentationRegisterFunction( 3 );
|
||||
}
|
||||
|
||||
void RegisterHookDocumentation(HSQUIRRELVM vm, const ScriptHook_t* pHook, const ScriptFuncDescriptor_t& pFuncDesc, ScriptClassDesc_t* pClassDesc = nullptr)
|
||||
@ -1579,16 +1584,11 @@ void RegisterHookDocumentation(HSQUIRRELVM vm, const ScriptHook_t* pHook, const
|
||||
V_strcat_safe(signature, ")");
|
||||
|
||||
// RegisterHookHelp(name, signature, description)
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "RegisterHookHelp", -1);
|
||||
sq_get(vm, -2);
|
||||
sq_remove(vm, -2);
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, signature, -1);
|
||||
sq_pushstring(vm, pFuncDesc.m_pszDescription ? pFuncDesc.m_pszDescription : "", -1);
|
||||
sq_call(vm, 4, SQFalse, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
PushDocumentationRegisterFunction( "RegisterHookHelp" );
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, signature, -1);
|
||||
sq_pushstring(vm, pFuncDesc.m_pszDescription ? pFuncDesc.m_pszDescription : "", -1);
|
||||
CallDocumentationRegisterFunction( 3 );
|
||||
}
|
||||
|
||||
void RegisterMemberDocumentation(HSQUIRRELVM vm, const ScriptMemberDesc_t& pDesc, ScriptClassDesc_t* pClassDesc = nullptr)
|
||||
@ -1609,21 +1609,15 @@ void RegisterMemberDocumentation(HSQUIRRELVM vm, const ScriptMemberDesc_t& pDesc
|
||||
if (pDesc.m_pszScriptName)
|
||||
V_strcat_safe(name, pDesc.m_pszScriptName);
|
||||
|
||||
|
||||
char signature[256] = "";
|
||||
V_snprintf(signature, sizeof(signature), "%s %s", ScriptDataTypeToName(pDesc.m_ReturnType), name);
|
||||
|
||||
// RegisterHookHelp(name, signature, description)
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "RegisterMemberHelp", -1);
|
||||
sq_get(vm, -2);
|
||||
sq_remove(vm, -2);
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, signature, -1);
|
||||
sq_pushstring(vm, pDesc.m_pszDescription ? pDesc.m_pszDescription : "", -1);
|
||||
sq_call(vm, 4, SQFalse, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
// RegisterMemberHelp(name, signature, description)
|
||||
PushDocumentationRegisterFunction( "RegisterMemberHelp" );
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushstring(vm, signature, -1);
|
||||
sq_pushstring(vm, pDesc.m_pszDescription ? pDesc.m_pszDescription : "", -1);
|
||||
CallDocumentationRegisterFunction( 3 );
|
||||
}
|
||||
|
||||
|
||||
@ -2439,6 +2433,41 @@ bool SquirrelVM::SetValue(HSCRIPT hScope, const char* pszKey, const ScriptVarian
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SquirrelVM::SetValue( HSCRIPT hScope, const ScriptVariant_t& key, const ScriptVariant_t& val )
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm_);
|
||||
HSQOBJECT obj = *(HSQOBJECT*)hScope;
|
||||
if (hScope)
|
||||
{
|
||||
Assert(hScope != INVALID_HSCRIPT);
|
||||
sq_pushobject(vm_, obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
sq_pushroottable(vm_);
|
||||
}
|
||||
|
||||
if ( sq_isarray(obj) )
|
||||
{
|
||||
Assert( key.m_type == FIELD_INTEGER );
|
||||
|
||||
sq_pushinteger(vm_, key.m_int);
|
||||
PushVariant(vm_, val);
|
||||
|
||||
sq_set(vm_, -3);
|
||||
}
|
||||
else
|
||||
{
|
||||
PushVariant(vm_, key);
|
||||
PushVariant(vm_, val);
|
||||
|
||||
sq_newslot(vm_, -3, SQFalse);
|
||||
}
|
||||
|
||||
sq_pop(vm_, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SquirrelVM::CreateTable(ScriptVariant_t& Table)
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm_);
|
||||
@ -2454,15 +2483,17 @@ void SquirrelVM::CreateTable(ScriptVariant_t& Table)
|
||||
Table = (HSCRIPT)obj;
|
||||
}
|
||||
|
||||
//
|
||||
// input table/array/class/instance/string
|
||||
//
|
||||
int SquirrelVM::GetNumTableEntries(HSCRIPT hScope)
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm_);
|
||||
|
||||
if (!hScope)
|
||||
{
|
||||
// TODO: This is called hScope but seems like just a table so
|
||||
// lets not fallback to root table
|
||||
return 0;
|
||||
// sq_getsize returns -1 on invalid input
|
||||
return -1;
|
||||
}
|
||||
|
||||
HSQOBJECT* scope = (HSQOBJECT*)hScope;
|
||||
@ -2555,6 +2586,47 @@ bool SquirrelVM::GetValue(HSCRIPT hScope, const char* pszKey, ScriptVariant_t* p
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SquirrelVM::GetValue( HSCRIPT hScope, ScriptVariant_t key, ScriptVariant_t* pValue )
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm_);
|
||||
|
||||
Assert(pValue);
|
||||
if (!pValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hScope)
|
||||
{
|
||||
HSQOBJECT* scope = (HSQOBJECT*)hScope;
|
||||
Assert(hScope != INVALID_HSCRIPT);
|
||||
sq_pushobject(vm_, *scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
sq_pushroottable(vm_);
|
||||
}
|
||||
|
||||
PushVariant(vm_, key);
|
||||
|
||||
if (sq_get(vm_, -2) != SQ_OK)
|
||||
{
|
||||
sq_pop(vm_, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!getVariant(vm_, -1, *pValue))
|
||||
{
|
||||
sq_pop(vm_, 2);
|
||||
return false;
|
||||
}
|
||||
|
||||
sq_pop(vm_, 2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SquirrelVM::ReleaseValue(ScriptVariant_t& value)
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm_);
|
||||
@ -2599,6 +2671,33 @@ bool SquirrelVM::ClearValue(HSCRIPT hScope, const char* pszKey)
|
||||
sq_pop(vm_, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SquirrelVM::ClearValue(HSCRIPT hScope, ScriptVariant_t pKey)
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm_);
|
||||
|
||||
if (hScope)
|
||||
{
|
||||
HSQOBJECT* scope = (HSQOBJECT*)hScope;
|
||||
Assert(hScope != INVALID_HSCRIPT);
|
||||
sq_pushobject(vm_, *scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
sq_pushroottable(vm_);
|
||||
}
|
||||
|
||||
PushVariant(vm_, pKey);
|
||||
if (SQ_FAILED(sq_deleteslot(vm_, -2, SQFalse)))
|
||||
{
|
||||
sq_pop(vm_, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
sq_pop(vm_, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
void SquirrelVM::CreateArray(ScriptVariant_t &arr, int size)
|
||||
{
|
||||
@ -2619,9 +2718,11 @@ bool SquirrelVM::ArrayAppend(HSCRIPT hArray, const ScriptVariant_t &val)
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm_);
|
||||
|
||||
HSQOBJECT *arr = (HSQOBJECT*)hArray;
|
||||
HSQOBJECT arr = *(HSQOBJECT*)hArray;
|
||||
if ( !sq_isarray(arr) )
|
||||
return false;
|
||||
|
||||
sq_pushobject(vm_, *arr);
|
||||
sq_pushobject(vm_, arr);
|
||||
PushVariant(vm_, val);
|
||||
bool ret = sq_arrayappend(vm_, -2) == SQ_OK;
|
||||
sq_pop(vm_, 1);
|
||||
@ -3085,10 +3186,9 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
}
|
||||
case OT_TABLE:
|
||||
{
|
||||
HSQOBJECT* obj = nullptr;
|
||||
if (readState.CheckCache(pBuffer, &obj))
|
||||
int marker = 0;
|
||||
if (readState.CheckCache(pBuffer, vm_, &marker))
|
||||
{
|
||||
sq_pushobject(vm_, *obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3096,8 +3196,7 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
|
||||
int count = pBuffer->GetInt();
|
||||
sq_newtableex(vm_, count);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
readState.StoreTopInCache(marker);
|
||||
|
||||
sq_push(vm_, -2);
|
||||
sq_setdelegate(vm_, -2);
|
||||
@ -3115,17 +3214,15 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
}
|
||||
case OT_ARRAY:
|
||||
{
|
||||
HSQOBJECT* obj = nullptr;
|
||||
if (readState.CheckCache(pBuffer, &obj))
|
||||
int marker = 0;
|
||||
if (readState.CheckCache(pBuffer, vm_, &marker))
|
||||
{
|
||||
sq_pushobject(vm_, *obj);
|
||||
break;
|
||||
}
|
||||
|
||||
int count = pBuffer->GetInt();
|
||||
sq_newarray(vm_, count);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
readState.StoreTopInCache(marker);
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
@ -3137,10 +3234,9 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
}
|
||||
case OT_CLOSURE:
|
||||
{
|
||||
HSQOBJECT* obj = nullptr;
|
||||
if (readState.CheckCache(pBuffer, &obj))
|
||||
int marker = 0;
|
||||
if (readState.CheckCache(pBuffer, vm_, &marker))
|
||||
{
|
||||
sq_pushobject(vm_, *obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3152,8 +3248,8 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
sq_pushnull(vm_);
|
||||
break;
|
||||
}
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
|
||||
readState.StoreTopInCache(marker);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3187,9 +3283,8 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
sq_poptop(vm_);
|
||||
}
|
||||
|
||||
*obj = ret;
|
||||
sq_addref(vm_, obj);
|
||||
sq_pushobject(vm_, *obj);
|
||||
vm_->Push(ret);
|
||||
readState.StoreTopInCache(marker);
|
||||
}
|
||||
|
||||
ReadObject(pBuffer, readState);
|
||||
@ -3198,10 +3293,12 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
sq_getstackobj(vm_, -1, &env);
|
||||
if (!sq_isnull(env))
|
||||
{
|
||||
if (_closure( *obj ) == nullptr)
|
||||
HSQOBJECT obj;
|
||||
sq_getstackobj(vm_, -2, &obj);
|
||||
if (_closure(obj) == nullptr)
|
||||
Warning("Closure is null\n");
|
||||
else
|
||||
_closure(*obj)->_env = _refcounted(env)->GetWeakRef(sq_type(env));
|
||||
_closure(obj)->_env = _refcounted(env)->GetWeakRef(sq_type(env));
|
||||
}
|
||||
sq_poptop(vm_);
|
||||
|
||||
@ -3226,10 +3323,9 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
}
|
||||
case OT_CLASS:
|
||||
{
|
||||
HSQOBJECT* obj = nullptr;
|
||||
if (readState.CheckCache(pBuffer, &obj))
|
||||
int marker = 0;
|
||||
if (readState.CheckCache(pBuffer, vm_, &marker))
|
||||
{
|
||||
sq_pushobject(vm_, *obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3238,8 +3334,7 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
if (classType == VectorClassType)
|
||||
{
|
||||
sq_pushobject(vm_, vectorClass_);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
readState.StoreTopInCache(marker);
|
||||
}
|
||||
else if (classType == NativeClassType)
|
||||
{
|
||||
@ -3254,8 +3349,7 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
sq_pushnull(vm_);
|
||||
}
|
||||
sq_remove(vm_, -2);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
readState.StoreTopInCache(marker);
|
||||
}
|
||||
else if (classType == ScriptClassType)
|
||||
{
|
||||
@ -3267,8 +3361,7 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
}
|
||||
|
||||
sq_newclass(vm_, hasBase);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
readState.StoreTopInCache(marker);
|
||||
|
||||
sq_pushnull(vm_);
|
||||
ReadObject(pBuffer, readState);
|
||||
@ -3292,10 +3385,9 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
}
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
HSQOBJECT* obj = nullptr;
|
||||
if (readState.CheckCache(pBuffer, &obj))
|
||||
int marker = 0;
|
||||
if (readState.CheckCache(pBuffer, vm_, &marker))
|
||||
{
|
||||
sq_pushobject(vm_, *obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3310,8 +3402,7 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
ReadObject(pBuffer, readState);
|
||||
sq_call(vm_, 2, SQTrue, SQFalse);
|
||||
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
readState.StoreTopInCache(marker);
|
||||
|
||||
sq_remove(vm_, -2);
|
||||
|
||||
@ -3340,8 +3431,9 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
if (sq_isinstance(singleton) && _instance(singleton)->_class == _class(klass))
|
||||
{
|
||||
foundSingleton = true;
|
||||
*obj = singleton;
|
||||
sq_addref(vm_, obj);
|
||||
|
||||
readState.StoreInCache(marker, singleton);
|
||||
sq_addref(vm_, &singleton);
|
||||
sq_pop(vm_, 2);
|
||||
break;
|
||||
}
|
||||
@ -3355,25 +3447,28 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
((ScriptClassDesc_t*)typetag)->m_pszScriptName);
|
||||
}
|
||||
|
||||
sq_pushobject(vm_, *obj);
|
||||
sq_pushobject(vm_, singleton);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
HSQOBJECT obj;
|
||||
sq_createinstance(vm_, -1);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
sq_getstackobj(vm_, -1, &obj);
|
||||
sq_addref(vm_, &obj);
|
||||
readState.StoreInCache(marker, obj);
|
||||
|
||||
sq_remove(vm_, -2);
|
||||
|
||||
{
|
||||
// HACK: No way to get the default values part from accessing the class directly
|
||||
SQUnsignedInteger nvalues = _instance(*obj)->_class->_defaultvalues.size();
|
||||
SQUnsignedInteger nvalues = _instance(obj)->_class->_defaultvalues.size();
|
||||
for (SQUnsignedInteger n = 0; n < nvalues; n++) {
|
||||
ReadObject(pBuffer, readState);
|
||||
HSQOBJECT val;
|
||||
sq_resetobject(&val);
|
||||
sq_getstackobj(vm_, -1, &val);
|
||||
_instance(*obj)->_values[n] = val;
|
||||
_instance(obj)->_values[n] = val;
|
||||
sq_pop(vm_, 1);
|
||||
}
|
||||
}
|
||||
@ -3436,10 +3531,9 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
}
|
||||
case OT_FUNCPROTO: //internal usage only
|
||||
{
|
||||
HSQOBJECT* obj = nullptr;
|
||||
if (readState.CheckCache(pBuffer, &obj))
|
||||
int marker = 0;
|
||||
if (readState.CheckCache(pBuffer, vm_, &marker))
|
||||
{
|
||||
sq_pushobject(vm_, *obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3452,15 +3546,13 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
}
|
||||
|
||||
vm_->Push(ret);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
readState.StoreTopInCache(marker);
|
||||
}
|
||||
case OT_OUTER: //internal usage only
|
||||
{
|
||||
HSQOBJECT* obj = nullptr;
|
||||
if (readState.CheckCache(pBuffer, &obj))
|
||||
int marker = 0;
|
||||
if (readState.CheckCache(pBuffer, vm_, &marker))
|
||||
{
|
||||
sq_pushobject(vm_, *obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3473,8 +3565,7 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
|
||||
outer->_valptr = &(outer->_value);
|
||||
sq_poptop(vm_);
|
||||
vm_->Push(outer);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
readState.StoreTopInCache(marker);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -3496,10 +3587,12 @@ void SquirrelVM::ReadState(CUtlBuffer* pBuffer)
|
||||
|
||||
sq_pushroottable(vm_);
|
||||
|
||||
HSQOBJECT* obj = nullptr;
|
||||
readState.CheckCache(pBuffer, &obj);
|
||||
sq_getstackobj(vm_, -1, obj);
|
||||
sq_addref(vm_, obj);
|
||||
HSQOBJECT obj;
|
||||
int marker = 0;
|
||||
readState.CheckCache(pBuffer, vm_, &marker);
|
||||
sq_getstackobj(vm_, -1, &obj);
|
||||
sq_addref(vm_, &obj);
|
||||
readState.StoreInCache(marker, obj);
|
||||
|
||||
int count = pBuffer->GetInt();
|
||||
|
||||
|
@ -106,14 +106,16 @@ class CSimpleCallChainer
|
||||
chain = null;
|
||||
}
|
||||
|
||||
DocumentedFuncs <- {}
|
||||
DocumentedClasses <- {}
|
||||
DocumentedEnums <- {}
|
||||
DocumentedConsts <- {}
|
||||
DocumentedHooks <- {}
|
||||
DocumentedMembers <- {}
|
||||
__Documentation <- {}
|
||||
|
||||
function AddAliasedToTable(name, signature, description, table)
|
||||
local DocumentedFuncs = {}
|
||||
local DocumentedClasses = {}
|
||||
local DocumentedEnums = {}
|
||||
local DocumentedConsts = {}
|
||||
local DocumentedHooks = {}
|
||||
local DocumentedMembers = {}
|
||||
|
||||
local function AddAliasedToTable(name, signature, description, table)
|
||||
{
|
||||
// This is an alias function, could use split() if we could guarantee
|
||||
// that ':' would not occur elsewhere in the description and Squirrel had
|
||||
@ -129,7 +131,7 @@ function AddAliasedToTable(name, signature, description, table)
|
||||
table[name] <- [signature, description];
|
||||
}
|
||||
|
||||
function RegisterHelp(name, signature, description)
|
||||
function __Documentation::RegisterHelp(name, signature, description)
|
||||
{
|
||||
if (description.len() && description[0] == '#')
|
||||
{
|
||||
@ -141,17 +143,17 @@ function RegisterHelp(name, signature, description)
|
||||
}
|
||||
}
|
||||
|
||||
function RegisterClassHelp(name, baseclass, description)
|
||||
function __Documentation::RegisterClassHelp(name, baseclass, description)
|
||||
{
|
||||
DocumentedClasses[name] <- [baseclass, description];
|
||||
}
|
||||
|
||||
function RegisterEnumHelp(name, num_elements, description)
|
||||
function __Documentation::RegisterEnumHelp(name, num_elements, description)
|
||||
{
|
||||
DocumentedEnums[name] <- [num_elements, description];
|
||||
}
|
||||
|
||||
function RegisterConstHelp(name, signature, description)
|
||||
function __Documentation::RegisterConstHelp(name, signature, description)
|
||||
{
|
||||
if (description.len() && description[0] == '#')
|
||||
{
|
||||
@ -163,31 +165,31 @@ function RegisterConstHelp(name, signature, description)
|
||||
}
|
||||
}
|
||||
|
||||
function RegisterHookHelp(name, signature, description)
|
||||
function __Documentation::RegisterHookHelp(name, signature, description)
|
||||
{
|
||||
DocumentedHooks[name] <- [signature, description];
|
||||
}
|
||||
|
||||
function RegisterMemberHelp(name, signature, description)
|
||||
function __Documentation::RegisterMemberHelp(name, signature, description)
|
||||
{
|
||||
DocumentedMembers[name] <- [signature, description];
|
||||
}
|
||||
|
||||
function printdoc( text )
|
||||
local function printdoc( text )
|
||||
{
|
||||
return ::printc(200,224,255,text);
|
||||
}
|
||||
|
||||
function printdocl( text )
|
||||
local function printdocl( text )
|
||||
{
|
||||
return printdoc(text + "\n");
|
||||
}
|
||||
|
||||
function PrintClass(name, doc)
|
||||
local function PrintClass(name, doc)
|
||||
{
|
||||
local text = "=====================================\n";
|
||||
text += ("Class: " + name + "\n");
|
||||
text += ("Base: " + doc[0] + "\n");
|
||||
text += ("Class: " + name + "\n");
|
||||
text += ("Base: " + doc[0] + "\n");
|
||||
if (doc[1].len())
|
||||
text += ("Description: " + doc[1] + "\n");
|
||||
text += "=====================================\n\n";
|
||||
@ -195,7 +197,7 @@ function PrintClass(name, doc)
|
||||
printdoc(text);
|
||||
}
|
||||
|
||||
function PrintFunc(name, doc)
|
||||
local function PrintFunc(name, doc)
|
||||
{
|
||||
local text = "Function: " + name + "\n"
|
||||
|
||||
@ -220,7 +222,7 @@ function PrintFunc(name, doc)
|
||||
printdocl(text);
|
||||
}
|
||||
|
||||
function PrintMember(name, doc)
|
||||
local function PrintMember(name, doc)
|
||||
{
|
||||
local text = ("Member: " + name + "\n");
|
||||
text += ("Signature: " + doc[0] + "\n");
|
||||
@ -229,11 +231,11 @@ function PrintMember(name, doc)
|
||||
printdocl(text);
|
||||
}
|
||||
|
||||
function PrintEnum(name, doc)
|
||||
local function PrintEnum(name, doc)
|
||||
{
|
||||
local text = "=====================================\n";
|
||||
text += ("Enum: " + name + "\n");
|
||||
text += ("Elements: " + doc[0] + "\n");
|
||||
text += ("Enum: " + name + "\n");
|
||||
text += ("Elements: " + doc[0] + "\n");
|
||||
if (doc[1].len())
|
||||
text += ("Description: " + doc[1] + "\n");
|
||||
text += "=====================================\n\n";
|
||||
@ -241,25 +243,25 @@ function PrintEnum(name, doc)
|
||||
printdoc(text);
|
||||
}
|
||||
|
||||
function PrintConst(name, doc)
|
||||
local function PrintConst(name, doc)
|
||||
{
|
||||
local text = ("Constant: " + name + "\n");
|
||||
if (doc[0] == null)
|
||||
{
|
||||
text += ("Value: null\n");
|
||||
text += ("Value: null\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
text += ("Value: " + doc[0] + "\n");
|
||||
text += ("Value: " + doc[0] + "\n");
|
||||
}
|
||||
if (doc[1].len())
|
||||
text += ("Description: " + doc[1] + "\n");
|
||||
printdocl(text);
|
||||
}
|
||||
|
||||
function PrintHook(name, doc)
|
||||
local function PrintHook(name, doc)
|
||||
{
|
||||
local text = ("Hook: " + name + "\n");
|
||||
local text = ("Hook: " + name + "\n");
|
||||
if (doc[0] == null)
|
||||
{
|
||||
// Is an aliased function
|
||||
@ -281,15 +283,15 @@ function PrintHook(name, doc)
|
||||
printdocl(text);
|
||||
}
|
||||
|
||||
function PrintMatchesInDocList(pattern, list, printfunc)
|
||||
local function PrintMatchesInDocList(pattern, list, printfunc)
|
||||
{
|
||||
local foundMatches = false;
|
||||
local foundMatches = 0;
|
||||
|
||||
foreach(name, doc in list)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern) != null || (doc[1].len() && doc[1].tolower().find(pattern) != null))
|
||||
{
|
||||
foundMatches = true;
|
||||
foundMatches = 1;
|
||||
printfunc(name, doc)
|
||||
}
|
||||
}
|
||||
@ -297,40 +299,41 @@ function PrintMatchesInDocList(pattern, list, printfunc)
|
||||
return foundMatches;
|
||||
}
|
||||
|
||||
function PrintHelp(pattern = "*")
|
||||
function __Documentation::PrintHelp(pattern = "*")
|
||||
{
|
||||
local foundMatches = false;
|
||||
local patternLower = pattern.tolower();
|
||||
|
||||
// Have a specific order
|
||||
foundMatches = ( PrintMatchesInDocList( patternLower, DocumentedEnums, PrintEnum ) || foundMatches );
|
||||
foundMatches = ( PrintMatchesInDocList( patternLower, DocumentedConsts, PrintConst ) || foundMatches );
|
||||
foundMatches = ( PrintMatchesInDocList( patternLower, DocumentedClasses, PrintClass ) || foundMatches );
|
||||
foundMatches = ( PrintMatchesInDocList( patternLower, DocumentedFuncs, PrintFunc ) || foundMatches );
|
||||
foundMatches = ( PrintMatchesInDocList( patternLower, DocumentedMembers, PrintMember ) || foundMatches );
|
||||
foundMatches = ( PrintMatchesInDocList( patternLower, DocumentedHooks, PrintHook ) || foundMatches );
|
||||
|
||||
if (!foundMatches)
|
||||
if (!(
|
||||
PrintMatchesInDocList( patternLower, DocumentedEnums, PrintEnum ) |
|
||||
PrintMatchesInDocList( patternLower, DocumentedConsts, PrintConst ) |
|
||||
PrintMatchesInDocList( patternLower, DocumentedClasses, PrintClass ) |
|
||||
PrintMatchesInDocList( patternLower, DocumentedFuncs, PrintFunc ) |
|
||||
PrintMatchesInDocList( patternLower, DocumentedMembers, PrintMember ) |
|
||||
PrintMatchesInDocList( patternLower, DocumentedHooks, PrintHook )
|
||||
))
|
||||
{
|
||||
printdocl("Pattern " + pattern + " not found");
|
||||
}
|
||||
}
|
||||
|
||||
// Vector documentation
|
||||
RegisterClassHelp( "Vector", "", "Basic 3-float Vector class." );
|
||||
RegisterHelp( "Vector::Length", "float Vector::Length()", "Return the vector's length." );
|
||||
RegisterHelp( "Vector::LengthSqr", "float Vector::LengthSqr()", "Return the vector's squared length." );
|
||||
RegisterHelp( "Vector::Length2D", "float Vector::Length2D()", "Return the vector's 2D length." );
|
||||
RegisterHelp( "Vector::Length2DSqr", "float Vector::Length2DSqr()", "Return the vector's squared 2D length." );
|
||||
__Documentation.RegisterClassHelp( "Vector", "", "Basic 3-float Vector class." );
|
||||
__Documentation.RegisterHelp( "Vector::Length", "float Vector::Length()", "Return the vector's length." );
|
||||
__Documentation.RegisterHelp( "Vector::LengthSqr", "float Vector::LengthSqr()", "Return the vector's squared length." );
|
||||
__Documentation.RegisterHelp( "Vector::Length2D", "float Vector::Length2D()", "Return the vector's 2D length." );
|
||||
__Documentation.RegisterHelp( "Vector::Length2DSqr", "float Vector::Length2DSqr()", "Return the vector's squared 2D length." );
|
||||
|
||||
RegisterHelp( "Vector::Normalized", "float Vector::Normalized()", "Return a normalized version of the vector." );
|
||||
RegisterHelp( "Vector::Norm", "void Vector::Norm()", "Normalize the vector in place." );
|
||||
RegisterHelp( "Vector::Scale", "vector Vector::Scale(float)", "Scale the vector's magnitude and return the result." );
|
||||
RegisterHelp( "Vector::Dot", "float Vector::Dot(vector)", "Return the dot/scalar product of two vectors." );
|
||||
RegisterHelp( "Vector::Cross", "float Vector::Cross(vector)", "Return the vector product of two vectors." );
|
||||
__Documentation.RegisterHelp( "Vector::Normalized", "float Vector::Normalized()", "Return a normalized version of the vector." );
|
||||
__Documentation.RegisterHelp( "Vector::Norm", "void Vector::Norm()", "Normalize the vector in place." );
|
||||
__Documentation.RegisterHelp( "Vector::Scale", "vector Vector::Scale(float)", "Scale the vector's magnitude and return the result." );
|
||||
__Documentation.RegisterHelp( "Vector::Dot", "float Vector::Dot(vector)", "Return the dot/scalar product of two vectors." );
|
||||
__Documentation.RegisterHelp( "Vector::Cross", "float Vector::Cross(vector)", "Return the vector product of two vectors." );
|
||||
|
||||
RegisterHelp( "Vector::ToKVString", "string Vector::ToKVString()", "Return a vector as a string in KeyValue form, without separation commas." );
|
||||
__Documentation.RegisterHelp( "Vector::ToKVString", "string Vector::ToKVString()", "Return a vector as a string in KeyValue form, without separation commas." );
|
||||
|
||||
RegisterMemberHelp( "Vector.x", "float Vector.x", "The vector's X coordinate on the cartesian X axis." );
|
||||
RegisterMemberHelp( "Vector.y", "float Vector.y", "The vector's Y coordinate on the cartesian Y axis." );
|
||||
RegisterMemberHelp( "Vector.z", "float Vector.z", "The vector's Z coordinate on the cartesian Z axis." );
|
||||
__Documentation.RegisterMemberHelp( "Vector.x", "float Vector.x", "The vector's X coordinate on the cartesian X axis." );
|
||||
__Documentation.RegisterMemberHelp( "Vector.y", "float Vector.y", "The vector's Y coordinate on the cartesian Y axis." );
|
||||
__Documentation.RegisterMemberHelp( "Vector.z", "float Vector.z", "The vector's Z coordinate on the cartesian Z axis." );
|
||||
|
||||
)vscript";
|
Loading…
x
Reference in New Issue
Block a user