Skip to content

Commit

Permalink
Fix prediction problems with the new input system
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDotBat committed Jan 22, 2021
1 parent f4f21ff commit 6d0e143
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions cl_ui3d2d.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@
ui3d2d = ui3d2d or {}

do --Input handling
local getRenderTarget, cursorVisible = render.GetRenderTarget, vgui.CursorVisible
local useBind = input.LookupBinding("+use", true)
local attackBind = input.LookupBinding("+attack", true)

local inputCount = 0

hook.Add("KeyPress", "ui3d2d.inputHandler", function(ply, key)
if key ~= IN_USE and key ~= IN_ATTACK then return end
inputCount = inputCount + 1
end)

hook.Add("KeyRelease", "ui3d2d.inputHandler", function(ply, key)
if key ~= IN_USE and key ~= IN_ATTACK then return end
inputCount = inputCount - 1
end)
do
local lookupBinding = input.LookupBinding
timer.Create("ui3d2d.lookupBindings", 5, 0, function() --Keep our use and attack bind keys up to date
useBind = lookupBinding("+use", true)
attackBind = lookupBinding("+attack", true)
end)
end

do
local getRenderTarget, cursorVisible = render.GetRenderTarget, vgui.CursorVisible
local getKeyCode, isButtonDown = input.GetKeyCode, input.IsButtonDown

local inputEnabled, isPressing, isPressed

hook.Add("PreRender", "ui3d2d.inputHandler", function() --Check the input state before rendering UIs
if getRenderTarget() then inputEnabled = false return end
if cursorVisible() then inputEnabled = false return end

local useKey = useBind and getKeyCode(useBind)
local attackKey = attackBind and getKeyCode(attackBind)

inputEnabled = true

local wasPressing = isPressing
isPressing = inputCount > 0
isPressing = (useKey and isButtonDown(useKey)) or (attackKey and isButtonDown(attackKey))
isPressed = not wasPressing and isPressing
end)

Expand Down

0 comments on commit 6d0e143

Please sign in to comment.