Repository navigation
Fix world.tod_changed firing every frame while a world.tod hook is active - #408
Closed
devilmaker20 wants to merge 1 commit into
Closed
devilmaker20 wants to merge 1 commit into
devilmaker20 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Nuno · project thread
Problem
OverworldState:timeOfDay()emitsworld.tod_changedon every call, which means every frame, whenever aworld.todhook 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,EVENINGwhile the clock saysDAYmakesnextTod ~= todtrue 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
🤖 Generated with Claude Code