Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of strike/guardian weapons #5443

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions scripts/dynassault.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 and not Spring.GetUnitIsStunned(unitID) then
counter = counter - 100
end
if resetRestoreTorso then
resetRestoreTorso = false
counter = (sleepTime or 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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
91 changes: 72 additions & 19 deletions scripts/dynstrike.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -56,7 +57,14 @@ 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_DGUN = 2500
local RESTORE_DELAY_NANO = 200
local RESTORE_DELAY_RIGHT = RESTORE_DELAY_NANO

---------------------------------------------------------------------
--- blender-exported animation: data (move to include file?) ---
Expand Down Expand Up @@ -345,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)
Expand Down Expand Up @@ -447,33 +456,70 @@ 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 and not Spring.GetUnitIsStunned(unitID) 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)
Signal(SIG_RESTORE_LEFT)
SetSignalMask(SIG_RESTORE_LEFT)
Sleep(sleepTime or RESTORE_DELAY)
Turn(ArmLeft, x_axis, math.rad(-5), ARM_SPEED_PITCH)
Turn(Gun, x_axis, math.rad(-5), ARM_SPEED_PITCH)
if sleepTime ~= nil then
Sleep(sleepTime)
end
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)
local counter = (sleepTime or RESTORE_DELAY)
while true do
if counter > 0 and not Spring.GetUnitIsStunned(unitID) 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)
Expand All @@ -489,20 +535,22 @@ end

function script.AimWeapon(num, heading, pitch)
local weaponNum = dyncomm.GetWeapon(num)

walking = false
if weaponNum == 1 then
Signal(SIG_LEFT)
SetSignalMask(SIG_LEFT)
Signal(SIG_RESTORE_LEFT)
Signal(SIG_RESTORE_TORSO)
resetRestoreTorso = true
resetRestoreLeft = 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
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
Expand Down Expand Up @@ -560,7 +608,10 @@ end

function script.StopBuilding()
SetUnitValue(COB.INBUILDSTANCE, 0)
StartThread(RestoreRightAim, 200)
Signal(SIG_RESTORE_RIGHT)
SetSignalMask(SIG_RESTORE_RIGHT)
RESTORE_DELAY_RIGHT = RESTORE_DELAY_NANO
StartThread(RestoreRightAim)
StartThread(NanoRestore)
nanoing = false
end
Expand Down Expand Up @@ -600,6 +651,8 @@ function script.Create()
dyncomm.Create()
Spring.SetUnitNanoPieces(unitID, nanoPieces)
StartThread(GG.Script.SmokeUnit, unitID, smokePiece)
StartThread(RestoreTorsoAfterDelay)
StartThread(RestoreLeftAfterDelay)
end

function script.Killed(recentDamage, maxHealth)
Expand Down