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

Add adjustable delay to how fast QuickDrop fires #6113

Open
wants to merge 2 commits into
base: deploy/fafdevelop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions lua/sim/units/AirTransportUnit.lua
Expand Up @@ -30,6 +30,9 @@ local HorzUnloadMargin = 2.5
-- Factor by which to multiply TransportHoverHeight when determining if we can unload cargo
local VertUnloadFactor = 1.5

-- time delay after which quick drop fires (drops can be faster than this, but not slower)
local QuickDropDelay = 10
clyfordv marked this conversation as resolved.
Show resolved Hide resolved

---@class AirTransport: AirUnit, BaseTransport
---@field slots table<Bone, Unit>
---@field GroundImpacted boolean
Expand Down Expand Up @@ -68,9 +71,15 @@ AirTransport = ClassUnit(AirUnit, BaseTransport) {
return
end

-- Tell our navigator to abort the move
-- Tell our navigator to abort the move after a delay/if we haven't detached cargo in the interim
-- this has the effect of causing the next unload command to be executed immediately
navigator:AbortMove()
self.dropFlag = true
ForkThread(function()
lL1l1 marked this conversation as resolved.
Show resolved Hide resolved
WaitTicks(QuickDropDelay)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forking a thread waits 1 tick but then WaitTicks correctly waits 10 ticks from before the thread was forked. e.g.:

LOG(GetGameTick()) -- tick 1
ForkThread(function ()
LOG(GetGameTick()) -- tick 2
WaitTicks(10)
LOG(GetGameTick()) -- tick 11

I don't really understand it but it works as long as QuickDropDelay >= 2 (1 delay ends up the same as 2).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that warrants a warning if the delay is too short? I don't see this number being changed too often.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting ticks is a bit strange - waiting 0 and 1 ticks is effectively the same tick! When we pass in 1 tack then we effectively tell the game to perform this function at the end of the current tick. When we wait 2 ticks, we tell the game to queue it for the next tick.

Effectively we also wait for the 'current' tick.

Copy link
Contributor

@lL1l1 lL1l1 May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that warrants a warning if the delay is too short? I don't see this number being changed too often.

I think a comment saying that the minimum is 2 ticks is sufficient.

When we pass in 1 tack then we effectively tell the game to perform this function at the end of the current tick. When we wait 2 ticks, we tell the game to queue it for the next tick.

Is that why some waits have off by 1 error compensation?

-- various delays in ticks + 1
local BuildCubeGlowDuration = 2
local BuildCubeDelay = 8
local BuildCubeFirstSliceDelay = 3
local BuildCubeSlicePeriod = 12
local BuilderSlicePeriod = 6

for t = 0.2, accelTime, 0.2 do
self:SetMaxSpeed(maxSpeed - (maxSpeed - terminalSpeed) * t/accelTime)
WaitTicks(3) -- This waits 2 ticks instead of 3 according to GetGameTick().
end

-- Wait a tick to let the target update awesomely.
WaitTicks(2)
self.timeAlive = self.timeAlive + .1

if self.dropFlag then
navigator:AbortMove()
end
end)
end
end
end,
Expand All @@ -87,6 +96,8 @@ AirTransport = ClassUnit(AirUnit, BaseTransport) {
---@param attachBone Bone
---@param unit Unit
OnTransportDetach = function(self, attachBone, unit)
-- Tell quick drop we didn't need it, and not to abort the next move
if self.dropFlag then self.dropFlag = nil end
AirUnitOnTransportDetach(self, attachBone, unit)
BaseTransportOnTransportDetach(self, attachBone, unit)
end,
Expand Down