Skip to content

Commit 4b295c1

Browse files
authored
Merge pull request #148 from samisalreadytaken/fixup
Minor fixup
2 parents 2f8e920 + 7894c8a commit 4b295c1

File tree

4 files changed

+123
-63
lines changed

4 files changed

+123
-63
lines changed

sp/src/game/server/hl2/hl2_player.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4037,7 +4037,10 @@ Vector CHL2_Player::EyeDirection2D( void )
40374037
Vector CHL2_Player::EyeDirection3D( void )
40384038
{
40394039
Vector vecForward;
4040-
4040+
#ifdef MAPBASE
4041+
EyeVectors( &vecForward );
4042+
return vecForward;
4043+
#else
40414044
// Return the vehicle angles if we request them
40424045
if ( GetVehicle() != NULL )
40434046
{
@@ -4048,6 +4051,7 @@ Vector CHL2_Player::EyeDirection3D( void )
40484051

40494052
AngleVectors( EyeAngles(), &vecForward );
40504053
return vecForward;
4054+
#endif
40514055
}
40524056

40534057

sp/src/game/shared/mapbase/vscript_funcs_shared.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,16 @@ static void AddPhysVelocity( HSCRIPT hPhys, const Vector& vecVelocity, const Vec
775775
//=============================================================================
776776
//=============================================================================
777777

778+
static int ScriptPrecacheModel( const char *modelname )
779+
{
780+
return CBaseEntity::PrecacheModel( modelname );
781+
}
782+
783+
static void ScriptPrecacheOther( const char *classname )
784+
{
785+
UTIL_PrecacheOther( classname );
786+
}
787+
778788
#ifndef CLIENT_DLL
779789
// TODO: Move this?
780790
static void ScriptInsertSound( int iType, const Vector &vecOrigin, int iVolume, float flDuration, HSCRIPT hOwner, int soundChannelIndex, HSCRIPT hSoundTarget )
@@ -996,10 +1006,10 @@ void RegisterSharedScriptFunctions()
9961006
//
9971007
// Precaching
9981008
//
999-
ScriptRegisterFunctionNamed( g_pScriptVM, CBaseEntity::PrecacheModel, "PrecacheModel", "Precaches a model for later usage." );
1009+
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPrecacheModel, "PrecacheModel", "Precaches a model for later usage." );
10001010
ScriptRegisterFunction( g_pScriptVM, PrecacheMaterial, "Precaches a material for later usage." );
10011011
ScriptRegisterFunction( g_pScriptVM, PrecacheParticleSystem, "Precaches a particle system for later usage." );
1002-
ScriptRegisterFunctionNamed( g_pScriptVM, UTIL_PrecacheOther, "PrecacheOther", "Precaches an entity class for later usage." );
1012+
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPrecacheOther, "PrecacheOther", "Precaches an entity class for later usage." );
10031013

10041014
//
10051015
// NPCs

sp/src/game/shared/mapbase/vscript_singletons.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ END_SCRIPTDESC();
366366
//=============================================================================
367367
// Game Event Listener
368368
// Based on Source 2 API
369+
//
370+
// NOTE: In Source 2 vscript (Lua) event listener contexts are tables that are
371+
// passed to the callback function as the call environment.
372+
// In mapbase implementation these are string identifiers because unlike Lua,
373+
// Squirrel has closure methods such as 'bindenv' which can bind functions to specified environments.
369374
//=============================================================================
370375

