From e0850b34e841abe7f65e2407be932e1f13b3631d Mon Sep 17 00:00:00 2001 From: TheOnly8Z <8888888zombies@gmail.com> Date: Wed, 21 Apr 2021 21:36:43 +0800 Subject: [PATCH] I have clutched... something... from the jaws of source spaghetti --- .gitignore | 2 +- lua/weapons/arccw_base/sh_anim.lua | 108 ++++++++++++++++----------- lua/weapons/arccw_base/sh_firing.lua | 2 +- lua/weapons/arccw_base/sh_reload.lua | 32 +++++--- lua/weapons/arccw_base/shared.lua | 3 + 5 files changed, 93 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index 7d9bb335..07ec1b8e 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/lua/weapons/arccw_base/sh_anim.lua b/lua/weapons/arccw_base/sh_anim.lua index 1be7bb4b..a66c466a 100644 --- a/lua/weapons/arccw_base/sh_anim.lua +++ b/lua/weapons/arccw_base/sh_anim.lua @@ -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,45 +234,62 @@ 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 + end 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 - if anim.TPAnim then local aseq = self:GetOwner():SelectWeightedSequence(anim.TPAnim) if aseq then @@ -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() diff --git a/lua/weapons/arccw_base/sh_firing.lua b/lua/weapons/arccw_base/sh_firing.lua index cd5d0eb7..0f582fe5 100644 --- a/lua/weapons/arccw_base/sh_firing.lua +++ b/lua/weapons/arccw_base/sh_firing.lua @@ -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) diff --git a/lua/weapons/arccw_base/sh_reload.lua b/lua/weapons/arccw_base/sh_reload.lua index 0a2c4a59..d54a9498 100644 --- a/lua/weapons/arccw_base/sh_reload.lua +++ b/lua/weapons/arccw_base/sh_reload.lua @@ -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,15 +347,15 @@ function SWEP:ReloadInsert(empty) ret = self:GetBuff_Hook("Hook_SelectReloadAnimation", ret) or ret - self:PlayAnimation(ret, mult, true, 0, true, nil, true) - self:SetReloading(CurTime() + (self:GetAnimKeyTime(ret, true) * mult)) - self:SetTimer(self:GetAnimKeyTime(ret, true) * mult, - function() - self:SetNthReload(self:GetNthReload() + 1) - if self:GetOwner():KeyDown(IN_ATTACK2) then - self:EnterSights() - end - end) + 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() + self:SetNthReload(self:GetNthReload() + 1) + if self:GetOwner():KeyDown(IN_ATTACK2) then + self:EnterSights() + end + end) self:SetReqEnd(false) else @@ -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) diff --git a/lua/weapons/arccw_base/shared.lua b/lua/weapons/arccw_base/shared.lua index 1f583a9c..28f412ea 100644 --- a/lua/weapons/arccw_base/shared.lua +++ b/lua/weapons/arccw_base/shared.lua @@ -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()