Skip to content

Commit

Permalink
Fix GetEyeTraceNoCursor caching (#1645)
Browse files Browse the repository at this point in the history
* Fix GetEyeTraceNoCursor caching

Fixes Facepunch/garrysmod-issues#4430.

Also
- Use FrameNumber instead of CurTime for caching so that it doesn't clash with prediction
- Added skipcache arg to both GetEyeTrace and GetEyeTraceNoCursor for skipping the clientside cache
- Check if the PlayerTrace/PlayerAimTrace vars are tables before returning them in-case they're modified by other addons accidentally

* Fix styling

* Remove skipcache arg
  • Loading branch information
Kefta authored Apr 1, 2020
1 parent cec8870 commit 51db65a
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions garrysmod/gamemodes/base/gamemode/obj_player_extend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,45 +173,41 @@ end
Player Eye Trace
-----------------------------------------------------------]]
function meta:GetEyeTrace()

if ( CLIENT ) then
local curtime = CurTime()
local framenum = FrameNumber()

-- Cache the trace results for the current frame, unless we're serverside
-- in which case it wouldn't play well with lag compensation at all
if ( self.LastPlayerTrace == curtime ) then
if ( self.LastPlayerTrace == framenum ) then
return self.PlayerTrace
end

self.LastPlayerTrace = curtime
self.LastPlayerTrace = framenum
end

local tr = util.TraceLine( util.GetPlayerTrace( self ) )
self.PlayerTrace = tr

return tr

end

--[[---------------------------------------------------------
GetEyeTraceIgnoreCursor
Like GetEyeTrace but doesn't use the cursor aim vector..
-----------------------------------------------------------]]
function meta:GetEyeTraceNoCursor()

if ( CLIENT ) then
local curtime = CurTime()
local framenum = FrameNumber()

if ( self.LastPlayerAimTrace == curtime ) then
if ( self.LastPlayerAimTrace == framenum ) then
return self.PlayerAimTrace
end

self.LastPlayertAimTrace = curtime
self.LastPlayerAimTrace = framenum
end

local tr = util.TraceLine( util.GetPlayerTrace( self, self:EyeAngles():Forward() ) )
self.PlayerAimTrace = tr

return tr

end

0 comments on commit 51db65a

Please sign in to comment.