Threads
Where plugin code runs: draws on the render thread, ticks on the game thread. Unless a plugin drives ticks, they’re the same thread and each tick runs just before its draw.
Threads.Subscription
Section titled “Threads.Subscription”cancel(): voidcancel()void Cancel()void cancel() constpub fn cancel(&self)fn cancel(self: Wraith.Threads.Subscription) voidvoid Wraith_Threads_Subscription_cancel(Wraith_Threads_Subscription self)cancel
Section titled “cancel”Fine to call twice, or from inside one.
Threads.WindDown
Section titled “Threads.WindDown”Says a plugin’s done winding down, from onStopping.
done(): voiddone()void Done()void done() constpub fn done(&self)fn done(self: Wraith.Threads.WindDown) voidvoid Wraith_Threads_WindDown_done(Wraith_Threads_WindDown self)Any thread. Fine to call twice.
Threads.Thread
Section titled “Threads.Thread”Handed to a thread of its own, see startThread.
stopping(): booleansleep(ms: number): booleanstopping(): booleansleep(ms: integer): booleanbool Stopping()bool Sleep(uint ms)bool stopping() constbool sleep(uint32_t ms) constpub fn stopping(&self) -> boolpub fn sleep(&self, ms: u32) -> boolfn stopping(self: Wraith.Threads.Thread) boolfn sleep(self: Wraith.Threads.Thread, ms: u32) boolbool Wraith_Threads_Thread_stopping(Wraith_Threads_Thread self)bool Wraith_Threads_Thread_sleep(Wraith_Threads_Thread self, uint32_t ms)stopping
Section titled “stopping”Asked to stop, by Running.stop or as the plugin unloads. Return soon after. Its thread.
Up to ms, waking early when asked to stop. False once asked. Its thread.
Threads.Running
Section titled “Threads.Running”stop(): voidstop()void Stop()void stop() constpub fn stop(&self)fn stop(self: Wraith.Threads.Running) voidvoid Wraith_Threads_Running_stop(Wraith_Threads_Running self)Asks it to stop and waits for it to return. Not from the thread itself. Fine to call twice.
Threads
Section titled “Threads”Get it with Api.threads().
onDraw(draw: Wraith.Threads.Draw): Wraith.Threads.SubscriptiononTick(tick: Wraith.Threads.Tick): Wraith.Threads.SubscriptionclaimTicks(changed: Wraith.Lease.Changed | null): Wraith.LeaserunTick(): voidonStopping(stopping: Wraith.Threads.Stopping): Wraith.Threads.SubscriptiononGameThread(): booleanpost(task: Wraith.Threads.Task): voidnow(): numbernextDraw(): Promise<void>nextTick(): Promise<void>toRender(): Promise<void>toGame(): Promise<void>toWorker(): Promise<void>delay(ms: number): Promise<void>run(name: string, job: Wraith.Threads.Job): voidstartThread(name: string, main: Wraith.Threads.ThreadMain): Wraith.Threads.RunningonDraw(draw: Wraith.Threads.Draw): Wraith.Threads.SubscriptiononTick(tick: Wraith.Threads.Tick): Wraith.Threads.SubscriptionclaimTicks(changed: Wraith.Lease.Changed|nil): Wraith.LeaserunTick()onStopping(stopping: Wraith.Threads.Stopping): Wraith.Threads.SubscriptiononGameThread(): booleanpost(task: Wraith.Threads.Task)now(): numbernextDraw(): salamander.PromisenextTick(): salamander.PromisetoRender(): salamander.PromisetoGame(): salamander.PromisetoWorker(): salamander.Promisedelay(ms: integer): salamander.Promiserun(name: string, job: Wraith.Threads.Job)startThread(name: string, main: Wraith.Threads.ThreadMain): Wraith.Threads.RunningWraith.Threads.Subscription? OnDraw(Wraith.Threads.Draw? draw)Wraith.Threads.Subscription? OnTick(Wraith.Threads.Tick? tick)Wraith.Lease? ClaimTicks(Wraith.Lease.Changed? changed)void RunTick()Wraith.Threads.Subscription? OnStopping(Wraith.Threads.Stopping? stopping)bool OnGameThread()void Post(Wraith.Threads.Task? task)double Now()System.Threading.Tasks.Task NextDrawAsync(System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task NextTickAsync(System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task ToRenderAsync(System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task ToGameAsync(System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task ToWorkerAsync(System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task DelayAsync(uint ms, System.Threading.CancellationToken cancel = default)void Run(string name, Wraith.Threads.Job? job)Wraith.Threads.Running? StartThread(string name, Wraith.Threads.ThreadMain? main)sal::Result<Wraith::Threads_Subscription, Wraith::ThreadsError> onDraw(Wraith::Threads_Draw draw) constsal::Result<Wraith::Threads_Subscription, Wraith::ThreadsError> onTick(Wraith::Threads_Tick tick) constsal::Result<Wraith::Lease, Wraith::ThreadsError> claimTicks(Wraith::Lease_Changed changed) constvoid runTick() constsal::Result<Wraith::Threads_Subscription, Wraith::ThreadsError> onStopping(Wraith::Threads_Stopping stopping) constbool onGameThread() constsal::Result<void, Wraith::ThreadsError> post(Wraith::Threads_Task task) constdouble now() constsal::Future<void, Wraith::ThreadsError> nextDraw() constsal::Future<void, Wraith::ThreadsError> nextTick() constsal::Future<void, Wraith::ThreadsError> toRender() constsal::Future<void, Wraith::ThreadsError> toGame() constsal::Future<void, Wraith::ThreadsError> toWorker() constsal::Future<void, Wraith::ThreadsError> delay(uint32_t ms) constsal::Result<void, Wraith::ThreadsError> run(std::string_view name, Wraith::Threads_Job job) constsal::Result<Wraith::Threads_Running, Wraith::ThreadsError> startThread(std::string_view name, Wraith::Threads_ThreadMain main) constpub fn on_draw(&self, draw: wraith::ThreadsDraw) -> Result<wraith::ThreadsSubscription, wraith::ThreadsError>pub fn on_tick(&self, tick: wraith::ThreadsTick) -> Result<wraith::ThreadsSubscription, wraith::ThreadsError>pub fn claim_ticks(&self, changed: wraith::LeaseChanged) -> Result<wraith::Lease, wraith::ThreadsError>pub fn run_tick(&self)pub fn on_stopping(&self, stopping: wraith::ThreadsStopping) -> Result<wraith::ThreadsSubscription, wraith::ThreadsError>pub fn on_game_thread(&self) -> boolpub fn post(&self, task: wraith::ThreadsTask) -> Result<(), wraith::ThreadsError>pub fn now(&self) -> f64pub fn next_draw(&self) -> salamander::Future<(), wraith::ThreadsError>pub fn next_tick(&self) -> salamander::Future<(), wraith::ThreadsError>pub fn to_render(&self) -> salamander::Future<(), wraith::ThreadsError>pub fn to_game(&self) -> salamander::Future<(), wraith::ThreadsError>pub fn to_worker(&self) -> salamander::Future<(), wraith::ThreadsError>pub fn delay(&self, ms: u32) -> salamander::Future<(), wraith::ThreadsError>pub fn run(&self, name: &str, job: wraith::ThreadsJob) -> Result<(), wraith::ThreadsError>pub fn start_thread(&self, name: &str, main: wraith::ThreadsThreadMain) -> Result<wraith::ThreadsRunning, wraith::ThreadsError>fn onDraw(self: Wraith.Threads, draw: Wraith.Threads.Draw) (Wraith.ThreadsError || rt.Failure)!Wraith.Threads.Subscriptionfn onTick(self: Wraith.Threads, tick: Wraith.Threads.Tick) (Wraith.ThreadsError || rt.Failure)!Wraith.Threads.Subscriptionfn claimTicks(self: Wraith.Threads, changed: ?Wraith.Lease.Changed) (Wraith.ThreadsError || rt.Failure)!Wraith.Leasefn runTick(self: Wraith.Threads) voidfn onStopping(self: Wraith.Threads, stopping: Wraith.Threads.Stopping) (Wraith.ThreadsError || rt.Failure)!Wraith.Threads.Subscriptionfn onGameThread(self: Wraith.Threads) boolfn post(self: Wraith.Threads, task: Wraith.Threads.Task) (Wraith.ThreadsError || rt.Failure)!voidfn now(self: Wraith.Threads) f64fn nextDraw(self: Wraith.Threads) rt.Promise((Wraith.ThreadsError || rt.Failure)!void, Wraith.ThreadsErrorCode)fn nextTick(self: Wraith.Threads) rt.Promise((Wraith.ThreadsError || rt.Failure)!void, Wraith.ThreadsErrorCode)fn toRender(self: Wraith.Threads) rt.Promise((Wraith.ThreadsError || rt.Failure)!void, Wraith.ThreadsErrorCode)fn toGame(self: Wraith.Threads) rt.Promise((Wraith.ThreadsError || rt.Failure)!void, Wraith.ThreadsErrorCode)fn toWorker(self: Wraith.Threads) rt.Promise((Wraith.ThreadsError || rt.Failure)!void, Wraith.ThreadsErrorCode)fn delay(self: Wraith.Threads, ms: u32) rt.Promise((Wraith.ThreadsError || rt.Failure)!void, Wraith.ThreadsErrorCode)fn run(self: Wraith.Threads, name: []const u8, job: Wraith.Threads.Job) (Wraith.ThreadsError || rt.Failure)!voidfn startThread(self: Wraith.Threads, name: []const u8, main: Wraith.Threads.ThreadMain) (Wraith.ThreadsError || rt.Failure)!Wraith.Threads.Runninguint32_t Wraith_Threads_onDraw(Wraith_Threads self, Wraith_Threads_Draw draw, Wraith_Threads_Subscription *out)uint32_t Wraith_Threads_onTick(Wraith_Threads self, Wraith_Threads_Tick tick, Wraith_Threads_Subscription *out)uint32_t Wraith_Threads_claimTicks(Wraith_Threads self, Wraith_Lease_Changed changed, Wraith_Lease *out)void Wraith_Threads_runTick(Wraith_Threads self)uint32_t Wraith_Threads_onStopping(Wraith_Threads self, Wraith_Threads_Stopping stopping, Wraith_Threads_Subscription *out)bool Wraith_Threads_onGameThread(Wraith_Threads self)uint32_t Wraith_Threads_post(Wraith_Threads self, Wraith_Threads_Task task)double Wraith_Threads_now(Wraith_Threads self)sal_Promise Wraith_Threads_nextDraw(Wraith_Threads self)sal_Promise Wraith_Threads_nextTick(Wraith_Threads self)sal_Promise Wraith_Threads_toRender(Wraith_Threads self)sal_Promise Wraith_Threads_toGame(Wraith_Threads self)sal_Promise Wraith_Threads_toWorker(Wraith_Threads self)sal_Promise Wraith_Threads_delay(Wraith_Threads self, uint32_t ms)uint32_t Wraith_Threads_run(Wraith_Threads self, sal_string name, Wraith_Threads_Job job)uint32_t Wraith_Threads_startThread(Wraith_Threads self, sal_string name, Wraith_Threads_ThreadMain main, Wraith_Threads_Running *out)onDraw
Section titled “onDraw”Once a frame on the render thread, for UI. Gone with the plugin.
Fails with ThreadsError. Uses Threads.Draw, Threads.Subscription.
onTick
Section titled “onTick”Once a tick on the game thread, for game logic. Gone with the plugin.
Fails with ThreadsError. Uses Threads.Tick, Threads.Subscription.
claimTicks
Section titled “claimTicks”A lease on ticks, see Lease. While held, ticks run on its runTick and wait for the first, so
claim in start. Unheld, they’re back on the render thread.
Fails with ThreadsError. Uses Lease.Changed, Lease.
runTick
Section titled “runTick”Once a game frame on the game’s thread, from the ticks holder. Runs every onTick. A no-op otherwise.
Not tick, which C# would make the same name as Tick.
onStopping
Section titled “onStopping”Before unload, to undo game changes from the right thread. Call wind_down.done when finished;
Wraith waits up to a second. Not when the game’s closing. Gone with the plugin.
Fails with ThreadsError. Uses Threads.Stopping, Threads.Subscription.
onGameThread
Section titled “onGameThread”Whether this is the tick thread. False everywhere till the first tick.
Any thread. Posted from inside a task, it waits a draw.
Fails with ThreadsError. Uses Threads.Task.
Milliseconds on a steady clock, with fractions. Any thread.
nextDraw
Section titled “nextDraw”At the start of the next draw, before its tick, on the render thread. Any thread.
Async. Fails with ThreadsError.
nextTick
Section titled “nextTick”At the next tick, on the game thread.
Async. Fails with ThreadsError.
toRender
Section titled “toRender”On the render thread, right away if already there, else at the next draw.
Async. Fails with ThreadsError.
toGame
Section titled “toGame”On the game thread, right away if already there, else at its next tick. Never block there.
Async. Fails with ThreadsError.
toWorker
Section titled “toWorker”On a worker, for slow or blocking work. Right away if already on one.
Async. Fails with ThreadsError.
After ms milliseconds, back on the calling thread (its next draw or tick for those threads).
Async. Fails with ThreadsError.
Once on a worker. Fine to block, like on a download.
Fails with ThreadsError. Uses Threads.Job.
startThread
Section titled “startThread”A thread of its own, for a loop that runs while the plugin does. Stopped and waited for as it
unloads, after onStopping.
Fails with ThreadsError. Uses Threads.ThreadMain, Threads.Running.
ThreadsError
Section titled “ThreadsError”What can go wrong, besides Cancelled, Unsupported and Gone.
| Code | Error | |
|---|---|---|
| 1 | NoFrames |
|
| 2 | Failed |
|
| 3 | NotForScripts |
Scripts run one thread at a time. await async calls instead, or use a native plugin |
Threads.Draw
Section titled “Threads.Draw”Once a frame on the render thread, inside an ImGui frame (a headless one if the overlay can’t draw).
Wraith.Threads.DrawWraith.Threads.DrawWraith.Threads.DrawWraith::Threads_Drawwraith::ThreadsDrawWraith.Threads.DrawWraith_Threads_DrawThreads.Task
Section titled “Threads.Task”Once, on the render thread at the start of the next draw, before its tick.
Wraith.Threads.TaskWraith.Threads.TaskWraith.Threads.TaskWraith::Threads_Taskwraith::ThreadsTaskWraith.Threads.TaskWraith_Threads_TaskThreads.Tick
Section titled “Threads.Tick”Once a tick on the game thread. No drawing here.
Wraith.Threads.TickWraith.Threads.TickWraith.Threads.TickWraith::Threads_Tickwraith::ThreadsTickWraith.Threads.TickWraith_Threads_TickThreads.Stopping
Section titled “Threads.Stopping”As the plugin’s about to stop, with everything still working.
Wraith.Threads.StoppingWraith.Threads.StoppingWraith.Threads.StoppingWraith::Threads_Stoppingwraith::ThreadsStoppingWraith.Threads.StoppingWraith_Threads_StoppingThreads.Job
Section titled “Threads.Job”Once, on a worker, for run.
Wraith.Threads.JobWraith.Threads.JobWraith.Threads.JobWraith::Threads_Jobwraith::ThreadsJobWraith.Threads.JobWraith_Threads_JobThreads.ThreadMain
Section titled “Threads.ThreadMain”A thread’s loop. Returns once thread.stopping() says so.
Wraith.Threads.ThreadMainWraith.Threads.ThreadMainWraith.Threads.ThreadMainWraith::Threads_ThreadMainwraith::ThreadsThreadMainWraith.Threads.ThreadMainWraith_Threads_ThreadMainwraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
