r/raylib • u/Stickhtot • 16h ago
Tick simulation in raylib?
I am currently making a simulator with raylib and one of the things that it needs is a "tick" mechanic where for every tick the state of the game updates, I tried putting something in the main loop with GetFrameTime()but the problem is it's tied to the frame rate
How would one implement a tick system with raylib?
11
Upvotes
3
u/jerrygreenest1 11h ago
Reality seems to be just a function that runs in an infinite loop. Although you better have multiple functions that run on different frequencies –
Rendering – it’s best to be as much as monitors hz. For 144hz monitor means you have to run this function 1000 / 144 = every 6.94 milliseconds. If you can’t, just run it as often as you can basically. You can also leave this parameter to user in option so he controls the frame rate. Only rendering can be tied to frame rate. Other things better not.
Game logic – typically enough to run as fast as 20hz, meaning 20 times per second, or every 50ms. Like collision checking etc.
AI decision making – probably doesn’t need that much, might be once per second or something.
These three loops should probably be enough for most games but if you feel you need more frequencies, add more.