Fixed Tick Rate Timer - #2102
Open
jknightdoeswork wants to merge 8 commits into
Open
Conversation
… by and not reset the system repeatedly.
jknightdoeswork
commented
May 16, 2026
| } | ||
| ecs_entity_t old_system = flecs_stage_set_system(stage, system); | ||
| ecs_entity_t interrupted_by = 0; | ||
| for (uint32_t i = 0; i < num_ticks; i++) { |
Author
There was a problem hiding this comment.
The difference here is that the system is called in a loop, once per num_ticks.
jknightdoeswork
commented
May 16, 2026
| action(&qit); | ||
| ecs_iter_fini(&qit); | ||
| } | ||
| interrupted_by = it->interrupted_by; |
Author
There was a problem hiding this comment.
The most recent interrupted_by is returned - not sure if this is precisely the intent of interrupted by.
jknightdoeswork
commented
May 16, 2026
|
|
||
| if (timer[i].single_shot) { | ||
| timer[i].active = false; | ||
| if (timer[i].fixed_interval) { |
Author
There was a problem hiding this comment.
if fixed_interval is false, the semantics are exactly the same as before.
jknightdoeswork
commented
May 16, 2026
| system_data->tick_source = timer; | ||
| } | ||
|
|
||
| error: |
Author
There was a problem hiding this comment.
Full disclosure: I directly copy'd this error label pattern without precisely tracking where the error can be jumped from. I will review this personally more precisely before merging but requesting comment.
jknightdoeswork
commented
May 16, 2026
| if (system_data) { | ||
| system_data->tick_source = timer; | ||
| } | ||
| error: |
Author
There was a problem hiding this comment.
See above regarding not precisely understanding this error pattern.
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.
Adds a new set of methods allowing a 'fixed interval' timer to be created and managed.
Core new method is
This PR adjusts tick sources to be able to tick multiple times per pipeline run with a fixed delta time.
Addresses this issue.
I think this should improve the ergonomics of defining a core game loop that requires parts of the pipeline to run at a fixed interval.
I think this test demonstrates the core difference:
Looking for discussion on this approach.
My understanding of the built in timer mechanism is that if you use it, you expose yourself to perhaps unexpected behavior if you progress a pipeline with a longer duration than 2.0*timer_interval. There is no built in mechanism from what I can tell in flecs that allows a system to be gaurenteed to be called with a fixed delta time.
This PR additively allows this key concept in a simulation loop to be expressed elegantly using the built in flecs pipeline and timers APIs.
My instinct is that this should be the default mechanics of timers, but this is written to be backwards compatible, and does not change timers or systems at all unless the new fixed_interval set of APIs are used.
Let me know if I'm missing something or my understanding is incorrect!
Thanks for the awesome library!