Skip to content

Commit 7d6ca83

Browse files
authored
Merge pull request #893 from ReactiveDrop/tracelineparams
fix TraceLineTable function degrading performance over time
2 parents 6f1a3aa + 7ae2d84 commit 7d6ca83

3 files changed

Lines changed: 526 additions & 468 deletions

File tree

src/game/server/vscript_server.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ static float ScriptTraceLine( const Vector &vecStart, const Vector &vecEnd, HSCR
11431143
}
11441144
}
11451145

1146-
static void ScriptTraceLineTable( HSCRIPT hTable )
1146+
static void ScriptTraceLineTable( HSCRIPT hTable, const Vector &vecStart, const Vector &vecEnd, const Vector &vecMins, const Vector &vecMaxs )
11471147
{
11481148
if ( !hTable )
11491149
return;
@@ -1152,26 +1152,22 @@ static void ScriptTraceLineTable( HSCRIPT hTable )
11521152
return;
11531153

11541154
trace_t tr;
1155-
ScriptVariant_t start, end, mask, ignore, collisiongroup, mins, maxs;
1156-
mask = MASK_VISIBLE_AND_NPCS;
1157-
collisiongroup = COLLISION_GROUP_NONE;
1158-
mins = vec3_origin;
1159-
maxs = vec3_origin;
1160-
g_pScriptVM->GetValue( hTable, "start", &start );
1161-
g_pScriptVM->GetValue( hTable, "end", &end );
1162-
g_pScriptVM->GetValue( hTable, "mask", &mask );
1163-
g_pScriptVM->GetValue( hTable, "ignore", &ignore );
1164-
g_pScriptVM->GetValue( hTable, "collisiongroup", &collisiongroup );
1165-
g_pScriptVM->GetValue( hTable, "mins", &mins );
1166-
g_pScriptVM->GetValue( hTable, "maxs", &maxs );
1167-
const Vector vecStart = start;
1168-
const Vector vecEnd = end;
1169-
const Vector vecMins = mins;
1170-
const Vector vecMaxs = maxs;
1155+
ScriptVariant_t rval;
1156+
int nMask = MASK_VISIBLE_AND_NPCS;
1157+
int nCollisionGroup = COLLISION_GROUP_NONE;
1158+
CBaseEntity *pIgnore = NULL;
1159+
1160+
if ( g_pScriptVM->GetValue( hTable, "mask", &rval ) )
1161+
nMask = ( int )rval;
1162+
if ( g_pScriptVM->GetValue( hTable, "ignore", &rval ) )
1163+
pIgnore = ToEnt( ( HSCRIPT )rval );
1164+
if ( g_pScriptVM->GetValue( hTable, "collisiongroup", &rval ) )
1165+
nCollisionGroup = ( int )rval;
1166+
11711167
if ( vecMins == vecMaxs )
1172-
UTIL_TraceLine( vecStart, vecEnd, ( int )mask, ToEnt( ignore ), ( int )collisiongroup, &tr );
1168+
UTIL_TraceLine( vecStart, vecEnd, ( unsigned int )nMask, pIgnore, nCollisionGroup, &tr );
11731169
else
1174-
UTIL_TraceHull( vecStart, vecEnd, vecMins, vecMaxs, ( int )mask, ToEnt( ignore ), ( int )collisiongroup, &tr );
1170+
UTIL_TraceHull( vecStart, vecEnd, vecMins, vecMaxs, ( unsigned int )nMask, pIgnore, nCollisionGroup, &tr );
11751171

11761172
g_pScriptVM->SetValue( hTable, "pos", tr.endpos );
11771173
g_pScriptVM->SetValue( hTable, "fraction", tr.fraction );
@@ -1720,7 +1716,7 @@ bool VScriptServerInit()
17201716
ScriptRegisterFunction( g_pScriptVM, SendToServerConsole, "Send a string to the server console as a command" );
17211717
ScriptRegisterFunction( g_pScriptVM, GetMapName, "Get the name of the map.");
17221718
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptTraceLine, "TraceLine", "given 2 points & ent to ignore, return fraction along line that hits world or models" );
1723-
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptTraceLineTable, "TraceLineTable", "Uses a configuration table to do a raytrace, puts return information into the table for return usage." );
1719+
ScriptRegisterFunction( g_pScriptVM, ScriptTraceLineTable, "Uses a configuration table to do a raytrace, puts return information into the table for return usage." );
17241720

17251721
ScriptRegisterFunction( g_pScriptVM, Time, "Get the current server time" );
17261722
ScriptRegisterFunction( g_pScriptVM, FrameTime, "Get the time spent on the server in the last frame" );

src/game/server/vscript_server.nut

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,22 @@ function ClientPrint( player, target, message, param1 = "", param2 = "", param3
272272
{
273273
DoClientPrint( player, target, message, param1.tostring(), param2.tostring(), param3.tostring(), param4.tostring() );
274274
}
275+
276+
function TraceLineTable( table )
277+
{
278+
local vecStart = Vector( 0.0, 0.0, 0.0 );
279+
local vecEnd = Vector( 0.0, 0.0, 0.0 );
280+
local vecMins = Vector( 0.0, 0.0, 0.0 );
281+
local vecMaxs = Vector( 0.0, 0.0, 0.0 );
282+
283+
if ( "start" in table )
284+
vecStart = table[ "start" ];
285+
if ( "end" in table )
286+
vecEnd = table[ "end" ];
287+
if ( "mins" in table )
288+
vecMins = table[ "mins" ];
289+
if ( "maxs" in table )
290+
vecMaxs = table[ "maxs" ];
291+
292+
ScriptTraceLineTable( table, vecStart, vecEnd, vecMins, vecMaxs );
293+
}

0 commit comments

Comments
 (0)