371376
// Define to use the older code that loads all events manually independent from the game event manager.
@@ -375,7 +380,13 @@ END_SCRIPTDESC();
375380
class CScriptGameEventListener : public IGameEventListener2, public CAutoGameSystem
376381
{
377382
public:
378-
CScriptGameEventListener() : m_bActive(false) /*, m_nEventTick(0)*/ {}
383+
CScriptGameEventListener() : m_bActive(false)
384+
{
385+
#ifdef _DEBUG
386+
m_nEventTick = 0;
387+
#endif
388+
}
389+
379390
~CScriptGameEventListener()
380391
{
381392
StopListeningForEvent();
@@ -397,7 +408,9 @@ class CScriptGameEventListener : public IGameEventListener2, public CAutoGameSys
397408
HSCRIPT m_hCallback;
398409
unsigned int m_iContextHash;
399410
bool m_bActive;
400-
//int m_nEventTick;
411+
#ifdef _DEBUG
412+
int m_nEventTick;
413+
#endif
401414

402415
static StringHashFunctor Hash;
403416
static inline unsigned int HashContext( const char* c ) { return c ? Hash(c) : 0; }
@@ -592,7 +605,9 @@ void CScriptGameEventListener::LevelShutdownPreEntity()
592605

593606
void CScriptGameEventListener::FireGameEvent( IGameEvent *event )
594607
{
595-
//m_nEventTick = gpGlobals->tickcount;
608+
#ifdef _DEBUG
609+
m_nEventTick = gpGlobals->tickcount;
610+
#endif
596611
ScriptVariant_t hTable;
597612
g_pScriptVM->CreateTable( hTable );
598613
WriteEventData( event, hTable );
@@ -722,13 +737,15 @@ void CScriptGameEventListener::StopListeningForEvent()
722737
if ( gameeventmanager )
723738
gameeventmanager->RemoveListener( this );
724739

740+
#ifdef _DEBUG
725741
// Event listeners are iterated forwards in the game event manager,
726742
// removing while iterating will cause it to skip one listener.
727743
// This could be prevented by writing a custom game event manager.
728-
//if ( m_nEventTick == gpGlobals->tickcount )
729-
//{
730-
// Warning("CScriptGameEventListener stopped in the same frame it was fired. This will break other event listeners!\n");
731-
//}
744+
if ( m_nEventTick == gpGlobals->tickcount )
745+
{
746+
Warning("CScriptGameEventListener stopped in the same frame it was fired. This will break other event listeners!\n");
747+
}
748+
#endif
732749
}
733750

734751
//-----------------------------------------------------------------------------
@@ -2423,9 +2440,7 @@ class CScriptConvarAccessor : public CAutoGameSystem
24232440
inline bool IsOverridable( unsigned int hash )
24242441
{
24252442
int idx = g_ConCommandsOverridable.Find( hash );
2426-
if ( idx == g_ConCommandsOverridable.InvalidIndex() )
2427-
return false;
2428-
return true;
2443+
return ( idx != g_ConCommandsOverridable.InvalidIndex() );
24292444
}
24302445

24312446
inline void AddBlockedConVar( const char *name )
@@ -2436,9 +2451,7 @@ class CScriptConvarAccessor : public CAutoGameSystem
24362451
inline bool IsBlockedConvar( const char *name )
24372452
{
24382453
int idx = g_ConVarsBlocked.Find( Hash(name) );
2439-
if ( idx == g_ConVarsBlocked.InvalidIndex() )
2440-
return false;
2441-
return true;
2454+
return ( idx != g_ConVarsBlocked.InvalidIndex() );
24422455
}
24432456

24442457
public:

sp/src/vscript/vscript_squirrel.nut

Lines changed: 80 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,82 @@ static char g_Script_vscript_squirrel[] = R"vscript(
77
88
Warning <- error;
99
10-
function clamp(val,min,max)
10+
function clamp( val, min, max )
1111
{
1212
if ( max < min )
1313
return max;
14-
else if( val < min )
14+
if ( val < min )
1515
return min;
16-
else if( val > max )
16+
if ( val > max )
1717
return max;
18-
else
19-
return val;
18+
return val;
2019
}
2120
22-
function max(a,b) return a > b ? a : b
21+
function max( a, b )
22+
{
23+
if ( a > b )
24+
return a;
25+
return b;
26+
}
2327
24-
function min(a,b) return a < b ? a : b
28+
function min( a, b )
29+
{
30+
if ( a < b )
31+
return a;
32+
return b;
33+
}
2534
26-
function RemapVal(val, A, B, C, D)
35+
function RemapVal( val, A, B, C, D )
2736
{
2837
if ( A == B )
29-
return val >= B ? D : C;
38+
{
39+
if ( val >= B )
40+
return D;
41+
return C;
42+
};
3043
return C + (D - C) * (val - A) / (B - A);
3144
}
3245
33-
function RemapValClamped(val, A, B, C, D)
46+
function RemapValClamped( val, A, B, C, D )
3447
{
3548
if ( A == B )
36-
return val >= B ? D : C;
49+
{
50+
if ( val >= B )
51+
return D;
52+
return C;
53+
};
54+
3755
local cVal = (val - A) / (B - A);
38-
cVal = (cVal < 0.0) ? 0.0 : (1.0 < cVal) ? 1.0 : cVal;
56+
57+
if ( cVal <= 0.0 )
58+
return C;
59+
60+
if ( cVal >= 1.0 )
61+
return D;
62+
3963
return C + (D - C) * cVal;
4064
}
4165
4266
function Approach( target, value, speed )
4367
{
44-
local delta = target - value
68+
local delta = target - value;
4569
46-
if( delta > speed )
47-
value += speed
48-
else if( delta < (-speed) )
49-
value -= speed
50-
else
51-
value = target
52-
53-
return value
70+
if ( delta > speed )
71+
return value + speed;
72+
if ( -speed > delta )
73+
return value - speed;
74+
return target;
5475
}
5576
5677
function AngleDistance( next, cur )
5778
{
5879
local delta = next - cur
5980
60-
if ( delta < (-180.0) )
61-
delta += 360.0
62-
else if ( delta > 180.0 )
63-
delta -= 360.0
64-
65-
return delta
81+
if ( delta > 180.0 )
82+
return delta - 360.0;
83+
if ( -180.0 > delta )
84+
return delta + 360.0;
85+
return delta;
6686
}
6787
6888
function FLerp( f1, f2, i1, i2, x )
@@ -83,7 +103,7 @@ function SimpleSpline( f )
83103
84104
function printl( text )
85105
{
86-
return ::print(text + "\n");
106+
return print(text + "\n");
87107
}
88108
89109
class CSimpleCallChainer
@@ -481,23 +501,36 @@ else
481501
}
482502
}
483503

