From 3850d850a0ffdc69978cde7d0bd85a932bad9f69 Mon Sep 17 00:00:00 2001 From: Porkch0p <49832728+Porkch0p@users.noreply.github.com> Date: Tue, 21 Jan 2025 19:47:57 -0600 Subject: [PATCH 1/6] Torso Rotation to Restore Thread Reduce signal usage for performance. Maintain faster timings on right arm --- scripts/dynstrike.lua | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/scripts/dynstrike.lua b/scripts/dynstrike.lua index 5f58d504a1..27aad7739e 100644 --- a/scripts/dynstrike.lua +++ b/scripts/dynstrike.lua @@ -57,6 +57,8 @@ local SIG_WALK = 32 local SIG_NANO = 64 local RESTORE_DELAY = 2500 +local RESTORE_DELAY_TORSO = 200 +local RESTORE_DELAY_RIGHT = 200 --------------------------------------------------------------------- --- blender-exported animation: data (move to include file?) --- @@ -447,20 +449,39 @@ function script.QueryWeapon(num) end local function RestoreTorsoAim(sleepTime) - Signal(SIG_RESTORE_TORSO) - SetSignalMask(SIG_RESTORE_TORSO) - Sleep(sleepTime or RESTORE_DELAY) + if sleepTime ~= nil then + Sleep(sleepTime) + end if not nanoing then Turn(Breast, z_axis, 0, TORSO_SPEED_YAW) aiming = false end end +local function RestoreTorsoAfterDelay(sleepTime) + local counter = (sleepTime or RESTORE_DELAY_TORSO) + while true do + if counter > 0 then + counter = counter - 100 + end + if resetRestoreTorso then + resetRestoreTorso = false + counter = RESTORE_DELAY_TORSO + end + if counter <= 0 then + if not nanoing then + RestoreTorsoAim() + end + end + Sleep(100) + end +end + local function RestoreRightAim(sleepTime) - StartThread(RestoreTorsoAim, sleepTime) + resetRestoreTorso = true Signal(SIG_RESTORE_RIGHT) SetSignalMask(SIG_RESTORE_RIGHT) - Sleep(sleepTime or RESTORE_DELAY) + Sleep(sleepTime or RESTORE_DELAY_RIGHT) if not nanoing then Turn(ArmRight, x_axis, math.rad(-5), ARM_SPEED_PITCH) Turn(HandRight, x_axis, math.rad(-5), ARM_SPEED_PITCH) @@ -468,7 +489,7 @@ local function RestoreRightAim(sleepTime) end local function RestoreLeftAim(sleepTime) - StartThread(RestoreTorsoAim, sleepTime) + resetRestoreTorso = true Signal(SIG_RESTORE_LEFT) SetSignalMask(SIG_RESTORE_LEFT) Sleep(sleepTime or RESTORE_DELAY) @@ -494,7 +515,7 @@ function script.AimWeapon(num, heading, pitch) Signal(SIG_LEFT) SetSignalMask(SIG_LEFT) Signal(SIG_RESTORE_LEFT) - Signal(SIG_RESTORE_TORSO) + resetRestoreTorso = true AimArm(heading, pitch, ArmLeft, Gun, true) StartThread(RestoreLeftAim) return true @@ -502,7 +523,7 @@ function script.AimWeapon(num, heading, pitch) Signal(SIG_RIGHT) SetSignalMask(SIG_RIGHT) Signal(SIG_RESTORE_RIGHT) - Signal(SIG_RESTORE_TORSO) + resetRestoreTorso = true AimArm(heading, pitch, ArmRight, HandRight, true) StartThread(RestoreRightAim) return true @@ -560,7 +581,9 @@ end function script.StopBuilding() SetUnitValue(COB.INBUILDSTANCE, 0) - StartThread(RestoreRightAim, 200) + Signal(SIG_RESTORE_RIGHT) + SetSignalMask(SIG_RESTORE_RIGHT) + StartThread(RestoreRightAim) StartThread(NanoRestore) nanoing = false end @@ -600,6 +623,7 @@ function script.Create() dyncomm.Create() Spring.SetUnitNanoPieces(unitID, nanoPieces) StartThread(GG.Script.SmokeUnit, unitID, smokePiece) + StartThread(RestoreTorsoAfterDelay) end function script.Killed(recentDamage, maxHealth) From 5cf87d608e5b56c34e0ed6e37202782a72913cf3 Mon Sep 17 00:00:00 2001 From: Porkch0p <49832728+Porkch0p@users.noreply.github.com> Date: Tue, 21 Jan 2025 21:04:19 -0600 Subject: [PATCH 2/6] Left Arm to Restore Thread Reduce signal usage for CPU performance (#4943) --- scripts/dynstrike.lua | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/scripts/dynstrike.lua b/scripts/dynstrike.lua index 27aad7739e..d1be7beea4 100644 --- a/scripts/dynstrike.lua +++ b/scripts/dynstrike.lua @@ -56,6 +56,9 @@ local SIG_RESTORE_TORSO = 16 local SIG_WALK = 32 local SIG_NANO = 64 +local resetRestoreLeft = false +local resetRestoreTorso = false + local RESTORE_DELAY = 2500 local RESTORE_DELAY_TORSO = 200 local RESTORE_DELAY_RIGHT = 200 @@ -489,14 +492,30 @@ local function RestoreRightAim(sleepTime) end local function RestoreLeftAim(sleepTime) - resetRestoreTorso = true - Signal(SIG_RESTORE_LEFT) - SetSignalMask(SIG_RESTORE_LEFT) - Sleep(sleepTime or RESTORE_DELAY) + if sleepTime ~= nil then + Sleep(sleepTime) + end Turn(ArmLeft, x_axis, math.rad(-5), ARM_SPEED_PITCH) Turn(Gun, x_axis, math.rad(-5), ARM_SPEED_PITCH) end +local function RestoreLeftAfterDelay(sleepTime) + local counter = (sleepTime or RESTORE_DELAY) + while true do + if counter > 0 then + counter = counter - 100 + end + if resetRestoreLeft then + resetRestoreLeft = false + counter = RESTORE_DELAY + end + if counter <= 0 then + RestoreLeftAim() + end + Sleep(100) + end +end + local function AimArm(heading, pitch, arm, hand, wait) aiming = true Turn(arm, x_axis, -pitch/2 - 0.7, ARM_SPEED_PITCH) @@ -512,12 +531,9 @@ function script.AimWeapon(num, heading, pitch) local weaponNum = dyncomm.GetWeapon(num) if weaponNum == 1 then - Signal(SIG_LEFT) - SetSignalMask(SIG_LEFT) - Signal(SIG_RESTORE_LEFT) resetRestoreTorso = true + resetRestoreLeft = true AimArm(heading, pitch, ArmLeft, Gun, true) - StartThread(RestoreLeftAim) return true elseif weaponNum == 2 then Signal(SIG_RIGHT) @@ -624,6 +640,7 @@ function script.Create() Spring.SetUnitNanoPieces(unitID, nanoPieces) StartThread(GG.Script.SmokeUnit, unitID, smokePiece) StartThread(RestoreTorsoAfterDelay) + StartThread(RestoreLeftAfterDelay) end function script.Killed(recentDamage, maxHealth) From 39c2747b81a88bc6c66ca8f7d997c836affed8de Mon Sep 17 00:00:00 2001 From: Porkch0p <49832728+Porkch0p@users.noreply.github.com> Date: Tue, 21 Jan 2025 22:25:38 -0600 Subject: [PATCH 3/6] Guardian Torso to Restore Thread Reduce performance hit when Guardian commander is firing --- scripts/dynassault.lua | 54 +++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/scripts/dynassault.lua b/scripts/dynassault.lua index 9736d8e134..d409f1455c 100644 --- a/scripts/dynassault.lua +++ b/scripts/dynassault.lua @@ -46,6 +46,7 @@ local ARM_SPEED_PITCH = math.rad(180) local ARM_PERPENDICULAR = math.rad(90) local RESTORE_DELAY = 2500 +local resetRestoreTorso = false -------------------------------------------------------------------------------- -- vars @@ -170,20 +171,6 @@ local function RestoreLegs() end -function script.Create() - dyncomm.Create() - Hide(rcannon_flare) - Hide(lnanoflare) - --- Turn(larm, x_axis, math.rad(30)) --- Turn(rarm, x_axis, math.rad(-10)) --- Turn(rhand, x_axis, math.rad(41)) --- Turn(lnanohand, x_axis, math.rad(36)) - - StartThread(GG.Script.SmokeUnit, unitID, smokePiece) - Spring.SetUnitNanoPieces(unitID, nanoPieces) -end - function script.StartMoving() StartThread(Walk) end @@ -197,14 +184,28 @@ end -------------------------------------------------------------------------------- local function RestoreTorsoAim() - Signal(SIG_RESTORE_TORSO) - SetSignalMask(SIG_RESTORE_TORSO) - Sleep(RESTORE_DELAY) Turn(torso, y_axis, restoreHeading, TORSO_SPEED_YAW) end +local function RestoreTorsoAfterDelay(sleepTime) + local counter = (sleepTime or RESTORE_DELAY) + while true do + if counter > 0 then + counter = counter - 100 + end + if resetRestoreTorso then + resetRestoreTorso = false + counter = RESTORE_DELAY + end + if counter <= 0 then + RestoreTorsoAim() + end + Sleep(100) + end +end + local function RestoreLaser() - StartThread(RestoreTorsoAim) + resetRestoreTorso = true Signal(SIG_RESTORE_LASER) SetSignalMask(SIG_RESTORE_LASER) Sleep(RESTORE_DELAY) @@ -220,7 +221,7 @@ local function RestoreLaser() end local function RestoreDGun() - StartThread(RestoreTorsoAim) + resetRestoreTorso = true Signal(SIG_RESTORE_DGUN) SetSignalMask(SIG_RESTORE_DGUN) Sleep(RESTORE_DELAY) @@ -327,6 +328,21 @@ function script.StartBuilding(heading, pitch) SetUnitValue(COB.INBUILDSTANCE, 1) end +function script.Create() + dyncomm.Create() + Hide(rcannon_flare) + Hide(lnanoflare) + +-- Turn(larm, x_axis, math.rad(30)) +-- Turn(rarm, x_axis, math.rad(-10)) +-- Turn(rhand, x_axis, math.rad(41)) +-- Turn(lnanohand, x_axis, math.rad(36)) + + StartThread(GG.Script.SmokeUnit, unitID, smokePiece) + StartThread(RestoreTorsoAfterDelay) + Spring.SetUnitNanoPieces(unitID, nanoPieces) +end + function script.Killed(recentDamage, maxHealth) local severity = recentDamage/maxHealth if severity < 0.5 then From 26dab39af98fd90fd49d039c8ef4658e4fa04b53 Mon Sep 17 00:00:00 2001 From: Porkch0p <49832728+Porkch0p@users.noreply.github.com> Date: Wed, 22 Jan 2025 01:29:08 -0600 Subject: [PATCH 4/6] Timing Adjustment: D-Gun and Walk Anim --- scripts/dynstrike.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/dynstrike.lua b/scripts/dynstrike.lua index d1be7beea4..4142450197 100644 --- a/scripts/dynstrike.lua +++ b/scripts/dynstrike.lua @@ -43,6 +43,7 @@ local smokePiece = {Breast, Head} local nanoPieces = {Nano} local nanoing = false local aiming = false +local walking = false local FINGER_ANGLE_IN = math.rad(10) local FINGER_ANGLE_OUT = math.rad(-25) @@ -61,7 +62,9 @@ local resetRestoreTorso = false local RESTORE_DELAY = 2500 local RESTORE_DELAY_TORSO = 200 -local RESTORE_DELAY_RIGHT = 200 +local RESTORE_DELAY_DGUN = 2500 +local RESTORE_DELAY_NANO = 200 +local RESTORE_DELAY_RIGHT = RESTORE_DELAY_NANO --------------------------------------------------------------------- --- blender-exported animation: data (move to include file?) --- @@ -350,6 +353,7 @@ local function Walk() local left = walkAngle[walkCycle] local right = walkAngle[3 - walkCycle] + walking = true ----------------------------------------------------------------------------------- Turn(HipLeft, x_axis, left[1].hip[1], left[1].hip[2] * speedMult) @@ -495,8 +499,10 @@ local function RestoreLeftAim(sleepTime) if sleepTime ~= nil then Sleep(sleepTime) end - Turn(ArmLeft, x_axis, math.rad(-5), ARM_SPEED_PITCH) - Turn(Gun, x_axis, math.rad(-5), ARM_SPEED_PITCH) + if not walking then + Turn(ArmLeft, x_axis, math.rad(-5), ARM_SPEED_PITCH) + Turn(Gun, x_axis, math.rad(-5), ARM_SPEED_PITCH) + end end local function RestoreLeftAfterDelay(sleepTime) @@ -529,7 +535,7 @@ end function script.AimWeapon(num, heading, pitch) local weaponNum = dyncomm.GetWeapon(num) - + walking = false if weaponNum == 1 then resetRestoreTorso = true resetRestoreLeft = true @@ -540,6 +546,11 @@ function script.AimWeapon(num, heading, pitch) SetSignalMask(SIG_RIGHT) Signal(SIG_RESTORE_RIGHT) resetRestoreTorso = true + if dyncomm.IsManualFire(num) then + RESTORE_DELAY_RIGHT = RESTORE_DELAY_DGUN + else + RESTORE_DELAY_RIGHT = RESTORE_DELAY_NANO + end AimArm(heading, pitch, ArmRight, HandRight, true) StartThread(RestoreRightAim) return true @@ -599,6 +610,7 @@ function script.StopBuilding() SetUnitValue(COB.INBUILDSTANCE, 0) Signal(SIG_RESTORE_RIGHT) SetSignalMask(SIG_RESTORE_RIGHT) + RESTORE_DELAY_RIGHT = RESTORE_DELAY_NANO StartThread(RestoreRightAim) StartThread(NanoRestore) nanoing = false From dc9d3e0303de5b35acc8458d22283c4d9f679005 Mon Sep 17 00:00:00 2001 From: Porkch0p <49832728+Porkch0p@users.noreply.github.com> Date: Wed, 22 Jan 2025 01:31:42 -0600 Subject: [PATCH 5/6] Pause countdown on Restore Thread while stunned --- scripts/dynassault.lua | 2 +- scripts/dynstrike.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/dynassault.lua b/scripts/dynassault.lua index d409f1455c..cc7d4d77f6 100644 --- a/scripts/dynassault.lua +++ b/scripts/dynassault.lua @@ -190,7 +190,7 @@ end local function RestoreTorsoAfterDelay(sleepTime) local counter = (sleepTime or RESTORE_DELAY) while true do - if counter > 0 then + if counter > 0 and not Spring.GetUnitIsStunned(unitID) then counter = counter - 100 end if resetRestoreTorso then diff --git a/scripts/dynstrike.lua b/scripts/dynstrike.lua index 4142450197..cf19b12eed 100644 --- a/scripts/dynstrike.lua +++ b/scripts/dynstrike.lua @@ -468,7 +468,7 @@ end local function RestoreTorsoAfterDelay(sleepTime) local counter = (sleepTime or RESTORE_DELAY_TORSO) while true do - if counter > 0 then + if counter > 0 and not Spring.GetUnitIsStunned(unitID) then counter = counter - 100 end if resetRestoreTorso then @@ -508,7 +508,7 @@ end local function RestoreLeftAfterDelay(sleepTime) local counter = (sleepTime or RESTORE_DELAY) while true do - if counter > 0 then + if counter > 0 and not Spring.GetUnitIsStunned(unitID) then counter = counter - 100 end if resetRestoreLeft then From ce451f7e1598442deef588f46a7c90bf59c9e972 Mon Sep 17 00:00:00 2001 From: Porkch0p <49832728+Porkch0p@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:47:00 -0600 Subject: [PATCH 6/6] Update scripts/dynassault.lua Co-authored-by: sprunk --- scripts/dynassault.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dynassault.lua b/scripts/dynassault.lua index cc7d4d77f6..b8fbeca6ea 100644 --- a/scripts/dynassault.lua +++ b/scripts/dynassault.lua @@ -195,7 +195,7 @@ local function RestoreTorsoAfterDelay(sleepTime) end if resetRestoreTorso then resetRestoreTorso = false - counter = RESTORE_DELAY + counter = (sleepTime or RESTORE_DELAY) end if counter <= 0 then RestoreTorsoAim()