Skip to content

Commit

Permalink
Torso Rotation to Restore Thread
Browse files Browse the repository at this point in the history
Reduce signal usage for performance. Maintain faster timings on right arm
  • Loading branch information
Porkch0p committed Jan 22, 2025
1 parent d7d33fc commit 3850d85
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions scripts/dynstrike.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?) ---
Expand Down Expand Up @@ -447,28 +449,47 @@ 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)
end
end

local function RestoreLeftAim(sleepTime)
StartThread(RestoreTorsoAim, sleepTime)
resetRestoreTorso = true
Signal(SIG_RESTORE_LEFT)
SetSignalMask(SIG_RESTORE_LEFT)
Sleep(sleepTime or RESTORE_DELAY)
Expand All @@ -494,15 +515,15 @@ 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
elseif weaponNum == 2 then
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
Expand Down Expand Up @@ -560,7 +581,9 @@ end

function script.StopBuilding()
SetUnitValue(COB.INBUILDSTANCE, 0)
StartThread(RestoreRightAim, 200)

This comment has been minimized.

Copy link
@Porkch0p

Porkch0p Jan 22, 2025

Author Contributor

This was providing the timings for the torso and right arm weapon moving quickly instead of 2.5s RESTORE_DELAY

Signal(SIG_RESTORE_RIGHT)
SetSignalMask(SIG_RESTORE_RIGHT)
StartThread(RestoreRightAim)
StartThread(NanoRestore)
nanoing = false
end
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3850d85

Please sign in to comment.