Skip to content

Fix world.tod_changed firing every frame while a world.tod hook is active - #408

Closed
devilmaker20 wants to merge 1 commit into
UNDERdecoded:mainfrom
devilmaker20:claude/fix-tod-changed-every-frame
Closed

devilmaker20 wants to merge 1 commit into
UNDERdecoded:mainfrom
devilmaker20:claude/fix-tod-changed-every-frame

Conversation

@devilmaker20

Copy link
Copy Markdown

Requested by Nuno · project thread

Problem

OverworldState:timeOfDay() emits world.tod_changed on every call, which means every frame, whenever a world.tod hook returns a different period from the clock's.

In the hooked branch the hook's result (nextTod) is compared with the raw clock period (tod), not with the period this state last reported (self.tod). So a hook that returns, say, EVENING while the clock says DAY makes nextTod ~= tod true on every call. The event then fires with {tod = EVENING, previous = DAY} every frame.

We measured about 2,300 emits in 12 seconds with a day/night mod that adds an EVENING period. Every listener that rebuilds on this event loops. In our case, visible wild Pokémon were cleared and respawned each frame.

Fix

Compare with self.tod, the period last reported, as the unhooked branch already does. Emit only on a real change, and not on the first assignment (previous == nil), which is the same rule the unhooked path uses.

The hook result and the value timeOfDay() returns are unchanged. Only the duplicate events go away.

Testing

  • The file compiles under LÖVE 12.
  • The same logic, applied as a listener-side dedupe in our mod, brought wild respawns from about 500 to 1 in 12 seconds on OmegaRecomp 1.0.5, which carries the same code.

🤖 Generated with Claude Code

…tive

OverworldState:timeOfDay() compared the hooked period with the raw clock
period instead of the period last reported. A world.tod hook that returns a
different period than the clock (e.g. EVENING while the clock says DAY)
therefore re-emitted world.tod_changed on every call, i.e. every frame.
Compare with self.tod, as the unhooked path already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant