vscript additions and fixes:

vscript_client.cpp
   - Fixed local player script instance registration
   - Added CEntities::GetLocalPlayer
   - Added Con_IsVisible
   - Added IsWindowedMode
   - Added ScreenWidth
   - Added ScreenHeight
   - Added ScreenTransform
   - Added missing DoUniqueString

gameinterface.cpp
usercmd.h
usercmd.cpp
vscript_singletons.cpp
   - CNetMsgScriptHelper

vscript_singletons.cpp
   - Added hash map for CScriptSaveRestoreUtil
   - Added hash map for CScriptGameEventListener::s_GameEvents
   - Changed CScriptGameEventListener string contexts to hashes
   - Added invalid input condition on CScriptGameEventListener::ListenToGameEvent
   - Moved CDebugOverlayScriptHelper to shared code

ivscript.h
vscript_squirrel.cpp
   - Added IScriptVM::Get/Set/ClearValue (ScriptVariant_t key)

baseentity.h
baseentity.cpp
   - Added CBaseEntity::SetContextThink (ScriptSetContextThink)

vscript_server.cpp
vscript_client.cpp
vscript_funcs_shared.cpp
   - Changed the order user vscript_*.nut files are executed - after internal scripts, before mapspawn

vscript_squirrel.cpp
vscript_squirrel.nut
vscript_server.nut
vscript_shared.cpp
   - Localised all documentation under __Documentation

hl2_usermessages.cpp
   - Added usermessage ScriptMsg

c_baseplayer.cpp
   - Removed redundant check in ~C_BasePlayer
This commit is contained in:
samisalreadytaken
2020-12-25 23:07:46 +03:00
parent 6ba3cd4c03
commit ef7d9ccc0f
18 changed files with 1716 additions and 991 deletions

View File

@@ -18,6 +18,7 @@
#include "vscript_server.nut"
#ifdef MAPBASE_VSCRIPT
#include "world.h"
#include "mapbase/vscript_singletons.h"
#endif
extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
@@ -246,451 +247,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 &center, 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 +566,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 +583,7 @@ bool VScriptServerInit()
g_pScriptVM->Run( g_Script_vscript_server );
}
VScriptRunScript( "vscript_server", true );
VScriptRunScript( "mapspawn", false );
#ifdef MAPBASE_VSCRIPT
@@ -1192,6 +747,9 @@ public:
virtual void LevelShutdownPostEntity( void )
{
#ifdef MAPBASE_VSCRIPT
g_ScriptNetMsg->LevelShutdownPreVM();
#endif
VScriptServerTerm();
}