484-
// Vector documentation
485-
__Documentation.RegisterClassHelp( "Vector", "", "Basic 3-float Vector class." );
486-
__Documentation.RegisterHelp( "Vector::Length", "float Vector::Length()", "Return the vector's length." );
487-
__Documentation.RegisterHelp( "Vector::LengthSqr", "float Vector::LengthSqr()", "Return the vector's squared length." );
488-
__Documentation.RegisterHelp( "Vector::Length2D", "float Vector::Length2D()", "Return the vector's 2D length." );
489-
__Documentation.RegisterHelp( "Vector::Length2DSqr", "float Vector::Length2DSqr()", "Return the vector's squared 2D length." );
490-
491-
__Documentation.RegisterHelp( "Vector::Normalized", "float Vector::Normalized()", "Return a normalized version of the vector." );
492-
__Documentation.RegisterHelp( "Vector::Norm", "void Vector::Norm()", "Normalize the vector in place." );
493-
__Documentation.RegisterHelp( "Vector::Scale", "vector Vector::Scale(float)", "Scale the vector's magnitude and return the result." );
494-
__Documentation.RegisterHelp( "Vector::Dot", "float Vector::Dot(vector)", "Return the dot/scalar product of two vectors." );
495-
__Documentation.RegisterHelp( "Vector::Cross", "float Vector::Cross(vector)", "Return the vector product of two vectors." );
496-
497-
__Documentation.RegisterHelp( "Vector::ToKVString", "string Vector::ToKVString()", "Return a vector as a string in KeyValue form, without separation commas." );
498-
499-
__Documentation.RegisterMemberHelp( "Vector.x", "float Vector.x", "The vector's X coordinate on the cartesian X axis." );
500-
__Documentation.RegisterMemberHelp( "Vector.y", "float Vector.y", "The vector's Y coordinate on the cartesian Y axis." );
501-
__Documentation.RegisterMemberHelp( "Vector.z", "float Vector.z", "The vector's Z coordinate on the cartesian Z axis." );
502-
504+
if (developer)
505+
{
506+
// Vector documentation
507+
__Documentation.RegisterClassHelp( "Vector", "", "Basic 3-float Vector class." );
508+
__Documentation.RegisterHelp( "Vector::Length", "float Vector::Length()", "Return the vector's length." );
509+
__Documentation.RegisterHelp( "Vector::LengthSqr", "float Vector::LengthSqr()", "Return the vector's squared length." );
510+
__Documentation.RegisterHelp( "Vector::Length2D", "float Vector::Length2D()", "Return the vector's 2D length." );
511+
__Documentation.RegisterHelp( "Vector::Length2DSqr", "float Vector::Length2DSqr()", "Return the vector's squared 2D length." );
512+
513+
__Documentation.RegisterHelp( "Vector::Normalized", "float Vector::Normalized()", "Return a normalized version of the vector." );
514+
__Documentation.RegisterHelp( "Vector::Norm", "void Vector::Norm()", "Normalize the vector in place." );
515+
__Documentation.RegisterHelp( "Vector::Scale", "vector Vector::Scale(float)", "Scale the vector's magnitude and return the result." );
516+
__Documentation.RegisterHelp( "Vector::Dot", "float Vector::Dot(vector)", "Return the dot/scalar product of two vectors." );
517+
__Documentation.RegisterHelp( "Vector::Cross", "float Vector::Cross(vector)", "Return the vector product of two vectors." );
518+
519+
__Documentation.RegisterHelp( "Vector::ToKVString", "string Vector::ToKVString()", "Return a vector as a string in KeyValue form, without separation commas." );
520+
521+
__Documentation.RegisterMemberHelp( "Vector.x", "float Vector.x", "The vector's X coordinate on the cartesian X axis." );
522+
__Documentation.RegisterMemberHelp( "Vector.y", "float Vector.y", "The vector's Y coordinate on the cartesian Y axis." );
523+
__Documentation.RegisterMemberHelp( "Vector.z", "float Vector.z", "The vector's Z coordinate on the cartesian Z axis." );
524+
525+
__Documentation.RegisterHelp( "clamp", "float clamp(float, float, float)", "" );
526+
__Documentation.RegisterHelp( "max", "float max(float, float)", "" );
527+
__Documentation.RegisterHelp( "min", "float min(float, float)", "" );
528+
__Documentation.RegisterHelp( "RemapVal", "float RemapVal(float, float, float, float, float)", "" );
529+
__Documentation.RegisterHelp( "RemapValClamped", "float RemapValClamped(float, float, float, float, float)", "" );
530+
__Documentation.RegisterHelp( "Approach", "float Approach(float, float, float)", "" );
531+
__Documentation.RegisterHelp( "AngleDistance", "float AngleDistance(float, float)", "" );
532+
__Documentation.RegisterHelp( "FLerp", "float FLerp(float, float, float, float, float)", "" );
533+
__Documentation.RegisterHelp( "Lerp", "float Lerp(float, float, float)", "" );
534+
__Documentation.RegisterHelp( "SimpleSpline", "float SimpleSpline(float)", "" );
535+
}
503536
)vscript";

0 commit comments

Comments
 (0)