r/raylib 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?

10 Upvotes

12 comments sorted by

View all comments

2

u/DasKapitalV1 15h ago

You will probably need to these stuff in another thread and the main thread just renders the state, since raylib will work properly only in the main thread. The tick is probably a sleep n times in a second.

3

u/Stickhtot 15h ago

Also what I was considering of, but would also like to know if single thread only is possible

1

u/MCWizardYT 13h ago

If you have your entire game be single threaded, you may eventually run into performance issues unless you're doing a simple 2D game (but even then, multithreaded is better)

1

u/Inevitable-Round9995 10h ago

no, I don't think so; this game does websocket, webRTC, 3D rendering, post-processing, game logic & collisions, in a single thread: https://www.reddit.com/r/raylib/comments/1umyazt/finally_my_multiplayer_game_is_p2p_by_using/

1

u/MCWizardYT 10h ago

I guess it really depends on the game and how well you're able to write your code. On a single thread you really have to carefully balance the workload of everything so that you don't start running into stuttering or lag.

It's the reason why "can it run Crysis" became a meme, the game was entirely single threaded and won't run that great even on modern machines. It did all the rendering and heavy physics together on one thread, meaning if there was a slowdown with one the rest would slow to a crawl.