mirror of
https://github.com/celisej567/source-sdk-2013.git
synced 2026-09-17 20:10:21 +03:00
Mapbase v6.0
- Fixed path_track paths saving as pointers instead of handles - Fixed player animations not falling to base class correctly - Fixed logic_externaldata creating garbage in trailing spaces - Added "SetHandModelSkin" input - Added unique colors for various types of console message, adjustable via convars - Added the ability to use map-specific weapon scripts - Added a way to display (placeholder) text entirely from Faceposer scenes - Added "autobreak" keyvalue to game_text, which automatically breaks long text into different lines - Added the ability to change a game_text's font (very limited) - Added LightToggle input to point_spotlight - Added Enable/DisableSprites on npc_manhack - Added ai_goal_police behavior from metrocops to Combine soldiers and citizens - Added func_precipitation particle rain systems from the Alien Swarm SDK - Added new func_precipitation spawnflags for controlling behavior in particle types - Added "mapbase_version" cvar which shows the version of Mapbase a mod might be running on - Fixed an oversight with NPC crouch activities which was causing npc_metropolice to stop firing in standoffs - Added toggleable patches to npc_combine AI which make soldiers less likely to stand around without shooting or rush to melee when not needed - Added key for custom logo font on env_credits scripts - Added SetSpeed and SetPushDir inputs for trigger_push - Added a bunch of I/O/KV to func_fish_pool to allow for more control over the fish - Added OnLostEnemy/Player support for npc_combine_camera - Added enhanced save/restore for the Response System, toggleable via convar - Added a convar which allows users to disable weapon autoswitching when picking up ammo - Split VScript base script into its own file - Added VScript descriptions for NPC squads and the manager class which handles them - Moved several classes, functions, etc. to the VScript library itself for future usage in other projects, like VBSP - Added VScript to VBSP with basic map file interfacing - Made some VScript documentation more clear due to deprecation of online documentation - Added VScript "hook" registration, creating a standardized system which shows up in script_help documentation - Added VScript-driven custom weapons - Added clientside VScript scopes - Added a bunch of weapon-related VScript functions - Split a bunch of cluttered VScript stuff into different files - Added VScript functions for "following" entities/bonemerging - Added VScript functions for grenades - Added a few more VScript trigger functions - Added OnDeath hook for VScript - Fixed documentation for aliased functions in VScript - Fixed $bumpmask not working on SDK_LightmappedGeneric - Made vertex blend swapping in Hammer use a constant instead of a combo (makes it easier to compile the shader, especially for $bumpmask's sake) - Fixed brush phong, etc. causing SDK_WorldVertexTransition to stop working - Added limited support for $envmapmask in the bumpmapping shader - Fixed more issues with parallax corrected cubemaps and instances - Made instance variable recursion consistent with VMFII
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "vscript/ivscript.h"
|
||||
|
||||
#include "vscript_bindings_base.h"
|
||||
|
||||
#include "tier1/tier1.h"
|
||||
|
||||
IScriptVM* makeSquirrelVM();
|
||||
@@ -41,7 +43,10 @@ public:
|
||||
delete pScriptVM;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
// Register base bindings for all VMs
|
||||
RegisterBaseBindings( pScriptVM );
|
||||
|
||||
return pScriptVM;
|
||||
}
|
||||
|
||||
@@ -53,6 +58,25 @@ public:
|
||||
delete pScriptVM;
|
||||
}
|
||||
}
|
||||
|
||||
// Mapbase moves CScriptKeyValues into the library so it could be used elsewhere
|
||||
virtual HSCRIPT CreateScriptKeyValues( IScriptVM *pVM, KeyValues *pKV, bool bAllowDestruct ) override
|
||||
{
|
||||
CScriptKeyValues *pSKV = new CScriptKeyValues( pKV );
|
||||
HSCRIPT hSKV = pVM->RegisterInstance( pSKV, bAllowDestruct );
|
||||
return hSKV;
|
||||
}
|
||||
|
||||
virtual KeyValues *GetKeyValuesFromScriptKV( IScriptVM *pVM, HSCRIPT hSKV ) override
|
||||
{
|
||||
CScriptKeyValues *pSKV = (hSKV ? (CScriptKeyValues*)pVM->GetInstanceValue( hSKV, GetScriptDesc( (CScriptKeyValues*)NULL ) ) : nullptr);
|
||||
if (pSKV)
|
||||
{
|
||||
return pSKV->m_pKeyValues;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
EXPOSE_SINGLE_INTERFACE(CScriptManager, IScriptManager, VSCRIPT_INTERFACE_VERSION);
|
||||
@@ -24,6 +24,12 @@ $Project "VScript"
|
||||
|
||||
$File "vscript.cpp"
|
||||
$File "vscript_squirrel.cpp"
|
||||
$File "vscript_squirrel.nut"
|
||||
|
||||
$File "vscript_bindings_base.cpp"
|
||||
$File "vscript_bindings_base.h"
|
||||
$File "vscript_bindings_math.cpp"
|
||||
$File "vscript_bindings_math.h"
|
||||
|
||||
$Folder "squirrel"
|
||||
{
|
||||
|
||||
537
sp/src/vscript/vscript_bindings_base.cpp
Normal file
537
sp/src/vscript/vscript_bindings_base.cpp
Normal file
@@ -0,0 +1,537 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose: VScript functions, constants, etc. registered within the library itself.
|
||||
//
|
||||
// This is for things which don't have to depend on server/client and can be accessed
|
||||
// from anywhere.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vscript/ivscript.h"
|
||||
|
||||
#include "tier1/tier1.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
#include <tier0/platform.h>
|
||||
#include "icommandline.h"
|
||||
#include "worldsize.h"
|
||||
#include "bspflags.h"
|
||||
|
||||
#include <vstdlib/random.h>
|
||||
|
||||
#include "vscript_bindings_base.h"
|
||||
#include "vscript_bindings_math.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Prints
|
||||
//
|
||||
//=============================================================================
|
||||
static void ScriptMsg( const char *msg )
|
||||
{
|
||||
Msg( "%s", msg );
|
||||
}
|
||||
|
||||
static void ScriptColorPrint( int r, int g, int b, const char *pszMsg )
|
||||
{
|
||||
const Color clr(r, g, b, 255);
|
||||
ConColorMsg( clr, "%s", pszMsg );
|
||||
}
|
||||
|
||||
static void ScriptColorPrintL( int r, int g, int b, const char *pszMsg )
|
||||
{
|
||||
const Color clr(r, g, b, 255);
|
||||
ConColorMsg( clr, "%s\n", pszMsg );
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Convar Lookup
|
||||
//
|
||||
//=============================================================================
|
||||
class CScriptConvarLookup
|
||||
{
|
||||
public:
|
||||
|
||||
float GetFloat( const char *pszConVar )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
return cvar.GetFloat();
|
||||
}
|
||||
|
||||
int GetInt( const char *pszConVar )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
return cvar.GetInt();
|
||||
}
|
||||
|
||||
bool GetBool( const char *pszConVar )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
return cvar.GetBool();
|
||||
}
|
||||
|
||||
const char *GetStr( const char *pszConVar )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
return cvar.GetString();
|
||||
}
|
||||
|
||||
const char *GetDefaultValue( const char *pszConVar )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
return cvar.GetDefault();
|
||||
}
|
||||
|
||||
bool IsFlagSet( const char *pszConVar, int nFlags )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
return cvar.IsFlagSet( nFlags );
|
||||
}
|
||||
|
||||
void SetFloat( const char *pszConVar, float value )
|
||||
{
|
||||
SetValue( pszConVar, value );
|
||||
}
|
||||
|
||||
void SetInt( const char *pszConVar, int value )
|
||||
{
|
||||
SetValue( pszConVar, value );
|
||||
}
|
||||
|
||||
void SetBool( const char *pszConVar, bool value )
|
||||
{
|
||||
SetValue( pszConVar, value );
|
||||
}
|
||||
|
||||
void SetStr( const char *pszConVar, const char *value )
|
||||
{
|
||||
SetValue( pszConVar, value );
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetValue( const char *pszConVar, T value )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
if (!cvar.IsValid())
|
||||
return;
|
||||
|
||||
// FCVAR_NOT_CONNECTED can be used to protect specific convars from nefarious interference
|
||||
if (cvar.IsFlagSet(FCVAR_NOT_CONNECTED))
|
||||
return;
|
||||
|
||||
cvar.SetValue( value );
|
||||
}
|
||||
|
||||
private:
|
||||
} g_ScriptConvarLookup;
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptConvarLookup, "CConvars", SCRIPT_SINGLETON "Provides an interface for getting and setting convars." )
|
||||
DEFINE_SCRIPTFUNC( GetFloat, "Returns the convar as a float. May return null if no such convar." )
|
||||
DEFINE_SCRIPTFUNC( GetInt, "Returns the convar as an int. May return null if no such convar." )
|
||||
DEFINE_SCRIPTFUNC( GetBool, "Returns the convar as a bool. May return null if no such convar." )
|
||||
DEFINE_SCRIPTFUNC( GetStr, "Returns the convar as a string. May return null if no such convar." )
|
||||
DEFINE_SCRIPTFUNC( GetDefaultValue, "Returns the convar's default value as a string. May return null if no such convar." )
|
||||
DEFINE_SCRIPTFUNC( IsFlagSet, "Returns the convar's flags. May return null if no such convar." )
|
||||
DEFINE_SCRIPTFUNC( SetFloat, "Sets the value of the convar as a float." )
|
||||
DEFINE_SCRIPTFUNC( SetInt, "Sets the value of the convar as an int." )
|
||||
DEFINE_SCRIPTFUNC( SetBool, "Sets the value of the convar as a bool." )
|
||||
DEFINE_SCRIPTFUNC( SetStr, "Sets the value of the convar as a string." )
|
||||
END_SCRIPTDESC();
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Command Line
|
||||
//
|
||||
//=============================================================================
|
||||
class CGlobalSys
|
||||
{
|
||||
public:
|
||||
const char* ScriptGetCommandLine()
|
||||
{
|
||||
return CommandLine()->GetCmdLine();
|
||||
}
|
||||
|
||||
bool CommandLineCheck(const char* name)
|
||||
{
|
||||
return !!CommandLine()->FindParm(name);
|
||||
}
|
||||
|
||||
const char* CommandLineCheckStr(const char* name)
|
||||
{
|
||||
return CommandLine()->ParmValue(name);
|
||||
}
|
||||
|
||||
float CommandLineCheckFloat(const char* name)
|
||||
{
|
||||
return CommandLine()->ParmValue(name, 0);
|
||||
}
|
||||
|
||||
int CommandLineCheckInt(const char* name)
|
||||
{
|
||||
return CommandLine()->ParmValue(name, 0);
|
||||
}
|
||||
} g_ScriptGlobalSys;
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( CGlobalSys, "CGlobalSys", SCRIPT_SINGLETON "GlobalSys" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetCommandLine, "GetCommandLine", "returns the command line" )
|
||||
DEFINE_SCRIPTFUNC( CommandLineCheck, "returns true if the command line param was used, otherwise false." )
|
||||
DEFINE_SCRIPTFUNC( CommandLineCheckStr, "returns the command line param as a string." )
|
||||
DEFINE_SCRIPTFUNC( CommandLineCheckFloat, "returns the command line param as a float." )
|
||||
DEFINE_SCRIPTFUNC( CommandLineCheckInt, "returns the command line param as an int." )
|
||||
END_SCRIPTDESC();
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// KeyValues access - CBaseEntity::ScriptGetKeyFromModel returns root KeyValues
|
||||
// ----------------------------------------------------------------------------
|
||||
BEGIN_SCRIPTDESC_ROOT( CScriptKeyValues, "Wrapper class over KeyValues instance" )
|
||||
DEFINE_SCRIPT_CONSTRUCTOR()
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptFindKey, "FindKey", "Given a KeyValues object and a key name, find a KeyValues object associated with the key name" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetFirstSubKey, "GetFirstSubKey", "Given a KeyValues object, return the first sub key object" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetNextKey, "GetNextKey", "Given a KeyValues object, return the next key object in a sub key group" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetKeyValueInt, "GetKeyInt", "Given a KeyValues object and a key name, return associated integer value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetKeyValueFloat, "GetKeyFloat", "Given a KeyValues object and a key name, return associated float value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetKeyValueBool, "GetKeyBool", "Given a KeyValues object and a key name, return associated bool value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetKeyValueString, "GetKeyString", "Given a KeyValues object and a key name, return associated string value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptIsKeyValueEmpty, "IsKeyEmpty", "Given a KeyValues object and a key name, return true if key name has no value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptReleaseKeyValues, "ReleaseKeyValues", "Given a root KeyValues object, release its contents" );
|
||||
|
||||
DEFINE_SCRIPTFUNC( TableToSubKeys, "Converts a script table to KeyValues." );
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetName, "GetName", "Given a KeyValues object, return its name" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetInt, "GetInt", "Given a KeyValues object, return its own associated integer value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetFloat, "GetFloat", "Given a KeyValues object, return its own associated float value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetString, "GetString", "Given a KeyValues object, return its own associated string value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetBool, "GetBool", "Given a KeyValues object, return its own associated bool value" );
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueInt, "SetKeyInt", "Given a KeyValues object and a key name, set associated integer value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueFloat, "SetKeyFloat", "Given a KeyValues object and a key name, set associated float value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueBool, "SetKeyBool", "Given a KeyValues object and a key name, set associated bool value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueString, "SetKeyString", "Given a KeyValues object and a key name, set associated string value" );
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetName, "SetName", "Given a KeyValues object, set its name" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetInt, "SetInt", "Given a KeyValues object, set its own associated integer value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetFloat, "SetFloat", "Given a KeyValues object, set its own associated float value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetBool, "SetBool", "Given a KeyValues object, set its own associated bool value" );
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetString, "SetString", "Given a KeyValues object, set its own associated string value" );
|
||||
END_SCRIPTDESC();
|
||||
|
||||
HSCRIPT CScriptKeyValues::ScriptFindKey( const char *pszName )
|
||||
{
|
||||
KeyValues *pKeyValues = m_pKeyValues->FindKey(pszName);
|
||||
if ( pKeyValues == NULL )
|
||||
return NULL;
|
||||
|
||||
CScriptKeyValues *pScriptKey = new CScriptKeyValues( pKeyValues );
|
||||
|
||||
// UNDONE: who calls ReleaseInstance on this??
|
||||
HSCRIPT hScriptInstance = g_pScriptVM->RegisterInstance( pScriptKey );
|
||||
return hScriptInstance;
|
||||
}
|
||||
|
||||
HSCRIPT CScriptKeyValues::ScriptGetFirstSubKey( void )
|
||||
{
|
||||
KeyValues *pKeyValues = m_pKeyValues->GetFirstSubKey();
|
||||
if ( pKeyValues == NULL )
|
||||
return NULL;
|
||||
|
||||
CScriptKeyValues *pScriptKey = new CScriptKeyValues( pKeyValues );
|
||||
|
||||
// UNDONE: who calls ReleaseInstance on this??
|
||||
HSCRIPT hScriptInstance = g_pScriptVM->RegisterInstance( pScriptKey );
|
||||
return hScriptInstance;
|
||||
}
|
||||
|
||||
HSCRIPT CScriptKeyValues::ScriptGetNextKey( void )
|
||||
{
|
||||
KeyValues *pKeyValues = m_pKeyValues->GetNextKey();
|
||||
if ( pKeyValues == NULL )
|
||||
return NULL;
|
||||
|
||||
CScriptKeyValues *pScriptKey = new CScriptKeyValues( pKeyValues );
|
||||
|
||||
// UNDONE: who calls ReleaseInstance on this??
|
||||
HSCRIPT hScriptInstance = g_pScriptVM->RegisterInstance( pScriptKey );
|
||||
return hScriptInstance;
|
||||
}
|
||||
|
||||
int CScriptKeyValues::ScriptGetKeyValueInt( const char *pszName )
|
||||
{
|
||||
int i = m_pKeyValues->GetInt( pszName );
|
||||
return i;
|
||||
}
|
||||
|
||||
float CScriptKeyValues::ScriptGetKeyValueFloat( const char *pszName )
|
||||
{
|
||||
float f = m_pKeyValues->GetFloat( pszName );
|
||||
return f;
|
||||
}
|
||||
|
||||
const char *CScriptKeyValues::ScriptGetKeyValueString( const char *pszName )
|
||||
{
|
||||
const char *psz = m_pKeyValues->GetString( pszName );
|
||||
return psz;
|
||||
}
|
||||
|
||||
bool CScriptKeyValues::ScriptIsKeyValueEmpty( const char *pszName )
|
||||
{
|
||||
bool b = m_pKeyValues->IsEmpty( pszName );
|
||||
return b;
|
||||
}
|
||||
|
||||
bool CScriptKeyValues::ScriptGetKeyValueBool( const char *pszName )
|
||||
{
|
||||
bool b = m_pKeyValues->GetBool( pszName );
|
||||
return b;
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptReleaseKeyValues( )
|
||||
{
|
||||
m_pKeyValues->deleteThis();
|
||||
m_pKeyValues = NULL;
|
||||
}
|
||||
|
||||
void CScriptKeyValues::TableToSubKeys( HSCRIPT hTable )
|
||||
{
|
||||
int nIterator = -1;
|
||||
ScriptVariant_t varKey, varValue;
|
||||
while ((nIterator = g_pScriptVM->GetKeyValue( hTable, nIterator, &varKey, &varValue )) != -1)
|
||||
{
|
||||
switch (varValue.m_type)
|
||||
{
|
||||
case FIELD_CSTRING: m_pKeyValues->SetString( varKey.m_pszString, varValue.m_pszString ); break;
|
||||
case FIELD_INTEGER: m_pKeyValues->SetInt( varKey.m_pszString, varValue.m_int ); break;
|
||||
case FIELD_FLOAT: m_pKeyValues->SetFloat( varKey.m_pszString, varValue.m_float ); break;
|
||||
case FIELD_BOOLEAN: m_pKeyValues->SetBool( varKey.m_pszString, varValue.m_bool ); break;
|
||||
case FIELD_VECTOR: m_pKeyValues->SetString( varKey.m_pszString, CFmtStr( "%f %f %f", varValue.m_pVector->x, varValue.m_pVector->y, varValue.m_pVector->z ) ); break;
|
||||
}
|
||||
|
||||
g_pScriptVM->ReleaseValue( varKey );
|
||||
g_pScriptVM->ReleaseValue( varValue );
|
||||
}
|
||||
}
|
||||
|
||||
const char *CScriptKeyValues::ScriptGetName()
|
||||
{
|
||||
const char *psz = m_pKeyValues->GetName();
|
||||
return psz;
|
||||
}
|
||||
|
||||
int CScriptKeyValues::ScriptGetInt()
|
||||
{
|
||||
int i = m_pKeyValues->GetInt();
|
||||
return i;
|
||||
}
|
||||
|
||||
float CScriptKeyValues::ScriptGetFloat()
|
||||
{
|
||||
float f = m_pKeyValues->GetFloat();
|
||||
return f;
|
||||
}
|
||||
|
||||
const char *CScriptKeyValues::ScriptGetString()
|
||||
{
|
||||
const char *psz = m_pKeyValues->GetString();
|
||||
return psz;
|
||||
}
|
||||
|
||||
bool CScriptKeyValues::ScriptGetBool()
|
||||
{
|
||||
bool b = m_pKeyValues->GetBool();
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
void CScriptKeyValues::ScriptSetKeyValueInt( const char *pszName, int iValue )
|
||||
{
|
||||
m_pKeyValues->SetInt( pszName, iValue );
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptSetKeyValueFloat( const char *pszName, float flValue )
|
||||
{
|
||||
m_pKeyValues->SetFloat( pszName, flValue );
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptSetKeyValueString( const char *pszName, const char *pszValue )
|
||||
{
|
||||
m_pKeyValues->SetString( pszName, pszValue );
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptSetKeyValueBool( const char *pszName, bool bValue )
|
||||
{
|
||||
m_pKeyValues->SetBool( pszName, bValue );
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptSetName( const char *pszValue )
|
||||
{
|
||||
m_pKeyValues->SetName( pszValue );
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptSetInt( int iValue )
|
||||
{
|
||||
m_pKeyValues->SetInt( NULL, iValue );
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptSetFloat( float flValue )
|
||||
{
|
||||
m_pKeyValues->SetFloat( NULL, flValue );
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptSetString( const char *pszValue )
|
||||
{
|
||||
m_pKeyValues->SetString( NULL, pszValue );
|
||||
}
|
||||
|
||||
void CScriptKeyValues::ScriptSetBool( bool bValue )
|
||||
{
|
||||
m_pKeyValues->SetBool( NULL, bValue );
|
||||
}
|
||||
|
||||
|
||||
// constructors
|
||||
CScriptKeyValues::CScriptKeyValues( KeyValues *pKeyValues = NULL )
|
||||
{
|
||||
if (pKeyValues == NULL)
|
||||
{
|
||||
m_pKeyValues = new KeyValues("");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pKeyValues = pKeyValues;
|
||||
}
|
||||
}
|
||||
|
||||
// destructor
|
||||
CScriptKeyValues::~CScriptKeyValues( )
|
||||
{
|
||||
if (m_pKeyValues)
|
||||
{
|
||||
m_pKeyValues->deleteThis();
|
||||
}
|
||||
m_pKeyValues = NULL;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
|
||||
void RegisterBaseBindings( IScriptVM *pVM )
|
||||
{
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptMsg, "Msg", "" );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptColorPrint, "printc", "Version of print() which takes a color before the message." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptColorPrintL, "printcl", "Version of printl() which takes a color before the message." );
|
||||
|
||||
ScriptRegisterFunction( pVM, GetCPUUsage, "Get CPU usage percentage." );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
pVM->RegisterInstance( &g_ScriptConvarLookup, "Convars" );
|
||||
pVM->RegisterInstance( &g_ScriptGlobalSys, "GlobalSys" );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
pVM->RegisterClass( GetScriptDescForClass( CScriptKeyValues ) );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// Math/world
|
||||
//
|
||||
ScriptRegisterConstant( pVM, MAX_COORD_FLOAT, "Maximum float coordinate." );
|
||||
ScriptRegisterConstant( pVM, MAX_TRACE_LENGTH, "Maximum traceable distance (assumes cubic world and trace from one corner to opposite)." );
|
||||
|
||||
//
|
||||
// Trace Contents/Masks
|
||||
//
|
||||
ScriptRegisterConstant( pVM, CONTENTS_EMPTY, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_SOLID, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_WINDOW, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_AUX, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_GRATE, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_SLIME, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_WATER, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_BLOCKLOS, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_OPAQUE, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_TESTFOGVOLUME, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_TEAM1, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_TEAM2, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_IGNORE_NODRAW_OPAQUE, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_MOVEABLE, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_AREAPORTAL, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_PLAYERCLIP, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_MONSTERCLIP, "Spatial content flags." );
|
||||
|
||||
ScriptRegisterConstant( pVM, CONTENTS_CURRENT_0, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_CURRENT_90, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_CURRENT_180, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_CURRENT_270, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_CURRENT_UP, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_CURRENT_DOWN, "Spatial content flags." );
|
||||
|
||||
ScriptRegisterConstant( pVM, CONTENTS_ORIGIN, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_MONSTER, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_DEBRIS, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_DETAIL, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_TRANSLUCENT, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_LADDER, "Spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, CONTENTS_HITBOX, "Spatial content flags." );
|
||||
|
||||
ScriptRegisterConstant( pVM, LAST_VISIBLE_CONTENTS, "Contains last visible spatial content flags." );
|
||||
ScriptRegisterConstant( pVM, ALL_VISIBLE_CONTENTS, "Contains all visible spatial content flags." );
|
||||
|
||||
ScriptRegisterConstant( pVM, MASK_SOLID, "Spatial content mask representing solid objects (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_PLAYERSOLID, "Spatial content mask representing objects solid to the player, including player clips (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_NPCSOLID, "Spatial content mask representing objects solid to NPCs, including NPC clips (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_WATER, "Spatial content mask representing water and slime solids (CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME)" );
|
||||
ScriptRegisterConstant( pVM, MASK_OPAQUE, "Spatial content mask representing objects which block lighting (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_OPAQUE_AND_NPCS, "Spatial content mask equivalent to MASK_OPAQUE, but also including NPCs (MASK_OPAQUE|CONTENTS_MONSTER)" );
|
||||
ScriptRegisterConstant( pVM, MASK_BLOCKLOS, "Spatial content mask representing objects which block LOS for AI (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_BLOCKLOS)" );
|
||||
ScriptRegisterConstant( pVM, MASK_BLOCKLOS_AND_NPCS, "Spatial content mask equivalent to MASK_BLOCKLOS, but also including NPCs (MASK_BLOCKLOS|CONTENTS_MONSTER)" );
|
||||
ScriptRegisterConstant( pVM, MASK_VISIBLE, "Spatial content mask representing objects which block LOS for players (MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_VISIBLE_AND_NPCS, "Spatial content mask equivalent to MASK_VISIBLE, but also including NPCs (MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_SHOT, "Spatial content mask representing objects solid to bullets (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX)" );
|
||||
ScriptRegisterConstant( pVM, MASK_SHOT_HULL, "Spatial content mask representing objects solid to non-raycasted weapons, including grates (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_GRATE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_SHOT_PORTAL, "Spatial content mask equivalent to MASK_SHOT, but excluding debris and not using expensive hitbox calculations (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER)" );
|
||||
ScriptRegisterConstant( pVM, MASK_SOLID_BRUSHONLY, "Spatial content mask equivalent to MASK_SOLID, but without NPCs (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_PLAYERSOLID_BRUSHONLY, "Spatial content mask equivalent to MASK_PLAYERSOLID, but without NPCs (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_PLAYERCLIP|CONTENTS_GRATE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_NPCSOLID_BRUSHONLY, "Spatial content mask equivalent to MASK_NPCSOLID, but without NPCs (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_NPCWORLDSTATIC, "Spatial content mask representing objects static to NPCs, used for nodegraph rebuilding (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE)" );
|
||||
ScriptRegisterConstant( pVM, MASK_SPLITAREAPORTAL, "Spatial content mask representing objects which can split areaportals (CONTENTS_WATER|CONTENTS_SLIME)" );
|
||||
|
||||
//
|
||||
// Misc. General
|
||||
//
|
||||
ScriptRegisterConstant( pVM, FCVAR_NONE, "Empty convar flag." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_UNREGISTERED, "If this convar flag is set, it isn't added to linked list, etc." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_DEVELOPMENTONLY, "If this convar flag is set, it's hidden in \"retail\" DLLs." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_GAMEDLL, "This convar flag is defined in server DLL convars." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_CLIENTDLL, "This convar flag is defined in client DLL convars." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_HIDDEN, "If this convar flag is set, it doesn't appear in the console or any searching tools, but it can still be set." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_PROTECTED, "This convar flag prevents convars with secure data (e.g. passwords) from sending full data to clients, only sending 1 if non-zero and 0 otherwise." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_SPONLY, "If this convar flag is set, it can't be changed by clients connected to a multiplayer server." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_ARCHIVE, "If this convar flag is set, its value will be saved when the game is exited." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_NOTIFY, "If this convar flag is set, it will notify players when it is changed." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_USERINFO, "If this convar flag is set, it will be marked as info which plays a part in how the server identifies a client." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_PRINTABLEONLY, "If this convar flag is set, it cannot contain unprintable characters. Used for player name cvars, etc." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_UNLOGGED, "If this convar flag is set, it will not log its changes if a log is being created." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_NEVER_AS_STRING, "If this convar flag is set, it will never be printed as a string." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_REPLICATED, "If this convar flag is set, it will enforce a serverside value on any clientside counterparts. (also known as FCAR_SERVER)" );
|
||||
ScriptRegisterConstant( pVM, FCVAR_DEMO, "If this convar flag is set, it will be recorded when starting a demo file." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_DONTRECORD, "If this convar flag is set, it will NOT be recorded when starting a demo file." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_RELOAD_MATERIALS, "If this convar flag is set, it will force a material reload when it changes." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_RELOAD_TEXTURES, "If this convar flag is set, it will force a texture reload when it changes." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_NOT_CONNECTED, "If this convar flag is set, it cannot be changed by a client connected to the server." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_MATERIAL_SYSTEM_THREAD, "This convar flag indicates it's read from the material system thread." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_ARCHIVE_XBOX, "If this convar flag is set, it will be archived on the Xbox config." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_ACCESSIBLE_FROM_THREADS, "If this convar flag is set, it will be accessible from the material system thread." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_SERVER_CAN_EXECUTE, "If this convar flag is set, the server will be allowed to execute it as a client command." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_SERVER_CANNOT_QUERY, "If this convar flag is set, the server will not be allowed to query its value." );
|
||||
ScriptRegisterConstant( pVM, FCVAR_CLIENTCMD_CAN_EXECUTE, "If this convar flag is set, any client will be allowed to execute this command." );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
RegisterMathBaseBindings( pVM );
|
||||
}
|
||||
62
sp/src/vscript/vscript_bindings_base.h
Normal file
62
sp/src/vscript/vscript_bindings_base.h
Normal file
@@ -0,0 +1,62 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 =================
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VSCRIPT_BINDINGS_BASE
|
||||
#define VSCRIPT_BINDINGS_BASE
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vscript/ivscript.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// KeyValues access
|
||||
// ----------------------------------------------------------------------------
|
||||
class CScriptKeyValues
|
||||
{
|
||||
public:
|
||||
CScriptKeyValues( KeyValues *pKeyValues );
|
||||
~CScriptKeyValues( );
|
||||
|
||||
HSCRIPT ScriptFindKey( const char *pszName );
|
||||
HSCRIPT ScriptGetFirstSubKey( void );
|
||||
HSCRIPT ScriptGetNextKey( void );
|
||||
int ScriptGetKeyValueInt( const char *pszName );
|
||||
float ScriptGetKeyValueFloat( const char *pszName );
|
||||
const char *ScriptGetKeyValueString( const char *pszName );
|
||||
bool ScriptIsKeyValueEmpty( const char *pszName );
|
||||
bool ScriptGetKeyValueBool( const char *pszName );
|
||||
void ScriptReleaseKeyValues( );
|
||||
|
||||
// Functions below are new with Mapbase
|
||||
void TableToSubKeys( HSCRIPT hTable );
|
||||
|
||||
const char *ScriptGetName();
|
||||
int ScriptGetInt();
|
||||
float ScriptGetFloat();
|
||||
const char *ScriptGetString();
|
||||
bool ScriptGetBool();
|
||||
|
||||
void ScriptSetKeyValueInt( const char *pszName, int iValue );
|
||||
void ScriptSetKeyValueFloat( const char *pszName, float flValue );
|
||||
void ScriptSetKeyValueString( const char *pszName, const char *pszValue );
|
||||
void ScriptSetKeyValueBool( const char *pszName, bool bValue );
|
||||
void ScriptSetName( const char *pszValue );
|
||||
void ScriptSetInt( int iValue );
|
||||
void ScriptSetFloat( float flValue );
|
||||
void ScriptSetString( const char *pszValue );
|
||||
void ScriptSetBool( bool bValue );
|
||||
|
||||
KeyValues *GetKeyValues() { return m_pKeyValues; }
|
||||
|
||||
KeyValues *m_pKeyValues; // actual KeyValue entity
|
||||
};
|
||||
|
||||
void RegisterBaseBindings( IScriptVM *pVM );
|
||||
|
||||
#endif
|
||||
451
sp/src/vscript/vscript_bindings_math.cpp
Normal file
451
sp/src/vscript/vscript_bindings_math.cpp
Normal file
@@ -0,0 +1,451 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose: VScript functions, constants, etc. registered within the library itself.
|
||||
//
|
||||
// This is for things which don't have to depend on server/client and can be accessed
|
||||
// from anywhere.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vscript/ivscript.h"
|
||||
|
||||
#include "tier1/tier1.h"
|
||||
|
||||
#include <tier0/platform.h>
|
||||
#include "worldsize.h"
|
||||
|
||||
#include <vstdlib/random.h>
|
||||
|
||||
#include "vscript_bindings_math.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// matrix3x4_t
|
||||
//
|
||||
//=============================================================================
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( matrix3x4_t, "matrix3x4_t", "A 3x4 matrix transform." )
|
||||
|
||||
DEFINE_SCRIPT_CONSTRUCTOR()
|
||||
DEFINE_SCRIPTFUNC( Init, "Creates a matrix where the X axis = forward, the Y axis = left, and the Z axis = up." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ScriptConcatTransforms( HSCRIPT hMat1, HSCRIPT hMat2, HSCRIPT hOut )
|
||||
{
|
||||
if (!hMat1 || !hMat2 || !hOut)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
matrix3x4_t *pMat2 = ToMatrix3x4( hMat2 );
|
||||
matrix3x4_t *pOut = ToMatrix3x4( hOut );
|
||||
|
||||
ConcatTransforms( *pMat1, *pMat2, *pOut );
|
||||
}
|
||||
|
||||
void ScriptMatrixCopy( HSCRIPT hMat1, HSCRIPT hOut )
|
||||
{
|
||||
if (!hMat1 || !hOut)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
matrix3x4_t *pOut = ToMatrix3x4( hOut );
|
||||
|
||||
MatrixCopy( *pMat1, *pOut );
|
||||
}
|
||||
|
||||
void ScriptMatrixInvert( HSCRIPT hMat1, HSCRIPT hOut )
|
||||
{
|
||||
if (!hMat1 || !hOut)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
matrix3x4_t *pOut = ToMatrix3x4( hOut );
|
||||
|
||||
MatrixInvert( *pMat1, *pOut );
|
||||
}
|
||||
|
||||
void ScriptMatricesAreEqual( HSCRIPT hMat1, HSCRIPT hMat2 )
|
||||
{
|
||||
if (!hMat1 || !hMat2)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
matrix3x4_t *pMat2 = ToMatrix3x4( hMat2 );
|
||||
|
||||
MatricesAreEqual( *pMat1, *pMat2 );
|
||||
}
|
||||
|
||||
const Vector& ScriptMatrixGetColumn( HSCRIPT hMat1, int column )
|
||||
{
|
||||
static Vector outvec;
|
||||
outvec.Zero();
|
||||
if (!hMat1)
|
||||
return outvec;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
MatrixGetColumn( *pMat1, column, outvec );
|
||||
return outvec;
|
||||
}
|
||||
|
||||
void ScriptMatrixSetColumn( const Vector& vecset, int column, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
static Vector outvec;
|
||||
MatrixSetColumn( vecset, column, *pMat1 );
|
||||
}
|
||||
|
||||
void ScriptMatrixAngles( HSCRIPT hMat1, const QAngle& angset, const Vector& vecset )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
MatrixAngles( *pMat1, *const_cast<QAngle*>(&angset), *const_cast<Vector*>(&vecset) );
|
||||
}
|
||||
|
||||
void ScriptAngleMatrix( const QAngle& angset, const Vector& vecset, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
AngleMatrix( angset, vecset, *pMat1 );
|
||||
}
|
||||
|
||||
void ScriptAngleIMatrix( const QAngle& angset, const Vector& vecset, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
AngleIMatrix( angset, vecset, *pMat1 );
|
||||
}
|
||||
|
||||
void ScriptSetIdentityMatrix( HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
SetIdentityMatrix( *pMat1 );
|
||||
}
|
||||
|
||||
void ScriptSetScaleMatrix( float x, float y, float z, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
SetScaleMatrix( x, y, z, *pMat1 );
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Quaternion
|
||||
//
|
||||
//=============================================================================
|
||||
CScriptQuaternionInstanceHelper g_QuaternionScriptInstanceHelper;
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( Quaternion, "Quaternion", "A quaternion." )
|
||||
|
||||
DEFINE_SCRIPT_CONSTRUCTOR()
|
||||
DEFINE_SCRIPT_INSTANCE_HELPER( &g_QuaternionScriptInstanceHelper )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptInit, "Init", "Creates a quaternion with the given values." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool CScriptQuaternionInstanceHelper::ToString( void *p, char *pBuf, int bufSize )
|
||||
{
|
||||
Quaternion *pQuat = ((Quaternion *)p);
|
||||
V_snprintf( pBuf, bufSize, "(quaternion: (%f, %f, %f, %f))", pQuat->x, pQuat->y, pQuat->z, pQuat->w );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CScriptQuaternionInstanceHelper::Get( void *p, const char *pszKey, ScriptVariant_t &variant )
|
||||
{
|
||||
Quaternion *pQuat = ((Quaternion *)p);
|
||||
if ( strlen(pszKey) == 1 )
|
||||
{
|
||||
switch (pszKey[0])
|
||||
{
|
||||
case 'x':
|
||||
variant = pQuat->x;
|
||||
return true;
|
||||
case 'y':
|
||||
variant = pQuat->y;
|
||||
return true;
|
||||
case 'z':
|
||||
variant = pQuat->z;
|
||||
return true;
|
||||
case 'w':
|
||||
variant = pQuat->w;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CScriptQuaternionInstanceHelper::Set( void *p, const char *pszKey, ScriptVariant_t &variant )
|
||||
{
|
||||
Quaternion *pQuat = ((Quaternion *)p);
|
||||
if ( strlen(pszKey) == 1 )
|
||||
{
|
||||
switch (pszKey[0])
|
||||
{
|
||||
case 'x':
|
||||
variant.AssignTo( &pQuat->x );
|
||||
return true;
|
||||
case 'y':
|
||||
variant.AssignTo( &pQuat->y );
|
||||
return true;
|
||||
case 'z':
|
||||
variant.AssignTo( &pQuat->z );
|
||||
return true;
|
||||
case 'w':
|
||||
variant.AssignTo( &pQuat->w );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ScriptVariant_t *CScriptQuaternionInstanceHelper::Add( void *p, ScriptVariant_t &variant )
|
||||
{
|
||||
Quaternion *pQuat = ((Quaternion *)p);
|
||||
|
||||
float flAdd;
|
||||
variant.AssignTo( &flAdd );
|
||||
|
||||
(*pQuat)[0] += flAdd;
|
||||
(*pQuat)[1] += flAdd;
|
||||
(*pQuat)[2] += flAdd;
|
||||
(*pQuat)[3] += flAdd;
|
||||
|
||||
static ScriptVariant_t result;
|
||||
result = (HSCRIPT)p;
|
||||
return &result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ScriptQuaternionAdd( HSCRIPT hQuat1, HSCRIPT hQuat2, HSCRIPT hOut )
|
||||
{
|
||||
if (!hQuat1 || !hQuat2 || !hOut)
|
||||
return;
|
||||
|
||||
Quaternion *pQuat1 = ToQuaternion( hQuat1 );
|
||||
Quaternion *pQuat2 = ToQuaternion( hQuat2 );
|
||||
Quaternion *pOut = ToQuaternion( hOut );
|
||||
|
||||
QuaternionAdd( *pQuat1, *pQuat2, *pOut );
|
||||
}
|
||||
|
||||
void ScriptMatrixQuaternion( HSCRIPT hMat1, HSCRIPT hQuat1 )
|
||||
{
|
||||
if (!hMat1 || !hQuat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
Quaternion *pQuat1 = ToQuaternion( hQuat1 );
|
||||
|
||||
MatrixQuaternion( *pMat1, *pQuat1 );
|
||||
}
|
||||
|
||||
void ScriptQuaternionMatrix( HSCRIPT hQuat1, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hQuat1 || !hMat1)
|
||||
return;
|
||||
|
||||
Quaternion *pQuat1 = ToQuaternion( hQuat1 );
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
QuaternionMatrix( *pQuat1, *pMat1 );
|
||||
}
|
||||
|
||||
QAngle ScriptQuaternionAngles( HSCRIPT hQuat1 )
|
||||
{
|
||||
if (!hQuat1)
|
||||
return QAngle();
|
||||
|
||||
Quaternion *pQuat1 = ToQuaternion( hQuat1 );
|
||||
|
||||
QAngle angles;
|
||||
QuaternionAngles( *pQuat1, angles );
|
||||
return angles;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Misc. Vector/QAngle functions
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
const Vector& ScriptAngleVectors( const QAngle &angles )
|
||||
{
|
||||
static Vector forward;
|
||||
AngleVectors( angles, &forward );
|
||||
return forward;
|
||||
}
|
||||
|
||||
const QAngle& ScriptVectorAngles( const Vector &forward )
|
||||
{
|
||||
static QAngle angles;
|
||||
VectorAngles( forward, angles );
|
||||
return angles;
|
||||
}
|
||||
|
||||
const Vector& ScriptVectorRotate( const Vector &in, HSCRIPT hMat )
|
||||
{
|
||||
if (ToMatrix3x4(hMat) == NULL)
|
||||
return vec3_origin;
|
||||
|
||||
static Vector out;
|
||||
VectorRotate( in, *ToMatrix3x4(hMat), out );
|
||||
return out;
|
||||
}
|
||||
|
||||
const Vector& ScriptVectorIRotate( const Vector &in, HSCRIPT hMat )
|
||||
{
|
||||
if (ToMatrix3x4(hMat) == NULL)
|
||||
return vec3_origin;
|
||||
|
||||
static Vector out;
|
||||
VectorIRotate( in, *ToMatrix3x4(hMat), out );
|
||||
return out;
|
||||
}
|
||||
|
||||
const Vector& ScriptVectorTransform( const Vector &in, HSCRIPT hMat )
|
||||
{
|
||||
if (ToMatrix3x4(hMat) == NULL)
|
||||
return vec3_origin;
|
||||
|
||||
static Vector out;
|
||||
VectorTransform( in, *ToMatrix3x4( hMat ), out );
|
||||
return out;
|
||||
}
|
||||
|
||||
const Vector& ScriptVectorITransform( const Vector &in, HSCRIPT hMat )
|
||||
{
|
||||
if (ToMatrix3x4(hMat) == NULL)
|
||||
return vec3_origin;
|
||||
|
||||
static Vector out;
|
||||
VectorITransform( in, *ToMatrix3x4( hMat ), out );
|
||||
return out;
|
||||
}
|
||||
|
||||
const Vector& ScriptCalcClosestPointOnAABB( const Vector &mins, const Vector &maxs, const Vector &point )
|
||||
{
|
||||
static Vector outvec;
|
||||
CalcClosestPointOnAABB( mins, maxs, point, outvec );
|
||||
return outvec;
|
||||
}
|
||||
|
||||
const Vector& ScriptCalcClosestPointOnLine( const Vector &point, const Vector &vLineA, const Vector &vLineB )
|
||||
{
|
||||
static Vector outvec;
|
||||
CalcClosestPointOnLine( point, vLineA, vLineB, outvec );
|
||||
return outvec;
|
||||
}
|
||||
|
||||
float ScriptCalcDistanceToLine( const Vector &point, const Vector &vLineA, const Vector &vLineB )
|
||||
{
|
||||
return CalcDistanceToLine( point, vLineA, vLineB );
|
||||
}
|
||||
|
||||
const Vector& ScriptCalcClosestPointOnLineSegment( const Vector &point, const Vector &vLineA, const Vector &vLineB )
|
||||
{
|
||||
static Vector outvec;
|
||||
CalcClosestPointOnLineSegment( point, vLineA, vLineB, outvec );
|
||||
return outvec;
|
||||
}
|
||||
|
||||
float ScriptCalcDistanceToLineSegment( const Vector &point, const Vector &vLineA, const Vector &vLineB )
|
||||
{
|
||||
return CalcDistanceToLineSegment( point, vLineA, vLineB );
|
||||
}
|
||||
|
||||
void RegisterMathBaseBindings( IScriptVM *pVM )
|
||||
{
|
||||
ScriptRegisterConstantNamed( pVM, ((float)(180.f / M_PI_F)), "RAD2DEG", "" );
|
||||
ScriptRegisterConstantNamed( pVM, ((float)(M_PI_F / 180.f)), "DEG2RAD", "" );
|
||||
|
||||
ScriptRegisterFunction( pVM, RandomFloat, "Generate a random floating point number within a range, inclusive." );
|
||||
ScriptRegisterFunction( pVM, RandomInt, "Generate a random integer within a range, inclusive." );
|
||||
//ScriptRegisterFunction( pVM, Approach, "Returns a value which approaches the target value from the input value with the specified speed." );
|
||||
ScriptRegisterFunction( pVM, ApproachAngle, "Returns an angle which approaches the target angle from the input angle with the specified speed." );
|
||||
ScriptRegisterFunction( pVM, AngleDiff, "Returns the degrees difference between two yaw angles." );
|
||||
//ScriptRegisterFunction( pVM, AngleDistance, "Returns the distance between two angles." );
|
||||
ScriptRegisterFunction( pVM, AngleNormalize, "Clamps an angle to be in between -360 and 360." );
|
||||
ScriptRegisterFunction( pVM, AngleNormalizePositive, "Clamps an angle to be in between 0 and 360." );
|
||||
ScriptRegisterFunction( pVM, AnglesAreEqual, "Checks if two angles are equal based on a given tolerance value." );
|
||||
|
||||
//
|
||||
// matrix3x4_t
|
||||
//
|
||||
pVM->RegisterClass( GetScriptDescForClass( matrix3x4_t ) );
|
||||
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptFreeMatrixInstance, "FreeMatrixInstance", "Frees an allocated matrix instance." );
|
||||
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptConcatTransforms, "ConcatTransforms", "Concatenates two transformation matrices into another matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptMatrixCopy, "MatrixCopy", "Copies a matrix to another matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptMatrixInvert, "MatrixInvert", "Inverts a matrix and copies the result to another matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptMatricesAreEqual, "MatricesAreEqual", "Checks if two matrices are equal." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptMatrixGetColumn, "MatrixGetColumn", "Gets the column of a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptMatrixSetColumn, "MatrixSetColumn", "Sets the column of a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptMatrixAngles, "MatrixAngles", "Gets the angles and position of a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptAngleMatrix, "AngleMatrix", "Sets the angles and position of a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptAngleIMatrix, "AngleIMatrix", "Sets the inverted angles and position of a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptSetIdentityMatrix, "SetIdentityMatrix", "Turns a matrix into an identity matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptSetScaleMatrix, "SetScaleMatrix", "Scales a matrix." );
|
||||
|
||||
//
|
||||
// Quaternion
|
||||
//
|
||||
pVM->RegisterClass( GetScriptDescForClass( Quaternion ) );
|
||||
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptFreeQuaternionInstance, "FreeQuaternionInstance", "Frees an allocated quaternion instance." );
|
||||
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptQuaternionAdd, "QuaternionAdd", "Adds two quaternions together into another quaternion." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptMatrixQuaternion, "MatrixQuaternion", "Converts a matrix to a quaternion." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptQuaternionMatrix, "QuaternionMatrix", "Converts a quaternion to a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptQuaternionAngles, "QuaternionAngles", "Converts a quaternion to angles." );
|
||||
|
||||
//
|
||||
// Misc. Vector/QAngle functions
|
||||
//
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptAngleVectors, "AngleVectors", "Turns an angle into a direction vector." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptVectorAngles, "VectorAngles", "Turns a direction vector into an angle." );
|
||||
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptVectorRotate, "VectorRotate", "Rotates a vector with a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptVectorIRotate, "VectorIRotate", "Rotates a vector with the inverse of a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptVectorTransform, "VectorTransform", "Transforms a vector with a matrix." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptVectorITransform, "VectorITransform", "Transforms a vector with the inverse of a matrix." );
|
||||
|
||||
ScriptRegisterFunction( pVM, CalcSqrDistanceToAABB, "Returns the squared distance to a bounding box." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptCalcClosestPointOnAABB, "CalcClosestPointOnAABB", "Returns the closest point on a bounding box." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptCalcDistanceToLine, "CalcDistanceToLine", "Returns the distance to a line." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptCalcClosestPointOnLine, "CalcClosestPointOnLine", "Returns the closest point on a line." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptCalcDistanceToLineSegment, "CalcDistanceToLineSegment", "Returns the distance to a line segment." );
|
||||
ScriptRegisterFunctionNamed( pVM, ScriptCalcClosestPointOnLineSegment, "CalcClosestPointOnLineSegment", "Returns the closest point on a line segment." );
|
||||
}
|
||||
62
sp/src/vscript/vscript_bindings_math.h
Normal file
62
sp/src/vscript/vscript_bindings_math.h
Normal file
@@ -0,0 +1,62 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 =================
|
||||
//
|
||||
// Purpose: Shared VScript math functions.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VSCRIPT_BINDINGS_MATH
|
||||
#define VSCRIPT_BINDINGS_MATH
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
void RegisterMathBaseBindings( IScriptVM *pVM );
|
||||
|
||||
// Some base bindings require VM functions
|
||||
extern IScriptVM *g_pScriptVM;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exposes matrix3x4_t to VScript
|
||||
//-----------------------------------------------------------------------------
|
||||
inline matrix3x4_t *ToMatrix3x4( HSCRIPT hMat ) { return HScriptToClass<matrix3x4_t>( hMat ); }
|
||||
|
||||
static void ScriptFreeMatrixInstance( HSCRIPT hMat )
|
||||
{
|
||||
matrix3x4_t *smatrix = HScriptToClass<matrix3x4_t>( hMat );
|
||||
if (smatrix)
|
||||
{
|
||||
g_pScriptVM->RemoveInstance( hMat );
|
||||
delete smatrix;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exposes Quaternion to VScript
|
||||
//-----------------------------------------------------------------------------
|
||||
class CScriptQuaternionInstanceHelper : public IScriptInstanceHelper
|
||||
{
|
||||
bool ToString( void *p, char *pBuf, int bufSize );
|
||||
|
||||
bool Get( void *p, const char *pszKey, ScriptVariant_t &variant );
|
||||
bool Set( void *p, const char *pszKey, ScriptVariant_t &variant );
|
||||
|
||||
ScriptVariant_t *Add( void *p, ScriptVariant_t &variant );
|
||||
//ScriptVariant_t *Subtract( void *p, ScriptVariant_t &variant );
|
||||
//ScriptVariant_t *Multiply( void *p, ScriptVariant_t &variant );
|
||||
//ScriptVariant_t *Divide( void *p, ScriptVariant_t &variant );
|
||||
};
|
||||
|
||||
inline Quaternion *ToQuaternion( HSCRIPT hQuat ) { return HScriptToClass<Quaternion>( hQuat ); }
|
||||
|
||||
static void ScriptFreeQuaternionInstance( HSCRIPT hQuat )
|
||||
{
|
||||
Quaternion *squat = HScriptToClass<Quaternion>( hQuat );
|
||||
if (squat)
|
||||
{
|
||||
g_pScriptVM->RemoveInstance( hQuat );
|
||||
delete squat;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -33,6 +33,9 @@
|
||||
|
||||
#include "color.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier1/mapbase_con_groups.h"
|
||||
|
||||
#include "vscript_squirrel.nut"
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
@@ -1365,8 +1368,6 @@ struct SquirrelSafeCheck
|
||||
};
|
||||
|
||||
|
||||
#define CON_COLOR_VSCRIPT 80,186,255,255
|
||||
|
||||
void printfunc(HSQUIRRELVM SQ_UNUSED_ARG(v), const SQChar* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -1374,7 +1375,7 @@ void printfunc(HSQUIRRELVM SQ_UNUSED_ARG(v), const SQChar* format, ...)
|
||||
va_start(args, format);
|
||||
V_vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
va_end(args);
|
||||
ConColorMsg(Color(CON_COLOR_VSCRIPT), "%s", buffer);
|
||||
CGMsg(0, CON_GROUP_VSCRIPT_PRINT, "%s", buffer);
|
||||
}
|
||||
|
||||
void errorfunc(HSQUIRRELVM SQ_UNUSED_ARG(v), const SQChar* format, ...)
|
||||
@@ -1399,6 +1400,7 @@ const char * ScriptDataTypeToName(ScriptDataType_t datatype)
|
||||
case FIELD_BOOLEAN: return "bool";
|
||||
case FIELD_CHARACTER: return "char";
|
||||
case FIELD_HSCRIPT: return "handle";
|
||||
case FIELD_VARIANT: return "variant";
|
||||
default: return "<unknown>";
|
||||
}
|
||||
}
|
||||
@@ -1528,6 +1530,53 @@ void RegisterConstantDocumentation( HSQUIRRELVM vm, const ScriptConstantBinding_
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
|
||||
void RegisterHookDocumentation(HSQUIRRELVM vm, const ScriptHook_t* pHook, const ScriptFuncDescriptor_t& pFuncDesc, ScriptClassDesc_t* pClassDesc = nullptr)
|
||||
{
|
||||
SquirrelSafeCheck safeCheck(vm);
|
||||
|
||||
if (pFuncDesc.m_pszDescription && pFuncDesc.m_pszDescription[0] == SCRIPT_HIDE[0])
|
||||
return;
|
||||
|
||||
char name[256] = "";
|
||||
|
||||
if (pClassDesc)
|
||||
{
|
||||
V_strcat_safe(name, pClassDesc->m_pszScriptName);
|
||||
V_strcat_safe(name, " -> ");
|
||||
}
|
||||
|
||||
V_strcat_safe(name, pFuncDesc.m_pszScriptName);
|
||||
|
||||
|
||||
char signature[256] = "";
|
||||
V_snprintf(signature, sizeof(signature), "%s %s(", ScriptDataTypeToName(pFuncDesc.m_ReturnType), name);
|
||||
|
||||
for (int i = 0; i < pFuncDesc.m_Parameters.Count(); ++i)
|
||||
{
|
||||
if (i != 0)
|
||||
V_strcat_safe(signature, ", ");
|
||||
|
||||
V_strcat_safe(signature, ScriptDataTypeToName(pFuncDesc.m_Parameters[i]));
|
||||
V_strcat_safe(signature, " [");
|
||||
V_strcat_safe(signature, pHook->m_pszParameterNames[i]);
|
||||
V_strcat_safe(signature, "]");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
bool SquirrelVM::Init()
|
||||
{
|
||||
@@ -1598,269 +1647,7 @@ bool SquirrelVM::Init()
|
||||
sq_pop(vm_, 1);
|
||||
}
|
||||
|
||||
if (Run(
|
||||
R"script(
|
||||
Warning <- error;
|
||||
|
||||
function clamp(val,min,max)
|
||||
{
|
||||
if ( max < min )
|
||||
return max;
|
||||
else if( val < min )
|
||||
return min;
|
||||
else if( val > max )
|
||||
return max;
|
||||
else
|
||||
return val;
|
||||
}
|
||||
|
||||
function max(a,b) return a > b ? a : b
|
||||
|
||||
function min(a,b) return a < b ? a : b
|
||||
|
||||
function RemapVal(val, A, B, C, D)
|
||||
{
|
||||
if ( A == B )
|
||||
return val >= B ? D : C;
|
||||
return C + (D - C) * (val - A) / (B - A);
|
||||
}
|
||||
|
||||
function RemapValClamped(val, A, B, C, D)
|
||||
{
|
||||
if ( A == B )
|
||||
return val >= B ? D : C;
|
||||
local cVal = (val - A) / (B - A);
|
||||
cVal = (cVal < 0.0) ? 0.0 : (1.0 < cVal) ? 1.0 : cVal;
|
||||
return C + (D - C) * cVal;
|
||||
}
|
||||
|
||||
function Approach( target, value, speed )
|
||||
{
|
||||
local delta = target - value
|
||||
|
||||
if( delta > speed )
|
||||
value += speed
|
||||
else if( delta < (-speed) )
|
||||
value -= speed
|
||||
else
|
||||
value = target
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function AngleDistance( next, cur )
|
||||
{
|
||||
local delta = next - cur
|
||||
|
||||
if ( delta < (-180.0) )
|
||||
delta += 360.0
|
||||
else if ( delta > 180.0 )
|
||||
delta -= 360.0
|
||||
|
||||
return delta
|
||||
}
|
||||
|
||||
function printl( text )
|
||||
{
|
||||
return ::print(text + "\n");
|
||||
}
|
||||
|
||||
class CSimpleCallChainer
|
||||
{
|
||||
constructor(prefixString, scopeForThis, exactMatch)
|
||||
{
|
||||
prefix = prefixString;
|
||||
scope = scopeForThis;
|
||||
chain = [];
|
||||
scope["Dispatch" + prefixString] <- Call.bindenv(this);
|
||||
}
|
||||
|
||||
function PostScriptExecute()
|
||||
{
|
||||
local func;
|
||||
try {
|
||||
func = scope[prefix];
|
||||
} catch(e) {
|
||||
return;
|
||||
}
|
||||
if (typeof(func) != "function")
|
||||
return;
|
||||
chain.push(func);
|
||||
}
|
||||
|
||||
function Call()
|
||||
{
|
||||
foreach (func in chain)
|
||||
{
|
||||
func.pcall(scope);
|
||||
}
|
||||
}
|
||||
|
||||
prefix = null;
|
||||
scope = null;
|
||||
chain = null;
|
||||
}
|
||||
|
||||
DocumentedFuncs <- {}
|
||||
DocumentedClasses <- {}
|
||||
DocumentedEnums <- {}
|
||||
DocumentedConsts <- {}
|
||||
|
||||
function ModForAlias(name, signature, description)
|
||||
{
|
||||
// This is an alias function, could use split() if we could guarantee
|
||||
// that ':' would not occur elsewhere in the description and Squirrel had
|
||||
// a convience join() function -- It has split()
|
||||
local colon = description.find(":");
|
||||
if (colon == null)
|
||||
colon = description.len();
|
||||
local alias = description.slice(1, colon);
|
||||
description = description.slice(colon + 1);
|
||||
name = alias;
|
||||
signature = null;
|
||||
}
|
||||
|
||||
function RegisterHelp(name, signature, description)
|
||||
{
|
||||
if (description.len() && description[0] == '#')
|
||||
{
|
||||
ModForAlias(name, signature, description)
|
||||
}
|
||||
DocumentedFuncs[name] <- [signature, description];
|
||||
}
|
||||
|
||||
function RegisterClassHelp(name, baseclass, description)
|
||||
{
|
||||
DocumentedClasses[name] <- [baseclass, description];
|
||||
}
|
||||
|
||||
function RegisterEnumHelp(name, description)
|
||||
{
|
||||
DocumentedEnums[name] <- description;
|
||||
}
|
||||
|
||||
function RegisterConstHelp(name, signature, description)
|
||||
{
|
||||
if (description.len() && description[0] == '#')
|
||||
{
|
||||
ModForAlias(name, signature, description)
|
||||
}
|
||||
DocumentedConsts[name] <- [signature, description];
|
||||
}
|
||||
|
||||
function PrintClass(name, doc)
|
||||
{
|
||||
printl("=====================================");
|
||||
printl("Class: " + name);
|
||||
printl("Base: " + doc[0]);
|
||||
if (doc[1].len())
|
||||
printl("Description: " + doc[1]);
|
||||
printl("=====================================");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintFunc(name, doc)
|
||||
{
|
||||
printl("Function: " + name);
|
||||
if (doc[0] == null)
|
||||
{
|
||||
// Is an aliased function
|
||||
print("Signature: function " + name + "(");
|
||||
foreach(k,v in this[name].getinfos().parameters)
|
||||
{
|
||||
if (k == 0 && v == "this") continue;
|
||||
if (k > 1) print(", ");
|
||||
print(v);
|
||||
}
|
||||
printl(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
printl("Signature: " + doc[0]);
|
||||
}
|
||||
if (doc[1].len())
|
||||
printl("Description: " + doc[1]);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintEnum(name, doc)
|
||||
{
|
||||
printl("=====================================");
|
||||
printl("Enum: " + name);
|
||||
if (doc.len())
|
||||
printl("Description: " + doc);
|
||||
printl("=====================================");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintConst(name, doc)
|
||||
{
|
||||
printl("Constant: " + name);
|
||||
if (doc[0] == null)
|
||||
{
|
||||
// Is an aliased function
|
||||
print("Signature: function " + name + "(");
|
||||
foreach(k,v in this[name].getinfos().parameters)
|
||||
{
|
||||
if (k == 0 && v == "this") continue;
|
||||
if (k > 1) print(", ");
|
||||
print(v);
|
||||
}
|
||||
printl(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
printl("Value: " + doc[0]);
|
||||
}
|
||||
if (doc[1].len())
|
||||
printl("Description: " + doc[1]);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintHelp(pattern = "*")
|
||||
{
|
||||
local foundMatches = false;
|
||||
foreach(name, doc in DocumentedClasses)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintClass(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
foreach(name, doc in DocumentedFuncs)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintFunc(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
foreach(name, doc in DocumentedEnums)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintEnum(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
foreach(name, doc in DocumentedConsts)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintConst(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundMatches)
|
||||
printl("Pattern " + pattern + " not found");
|
||||
}
|
||||
|
||||
)script") != SCRIPT_DONE)
|
||||
if (Run(g_Script_vscript_squirrel) != SCRIPT_DONE)
|
||||
{
|
||||
this->Shutdown();
|
||||
return false;
|
||||
@@ -2297,6 +2084,13 @@ bool SquirrelVM::RegisterClass(ScriptClassDesc_t* pClassDesc)
|
||||
RegisterDocumentation(vm_, scriptFunction.m_desc, pClassDesc);
|
||||
}
|
||||
|
||||
for (int i = 0; i < pClassDesc->m_Hooks.Count(); ++i)
|
||||
{
|
||||
auto& scriptHook = pClassDesc->m_Hooks[i];
|
||||
|
||||
RegisterHookDocumentation(vm_, scriptHook, scriptHook->m_desc, pClassDesc);
|
||||
}
|
||||
|
||||
sq_pushstring(vm_, pClassDesc->m_pszScriptName, -1);
|
||||
sq_push(vm_, -2);
|
||||
|
||||
|
||||
325
sp/src/vscript/vscript_squirrel.nut
Normal file
325
sp/src/vscript/vscript_squirrel.nut
Normal file
@@ -0,0 +1,325 @@
|
||||
static char g_Script_vscript_squirrel[] = R"vscript(
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
Warning <- error;
|
||||
|
||||
function clamp(val,min,max)
|
||||
{
|
||||
if ( max < min )
|
||||
return max;
|
||||
else if( val < min )
|
||||
return min;
|
||||
else if( val > max )
|
||||
return max;
|
||||
else
|
||||
return val;
|
||||
}
|
||||
|
||||
function max(a,b) return a > b ? a : b
|
||||
|
||||
function min(a,b) return a < b ? a : b
|
||||
|
||||
function RemapVal(val, A, B, C, D)
|
||||
{
|
||||
if ( A == B )
|
||||
return val >= B ? D : C;
|
||||
return C + (D - C) * (val - A) / (B - A);
|
||||
}
|
||||
|
||||
function RemapValClamped(val, A, B, C, D)
|
||||
{
|
||||
if ( A == B )
|
||||
return val >= B ? D : C;
|
||||
local cVal = (val - A) / (B - A);
|
||||
cVal = (cVal < 0.0) ? 0.0 : (1.0 < cVal) ? 1.0 : cVal;
|
||||
return C + (D - C) * cVal;
|
||||
}
|
||||
|
||||
function Approach( target, value, speed )
|
||||
{
|
||||
local delta = target - value
|
||||
|
||||
if( delta > speed )
|
||||
value += speed
|
||||
else if( delta < (-speed) )
|
||||
value -= speed
|
||||
else
|
||||
value = target
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function AngleDistance( next, cur )
|
||||
{
|
||||
local delta = next - cur
|
||||
|
||||
if ( delta < (-180.0) )
|
||||
delta += 360.0
|
||||
else if ( delta > 180.0 )
|
||||
delta -= 360.0
|
||||
|
||||
return delta
|
||||
}
|
||||
|
||||
function printl( text )
|
||||
{
|
||||
return ::print(text + "\n");
|
||||
}
|
||||
|
||||
class CSimpleCallChainer
|
||||
{
|
||||
constructor(prefixString, scopeForThis, exactMatch)
|
||||
{
|
||||
prefix = prefixString;
|
||||
scope = scopeForThis;
|
||||
chain = [];
|
||||
scope["Dispatch" + prefixString] <- Call.bindenv(this);
|
||||
}
|
||||
|
||||
function PostScriptExecute()
|
||||
{
|
||||
local func;
|
||||
try {
|
||||
func = scope[prefix];
|
||||
} catch(e) {
|
||||
return;
|
||||
}
|
||||
if (typeof(func) != "function")
|
||||
return;
|
||||
chain.push(func);
|
||||
}
|
||||
|
||||
function Call()
|
||||
{
|
||||
foreach (func in chain)
|
||||
{
|
||||
func.pcall(scope);
|
||||
}
|
||||
}
|
||||
|
||||
prefix = null;
|
||||
scope = null;
|
||||
chain = null;
|
||||
}
|
||||
|
||||
DocumentedFuncs <- {}
|
||||
DocumentedClasses <- {}
|
||||
DocumentedEnums <- {}
|
||||
DocumentedConsts <- {}
|
||||
DocumentedHooks <- {}
|
||||
|
||||
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
|
||||
// a convience join() function -- It has split()
|
||||
local colon = description.find(":");
|
||||
if (colon == null)
|
||||
colon = description.len();
|
||||
local alias = description.slice(1, colon);
|
||||
description = description.slice(colon + 1);
|
||||
name = alias;
|
||||
signature = null;
|
||||
|
||||
table[name] <- [signature, description];
|
||||
}
|
||||
|
||||
function RegisterHelp(name, signature, description)
|
||||
{
|
||||
if (description.len() && description[0] == '#')
|
||||
{
|
||||
AddAliasedToTable(name, signature, description, DocumentedFuncs)
|
||||
}
|
||||
else
|
||||
{
|
||||
DocumentedFuncs[name] <- [signature, description];
|
||||
}
|
||||
}
|
||||
|
||||
function RegisterClassHelp(name, baseclass, description)
|
||||
{
|
||||
DocumentedClasses[name] <- [baseclass, description];
|
||||
}
|
||||
|
||||
function RegisterEnumHelp(name, description)
|
||||
{
|
||||
DocumentedEnums[name] <- description;
|
||||
}
|
||||
|
||||
function RegisterConstHelp(name, signature, description)
|
||||
{
|
||||
if (description.len() && description[0] == '#')
|
||||
{
|
||||
AddAliasedToTable(name, signature, description, DocumentedConsts)
|
||||
}
|
||||
else
|
||||
{
|
||||
DocumentedConsts[name] <- [signature, description];
|
||||
}
|
||||
}
|
||||
|
||||
function RegisterHookHelp(name, signature, description)
|
||||
{
|
||||
DocumentedHooks[name] <- [signature, description];
|
||||
}
|
||||
|
||||
function printdoc( text )
|
||||
{
|
||||
return ::printc(200,224,255,text);
|
||||
}
|
||||
|
||||
function printdocl( text )
|
||||
{
|
||||
return printdoc(text + "\n");
|
||||
}
|
||||
|
||||
function PrintClass(name, doc)
|
||||
{
|
||||
printdocl("=====================================");
|
||||
printdocl("Class: " + name);
|
||||
printdocl("Base: " + doc[0]);
|
||||
if (doc[1].len())
|
||||
printdocl("Description: " + doc[1]);
|
||||
printdocl("=====================================");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintFunc(name, doc)
|
||||
{
|
||||
printdocl("Function: " + name);
|
||||
if (doc[0] == null)
|
||||
{
|
||||
// Is an aliased function
|
||||
printdoc("Signature: function " + name + "(");
|
||||
foreach(k,v in this[name].getinfos().parameters)
|
||||
{
|
||||
if (k == 0 && v == "this") continue;
|
||||
if (k > 1) printdoc(", ");
|
||||
printdoc(v);
|
||||
}
|
||||
printdocl(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
printdocl("Signature: " + doc[0]);
|
||||
}
|
||||
if (doc[1].len())
|
||||
printdocl("Description: " + doc[1]);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintEnum(name, doc)
|
||||
{
|
||||
printdocl("=====================================");
|
||||
printdocl("Enum: " + name);
|
||||
if (doc.len())
|
||||
printdocl("Description: " + doc);
|
||||
printdocl("=====================================");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintConst(name, doc)
|
||||
{
|
||||
printdocl("Constant: " + name);
|
||||
if (doc[0] == null)
|
||||
{
|
||||
// Is an aliased function
|
||||
printdoc("Signature: function " + name + "(");
|
||||
foreach(k,v in this[name].getinfos().parameters)
|
||||
{
|
||||
if (k == 0 && v == "this") continue;
|
||||
if (k > 1) printdoc(", ");
|
||||
printdoc(v);
|
||||
}
|
||||
printdocl(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
printdocl("Value: " + doc[0]);
|
||||
}
|
||||
if (doc[1].len())
|
||||
printdocl("Description: " + doc[1]);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintHook(name, doc)
|
||||
{
|
||||
printdocl("Hook: " + name);
|
||||
if (doc[0] == null)
|
||||
{
|
||||
// Is an aliased function
|
||||
printdoc("Signature: function " + name + "(");
|
||||
foreach(k,v in this[name].getinfos().parameters)
|
||||
{
|
||||
if (k == 0 && v == "this") continue;
|
||||
if (k > 1) printdoc(", ");
|
||||
printdoc(v);
|
||||
}
|
||||
printdocl(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
printdocl("Signature: " + doc[0]);
|
||||
}
|
||||
if (doc[1].len())
|
||||
printdocl("Description: " + doc[1]);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function PrintHelp(pattern = "*")
|
||||
{
|
||||
local foundMatches = false;
|
||||
foreach(name, doc in DocumentedClasses)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintClass(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
foreach(name, doc in DocumentedFuncs)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintFunc(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
foreach(name, doc in DocumentedEnums)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintEnum(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
foreach(name, doc in DocumentedConsts)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintConst(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
foreach(name, doc in DocumentedHooks)
|
||||
{
|
||||
if (pattern == "*" || name.tolower().find(pattern.tolower()) != null)
|
||||
{
|
||||
foundMatches = true;
|
||||
PrintHook(name, doc)
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundMatches)
|
||||
printdocl("Pattern " + pattern + " not found");
|
||||
}
|
||||
|
||||
)vscript";
|
||||
Reference in New Issue
Block a user