I have clutched... something... from the jaws of source spaghetti

This commit is contained in:
TheOnly8Z 2021-04-21 21:36:43 +08:00
parent efaa247d42
commit e0850b34e8
5 changed files with 93 additions and 54 deletions

2
.gitignore vendored
View File

@ -1,4 +1,3 @@
arccw.code-workspace
upload.cmd
workshop_id.cmd
.VSCodeCounter/2021-01-30_17-43-13/details.md
@ -9,3 +8,4 @@ workshop_id.cmd
.VSCodeCounter/2021-02-19_16-55-12/results.csv
.VSCodeCounter/2021-02-19_16-55-12/results.md
.VSCodeCounter/2021-02-19_16-55-12/results.txt
*.code-workspace

View File

@ -42,6 +42,8 @@ function SWEP:PlayAnimation(key, mult, pred, startfrom, tt, skipholster, ignorer
ignorereload = ignorereload or false
absolute = absolute or false
local ct = CurTime() --pred and CurTime() or UnPredictedCurTime()
if !self.Animations[key] then return end
if self:GetReloading() and !ignorereload then return end
@ -131,12 +133,12 @@ function SWEP:PlayAnimation(key, mult, pred, startfrom, tt, skipholster, ignorer
if startfrom > (time * mult) then return end
if tt then
self:SetNextPrimaryFire(CurTime() + ((anim.MinProgress or time) * mult) - startfrom)
self:SetNextPrimaryFire(ct + ((anim.MinProgress or time) * mult) - startfrom)
end
if CLIENT then
vm:SetAnimTime(CurTime() - startfrom)
end
--if CLIENT then
-- vm:SetAnimTime(ct - startfrom)
--end
if anim.LHIK then
-- self.LHIKTimeline = {
@ -155,8 +157,8 @@ function SWEP:PlayAnimation(key, mult, pred, startfrom, tt, skipholster, ignorer
-- self.LHIKTimeline[3] = math.huge
-- self.LHIKTimeline[4] = math.huge
-- end
self.LHIKStartTime = CurTime()
self.LHIKEndTime = CurTime() + ttime
self.LHIKStartTime = ct
self.LHIKEndTime = ct + ttime
if anim.LHIKTimeline then
self.LHIKTimeline = {}
@ -189,7 +191,7 @@ function SWEP:PlayAnimation(key, mult, pred, startfrom, tt, skipholster, ignorer
end
if anim.LastClip1OutTime then
self.LastClipOutTime = CurTime() + ((anim.LastClip1OutTime * mult) - startfrom)
self.LastClipOutTime = ct + ((anim.LastClip1OutTime * mult) - startfrom)
end
local seq = anim.Source
@ -212,7 +214,14 @@ function SWEP:PlayAnimation(key, mult, pred, startfrom, tt, skipholster, ignorer
seq = vm:LookupSequence(seq)
end
if seq then --!game.SinglePlayer() and CLIENT
--local lastseq = self:GetLastSequence()
--self:SetLastSequence(seq)
local lastanim = self:GetLastAnim()
self:SetLastAnim(key)
-- Hack to fix an issue with playing one anim multiple times in a row
-- Provided by Jackarunda
local resetSeq = anim.HardResetAnim and vm:LookupSequence(anim.HardResetAnim)
@ -225,44 +234,61 @@ function SWEP:PlayAnimation(key, mult, pred, startfrom, tt, skipholster, ignorer
vm:SetPlaybackRate(math.Clamp(dur / (ttime + startfrom), -4, 12))
end)
else
--[[]
if seq > 0 and IsFirstTimePredicted() then
print(self:GetOwner(), seq, self:GetLastSequence(), CurTime(), UnPredictedCurTime())
if SERVER then
PrintMessage(HUD_PRINTTALK, "SERVER: " .. tostring(self:GetOwner()) .. " " .. tostring(seq) .. " " .. CurTime())
end
end
]]
--[[]
print(seq, lastseq, CurTime())
vm:SendViewModelMatchingSequence(seq)
local dur = vm:SequenceDuration()
vm:SetPlaybackRate(math.Clamp(dur / (ttime + startfrom), -4, 12))
self.LastAnimStartTime = CurTime()
self.LastAnimFinishTime = CurTime() + (dur * mult)
self.LastAnimStartTime = ct
self.LastAnimFinishTime = ct + (dur * mult)
]]
if anim == lastanim then
vm:SendViewModelMatchingSequence(seq)
vm:SetPlaybackRate(0)
vm:SetCycle(0)
--if seq ~= lastseq then self:PlayIdleAnimation(pred) end
--print("identical", seq, CurTime())
if pred and IsFirstTimePredicted() then
timer.Simple(0, function()
vm:SendViewModelMatchingSequence(seq)
local dur = vm:SequenceDuration()
vm:SetPlaybackRate(math.Clamp(dur / (ttime + startfrom), -4, 12))
self.LastAnimStartTime = ct
self.LastAnimFinishTime = ct + (dur * mult)
self:SetTimer(ttime, function()
self:NextAnimation()
end, key)
self:SetTimer(ttime, function()
self:PlayIdleAnimation(pred)
end, "idlereset")
end)
end
else
--print("new", seq, lastseq, CurTime())
vm:SendViewModelMatchingSequence(seq)
local dur = vm:SequenceDuration()
vm:SetPlaybackRate(math.Clamp(dur / (ttime + startfrom), -4, 12))
self.LastAnimStartTime = ct
self.LastAnimFinishTime = ct + (dur * mult)
end
-- :(
-- unfortunately, gmod seems to have broken the features required for this to work.
-- as such, I'm reverting to a more traditional reload system.
-- local framestorealtime = 1
-- if anim.FrameRate then
-- framestorealtime = 1 / anim.FrameRate
-- end
-- local dur = vm:SequenceDuration()
-- vm:SetPlaybackRate(dur / (ttime + startfrom))
-- if anim.Checkpoints then
-- self.CheckpointAnimation = key
-- self.CheckpointTime = startfrom
-- for i, k in pairs(anim.Checkpoints) do
-- if !k then continue end
-- if istable(k) then continue end
-- local realtime = k * framestorealtime
-- if realtime > startfrom then
-- self:SetTimer((realtime * mult) - startfrom, function()
-- self.CheckpointAnimation = key
-- self.CheckpointTime = realtime
-- end)
-- end
-- end
-- end
end
end
if anim.TPAnim then
local aseq = self:GetOwner():SelectWeightedSequence(anim.TPAnim)
@ -292,8 +318,6 @@ function SWEP:PlayAnimation(key, mult, pred, startfrom, tt, skipholster, ignorer
self:SetTimer(ttime, function()
self:NextAnimation()
-- self:ResetCheckpoints()
end, key)
self:SetTimer(ttime, function()

View File

@ -506,7 +506,7 @@ function SWEP:DoPrimaryAnim()
local time = self:GetBuff_Mult("Mult_FireAnimTime", anim) or 1
if anim and (CLIENT or game.SinglePlayer()) then self:PlayAnimation(anim, time, true, 0, false) end
if anim then self:PlayAnimation(anim, time, false, 0, false) end
end
function SWEP:DoPenetration(tr, penleft, alreadypenned)

View File

@ -20,6 +20,7 @@ function SWEP:SetClipInfo(load)
end
function SWEP:Reload()
if self:GetOwner():IsNPC() then
return
end
@ -37,6 +38,17 @@ function SWEP:Reload()
-- if !game.SinglePlayer() and !IsFirstTimePredicted() then return end
-- DEBUG
--[[]
local vm = self.Owner:GetViewModel()
vm:SendViewModelMatchingSequence(vm:LookupSequence("reload"))
print("reload", CurTime())
if SERVER then
PrintMessage(HUD_PRINTTALK, "SERVER: " .. tostring(self:GetOwner()) .. " " .. CurTime())
end
if true then self:SetNextPrimaryFire(CurTime() + 2) return end
]]
if self.Throwing then return end
if self.PrimaryBash then return end
@ -335,7 +347,7 @@ function SWEP:ReloadInsert(empty)
ret = self:GetBuff_Hook("Hook_SelectReloadAnimation", ret) or ret
self:PlayAnimation(ret, mult, true, 0, true, nil, true)
self:PlayAnimation(ret, mult, false, 0, true, nil, true)
self:SetReloading(CurTime() + (self:GetAnimKeyTime(ret, true) * mult))
self:SetTimer(self:GetAnimKeyTime(ret, true) * mult,
function()
@ -370,7 +382,7 @@ function SWEP:ReloadInsert(empty)
self:SetReloading(CurTime() + time * mult)
self:PlayAnimation(insertanim, mult, true, 0, true, nil, true)
self:PlayAnimation(insertanim, mult, false, 0, true, nil, true)
self:SetTimer(time * mult,
function()
self:ReloadInsert(empty)

View File

@ -717,6 +717,7 @@ function SWEP:SetupDataTables()
self:NetworkVar("Int", 3, "LastLoad")
self:NetworkVar("Int", 4, "NthReload")
self:NetworkVar("Int", 5, "NthShot")
--self:NetworkVar("Int", 6, "LastSequence")
self:NetworkVar("Bool", 0, "HeatLocked")
self:NetworkVar("Bool", 1, "NeedCycle")
@ -731,6 +732,8 @@ function SWEP:SetupDataTables()
self:NetworkVar("Float", 2, "ReloadingREAL")
self:NetworkVar("Float", 3, "MagUpIn")
self:NetworkVar("Float", 4, "NextPrimaryFireSlowdown")
self:NetworkVar("String", 0, "LastAnim")
end
function SWEP:OnRestore()