Skip to content

Commit 2fe4de9

Browse files
committed
docs(Lua): document new delayed actions
1 parent 838ebd1 commit 2fe4de9

File tree

9 files changed

+779
-8
lines changed

9 files changed

+779
-8
lines changed

assets/Changelog.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,35 @@ Added global functions for mod management ([UE4SS #1105](https://github.com/UE4S
113113
- `RestartMod(ModName)` - Restart another mod by name
114114
- `UninstallMod(ModName)` - Uninstall another mod by name
115115

116+
Added comprehensive Delayed Action System for game-thread timer management ([UE4SS #XXXX](https://github.com/UE4SS-RE/RE-UE4SS/pull/XXXX))
117+
- New execution functions:
118+
- `ExecuteInGameThreadWithDelay(delayMs, callback)` - Execute after delay, returns handle
119+
- `ExecuteInGameThreadWithDelay(handle, delayMs, callback)` - UE Delay-style (only executes if handle not active)
120+
- `RetriggerableExecuteInGameThreadWithDelay(handle, delayMs, callback)` - Resets timer if called again (debouncing)
121+
- `LoopInGameThreadWithDelay(delayMs, callback)` - Repeating timer with handle
122+
- `ExecuteInGameThreadAfterFrames(frames, callback)` - Frame-based delay (requires EngineTick)
123+
- `LoopInGameThreadAfterFrames(frames, callback)` - Frame-based repeating timer
124+
- `MakeActionHandle()` - Generate unique handle for use with delay functions
125+
- Timer control functions:
126+
- `CancelDelayedAction(handle)` - Cancel a pending action
127+
- `PauseDelayedAction(handle)` - Pause a timer
128+
- `UnpauseDelayedAction(handle)` - Resume a paused timer
129+
- `ResetDelayedActionTimer(handle)` - Restart with original delay
130+
- `SetDelayedActionTimer(handle, newDelayMs)` - Change delay and restart
131+
- `ClearAllDelayedActions()` - Cancel all actions for current mod
132+
- Query functions:
133+
- `IsValidDelayedActionHandle(handle)` - Check if handle exists
134+
- `IsDelayedActionActive(handle)` - Check if timer is running
135+
- `IsDelayedActionPaused(handle)` - Check if timer is paused
136+
- `GetDelayedActionRate(handle)` - Get configured delay
137+
- `GetDelayedActionTimeRemaining(handle)` - Get remaining time
138+
- `GetDelayedActionTimeElapsed(handle)` - Get elapsed time
139+
- New global variables: `EngineTickAvailable`, `ProcessEventAvailable`
140+
- New enum: `EGameThreadMethod` with `ProcessEvent` and `EngineTick` values
141+
- `ExecuteInGameThread` now accepts optional second parameter for execution method
142+
- Per-mod action ownership ensures mods can only control their own timers
143+
- **Deprecates:** `ExecuteAsync` and `LoopAsync` (still work but lack control features)
144+
116145
**Updated Lua version to 5.4.7** ([UE4SS #887](https://github.com/UE4SS-RE/RE-UE4SS/pull/887))
117146
- This is necessary to compile with Clang.
118147

assets/Mods/shared/Types.lua

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,138 @@ function RegisterHook(UFunctionName, Callback) end
383383
---@param PostId integer
384384
function UnregisterHook(UFunctionName, PreId, PostId) end
385385

386-
---Execute code inside the game thread using ProcessEvent.
386+
---Specifies which hook to use for game thread execution
387+
---@enum EGameThreadMethod
388+
EGameThreadMethod = {
389+
---Execute via the ProcessEvent hook. Called frequently (multiple times per frame).
390+
ProcessEvent = 0,
391+
---Execute via the EngineTick hook. Called once per frame.
392+
EngineTick = 1,
393+
}
394+
395+
---True if EngineTick hook is available for frame-based delays
396+
---@type boolean
397+
EngineTickAvailable = false
398+
399+
---True if ProcessEvent hook is available
400+
---@type boolean
401+
ProcessEventAvailable = false
402+
403+
---Execute code inside the game thread.
387404
---Will execute as soon as the game has time to execute.
388405
---@param Callback fun()
389406
function ExecuteInGameThread(Callback) end
390407

408+
---Execute code inside the game thread using a specific method.
409+
---@param Callback fun()
410+
---@param Method EGameThreadMethod
411+
function ExecuteInGameThread(Callback, Method) end
412+
413+
---Execute callback after a delay in milliseconds. Returns a handle for control.
414+
---@param DelayMs integer Delay in milliseconds
415+
---@param Callback fun() Function to execute
416+
---@return integer handle Handle to control the action
417+
function ExecuteInGameThreadWithDelay(DelayMs, Callback) end
418+
419+
---Execute callback after a delay, but only if the handle is not already active (UE Delay-style).
420+
---If the handle is already active, does nothing and returns the same handle.
421+
---@param Handle integer Existing handle to check/reuse
422+
---@param DelayMs integer Delay in milliseconds
423+
---@param Callback fun() Function to execute
424+
---@return integer handle The provided handle
425+
function ExecuteInGameThreadWithDelay(Handle, DelayMs, Callback) end
426+
427+
---Execute callback after delay, resetting the timer if called again with the same handle.
428+
---Useful for debouncing.
429+
---@param Handle integer Handle to reset if active
430+
---@param DelayMs integer Delay in milliseconds
431+
---@param Callback fun() Function to execute
432+
---@return integer handle The provided handle
433+
function RetriggerableExecuteInGameThreadWithDelay(Handle, DelayMs, Callback) end
434+
435+
---Execute callback repeatedly with a delay between each execution.
436+
---Returns a handle that can be used to cancel the loop.
437+
---@param DelayMs integer Delay in milliseconds between executions
438+
---@param Callback fun() Function to execute repeatedly
439+
---@return integer handle Handle to control the loop
440+
function LoopInGameThreadWithDelay(DelayMs, Callback) end
441+
442+
---Execute callback after a number of frames (requires EngineTick hook).
443+
---@param Frames integer Number of frames to wait
444+
---@param Callback fun() Function to execute
445+
---@return integer handle Handle to control the action
446+
function ExecuteInGameThreadAfterFrames(Frames, Callback) end
447+
448+
---Execute callback repeatedly after a number of frames (requires EngineTick hook).
449+
---@param Frames integer Number of frames between executions
450+
---@param Callback fun() Function to execute repeatedly
451+
---@return integer handle Handle to control the loop
452+
function LoopInGameThreadAfterFrames(Frames, Callback) end
453+
454+
---Generate a unique action handle for use with delay functions.
455+
---@return integer handle A unique handle
456+
function MakeActionHandle() end
457+
458+
---Cancel a pending delayed action.
459+
---@param Handle integer Handle returned from a delay function
460+
---@return boolean success True if the action was cancelled
461+
function CancelDelayedAction(Handle) end
462+
463+
---Pause a delayed action, preserving remaining time.
464+
---@param Handle integer Handle returned from a delay function
465+
---@return boolean success True if the action was paused
466+
function PauseDelayedAction(Handle) end
467+
468+
---Resume a paused delayed action.
469+
---@param Handle integer Handle returned from a delay function
470+
---@return boolean success True if the action was resumed
471+
function UnpauseDelayedAction(Handle) end
472+
473+
---Reset a delayed action's timer to its original delay. Also unpauses if paused.
474+
---@param Handle integer Handle returned from a delay function
475+
---@return boolean success True if the timer was reset
476+
function ResetDelayedActionTimer(Handle) end
477+
478+
---Set a new delay for a delayed action and restart the timer. Also unpauses if paused.
479+
---@param Handle integer Handle returned from a delay function
480+
---@param NewDelayMs integer New delay in milliseconds
481+
---@return boolean success True if the timer was updated
482+
function SetDelayedActionTimer(Handle, NewDelayMs) end
483+
484+
---Cancel all delayed actions belonging to the current mod.
485+
---@return integer count Number of actions that were cancelled
486+
function ClearAllDelayedActions() end
487+
488+
---Check if a handle refers to a valid delayed action.
489+
---@param Handle integer Handle to check
490+
---@return boolean valid True if the handle exists
491+
function IsValidDelayedActionHandle(Handle) end
492+
493+
---Check if a delayed action is currently active (not paused, not cancelled).
494+
---@param Handle integer Handle to check
495+
---@return boolean active True if the action is active
496+
function IsDelayedActionActive(Handle) end
497+
498+
---Check if a delayed action is currently paused.
499+
---@param Handle integer Handle to check
500+
---@return boolean paused True if the action is paused
501+
function IsDelayedActionPaused(Handle) end
502+
503+
---Get the configured delay for a delayed action.
504+
---@param Handle integer Handle to check
505+
---@return integer delayMs Configured delay in milliseconds (or frames for frame-based), -1 if invalid
506+
function GetDelayedActionRate(Handle) end
507+
508+
---Get the remaining time until a delayed action fires.
509+
---@param Handle integer Handle to check
510+
---@return integer remainingMs Remaining time in milliseconds (or frames for frame-based), -1 if invalid
511+
function GetDelayedActionTimeRemaining(Handle) end
512+
513+
---Get the elapsed time since a delayed action was started/reset.
514+
---@param Handle integer Handle to check
515+
---@return integer elapsedMs Elapsed time in milliseconds (or frames for frame-based), -1 if invalid
516+
function GetDelayedActionTimeElapsed(Handle) end
517+
391518
---Returns a ThreadId object representing the id of the current thread.
392519
---@return ThreadId
393520
function GetCurrentThreadId() end

docs/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Table Definitions]()
2020
- [Key](./lua-api/table-definitions/key.md)
2121
- [ModifierKey](./lua-api/table-definitions/modifierkey.md)
22+
- [EGameThreadMethod](./lua-api/table-definitions/egamethreadmethod.md)
2223
- [PropertyTypes](./lua-api/table-definitions/propertytypes.md)
2324
- [OffsetInternalInfo](./lua-api/table-definitions/offsetinternalinfo.md)
2425
- [ArrayPropertyInfo](./lua-api/table-definitions/arraypropertyinfo.md)
@@ -79,6 +80,7 @@
7980
- [NotifyOnNewObject](./lua-api/global-functions/notifyonnewobject.md)
8081
- [ExecuteWithDelay](./lua-api/global-functions/executewithdelay.md)
8182
- [ExecuteInGameThread](./lua-api/global-functions/executeingamethread.md)
83+
- [Delayed Actions](./lua-api/global-functions/delayedactions.md)
8284
- [ExecuteAsync](./lua-api/global-functions/executeasync.md)
8385
- [LoopAsync](./lua-api/global-functions/loopasync.md)
8486
- [LoadAsset](./lua-api/global-functions/loadasset.md)

0 commit comments

Comments
 (0)