WIP: feat(api): set, hold and speed up the game's clock, and follow its hours #3282
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3282
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/Longshot:feat/world-clock-api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A mod can now set the game's clock, stop it, make it run slower or faster, and hear each hour as it passes. Until now the API could only read the time of day (
state().timeOfDay).world.setTime(hours): sets the clock. It uses the game's own clock setter, so it behaves the same as the game setting its time.world.holdTime(true|false): stops the clock, or lets it run again. It does this by holding the speed at 0, not by setting the clock back every game minute.world.setTimeScale(scale)andworld.timeScale(): how fast the time of day runs. 1 is the game's own speed, 0.2 a day five times as long, 0 stopped, at most 60. Each mod sets its own speed and the clock runs at their product. A hold stops the clock whatever the speeds. Both end when the mod stops.game.hourPassed: one event for each whole hour that passes, in order, also when several pass at once (the Sun's Song, a load that took time, asetTime), withjumpedset then.content.flag({ bind: { hours: [from, to] } })). A placement'swhenand a schedule's state then follow the clock with no script, also while a map loads.How the speed works: the game adds
2 * stepgame seconds to the time of day each frame, and main's siteframe.wholeTimeOfDayalready cuts that to whole seconds. The speed multiplies that amount at the site. At 1 the game's own code path runs unchanged. At any other speed the fractions are carried, because a slower day's share of a frame is under a second (0.4 at a fifth at 60 fps), and the game's cut would round it to 0. There is no new hook site and no builder change.This is also what a Day length setting can be built on: a system mod on
world.setTimeScale, as a follow-up to #2413 (written for the old C side).Read first:
game/crates/game-core/src/video.rs(on_frame_whole_time_of_day,time_of_day_whole,set_clock_rate), thengame/crates/api/src/services/world.rs(set_time,hold_time,set_time_scale,clock_step,hours_passed) andgame.rs'shourPassed. The schema is ingame/modapi/schema/world.tomlandgame.toml. The docs underdocs/modding/are generated from it.See #2413.
Testing
Tested: Windows 11, RTX 3080, NVIDIA 621.47, hidden window (
dev.py game-tests), over a base of mainf359e2621(before this branch was rebased onto mainde6fb7b5d; the rebase changed generated docs only, and movedhourPassedto order 32 because main'spressedevent now takes 31). A test mod read the clock while it set speeds, from a save at Hyrule Castle's gate (castle-gate, with the field's arrival flag set so the clock runs):holdTime(true)stopped it, andholdTime(false)let it run again.setTimejumped the clock, andhourPassednamed each hour of the jump, withjumpedset.ArgumentError.Checks:
cargo testofgame-core,api,content,schema,schema-genandmodtool,cargo clippy -D warnings,cargo fmt --checkandschema-gen --checkpass on the head. New unit tests cover the speed at 1, 0.2, 0, 3 and at 144 fps, the clamping, and hours passed over midnight and by a jump.Still to test:
holdTime, expecting the same clock rates (by hand).whenon it, expecting the placement to appear and go at those hours with no script (by hand).Measurements
Nothing to measure: with no mod using the clock, each frame does one relaxed atomic load at
frame.wholeTimeOfDay(then the game's own path) and one check of the running content mods for flags bound to hours, which is empty.Risks
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). The crates' cargo checks pass; the whole suite has not run on this head yet.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
world.setTime and holdTime (the game's own set of its clock), game.hourPassed (each whole hour, those of a jump and of a load too), and a content flag bound to hours of the clock (bind: { hours }), which a placement's when and a schedule's state follow with no script, while a map loads too. Ported onto main from the API extensions stack without its maps commit (travelTo and exits stay there). Co-Authored-By: Claude Opus 5.5 <[email protected]>Tested in game: Windows 11, RTX 3080, NVIDIA 621.47, dev.py game-tests from a save at Hyrule Castle's gate, over a base of main
f359e2621(before the rebase ontode6fb7b5d, which changed generated docs and hourPassed's order only): speeds 1, 0.25, 2, 3 and 60 ran the clock within 1% of 2 game minutes a second times the speed; 0 and holdTime stopped it; setTime jumped it and hourPassed named each hour of the jump; a speed out of range threw ArgumentError.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.