mirror of
https://github.com/Mista-Tea/improved-stacker.git
synced 2025-03-04 03:12:57 -05:00
Fixed #38 - Optimize render hooks that involve traces
According to DBugR, switching the eye trace with the stacker tool check reduces the hook runtime from ~5 m/s to ~1.3 m/s. We don't need to perform eye traces when the player doesn't even have the tool selected. I've also switched the same logic inside of the PreDrawHalos hook, though the performance difference seems to be neglible or nonexistent, but better safe than sorry.
This commit is contained in:
parent
67c9f0bb1a
commit
693fa6fbcc
@ -1183,20 +1183,21 @@ if ( CLIENT ) then
|
||||
-- will be called way more than it needs to be and causes horrible FPS drops in singleplayer.
|
||||
--]]--
|
||||
hook.Add( "PreDrawHalos", mode.."_predrawhalos", function()
|
||||
-- check if the player has fully initialized
|
||||
local ply = LocalPlayer()
|
||||
if ( not IsValid( ply ) ) then return end
|
||||
|
||||
-- check if we're looking at a valid entity
|
||||
local lookingAt = ply:GetEyeTrace().Entity
|
||||
if ( not ( IsValid( lookingAt ) and lookingAt:GetClass() == "prop_physics" ) ) then
|
||||
-- check if they have the toolgun out and have stacker selected
|
||||
local wep = ply:GetActiveWeapon()
|
||||
if ( not ( IsValid( wep ) and wep:GetClass() == "gmod_tool" and cvarTool and cvarTool:GetString() == mode ) ) then
|
||||
improvedstacker.ReleaseGhosts()
|
||||
improvedstacker.SetLookedAt( nil )
|
||||
return
|
||||
end
|
||||
|
||||
-- check if they have the toolgun out and have stacker selected
|
||||
local wep = ply:GetActiveWeapon()
|
||||
if ( not ( IsValid( wep ) and wep:GetClass() == "gmod_tool" and cvarTool and cvarTool:GetString() == mode ) ) then
|
||||
-- check if we're looking at a valid entity
|
||||
local lookingAt = ply:GetEyeTrace().Entity
|
||||
if ( not ( IsValid( lookingAt ) and lookingAt:GetClass() == "prop_physics" ) ) then
|
||||
improvedstacker.ReleaseGhosts()
|
||||
improvedstacker.SetLookedAt( nil )
|
||||
return
|
||||
@ -1255,24 +1256,26 @@ if ( CLIENT ) then
|
||||
|
||||
hook.Add( "PostDrawTranslucentRenderables", mode.."_directions", function( drawingDepth, drawingSky )
|
||||
if ( drawingSky ) then return end
|
||||
|
||||
-- check if the player has fully initialized
|
||||
local ply = LocalPlayer()
|
||||
if ( not IsValid( ply ) ) then return end
|
||||
|
||||
-- check if we want to draw the axis at all
|
||||
if ( not ( cvarAxis and cvarAxis:GetBool() ) ) then return end
|
||||
|
||||
-- check if we're looking at a valid entity
|
||||
local ent = ply:GetEyeTrace().Entity
|
||||
if ( not IsValid( ent ) ) then
|
||||
return
|
||||
end
|
||||
|
||||
-- check if they have the toolgun out and have stacker selected
|
||||
local wep = ply:GetActiveWeapon()
|
||||
if ( not ( IsValid( wep ) and wep:GetClass() == "gmod_tool" and cvarTool and cvarTool:GetString() == mode ) ) then
|
||||
return
|
||||
end
|
||||
|
||||
-- check if we're looking at a valid entity
|
||||
local ent = ply:GetEyeTrace().Entity
|
||||
if ( not IsValid( ent ) ) then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = ent:GetPos()
|
||||
|
||||
local f = ent:GetForward()
|
||||
@ -1673,4 +1676,4 @@ if ( CLIENT ) then
|
||||
end
|
||||
end )
|
||||
end )
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user