#Help with refactored Game Loop

2 messages · Page 1 of 1 (latest)

topaz pine
#

Hey so I was following this guide on how to make a frame independent game loop, but it made my game loop complex enough to warrant it's own file, pretty much I made a new file and have the game loop logic stored in there and I can start the game loop by passing in some functions to it:

void GameLoop::start(
        double update_rate_hz,
        const std::function<void(double)>& fixed_timestep_update_func,
        const std::function<void()>& non_rate_limited_update_func,
        const std::function<int()>& termination_condition_func
        ) {

(you can think of fixed_timestep_update_func as your physics update call, non_rate_limited_updated_func your render and termination_condition_func as the condition to the while/game loop stopping)

In my main file, I am trying to avoid using global state and I'm just passing things in to certain functions that need them. For example in the past I had

void render(Character character, Model map, Hud hud) { ... }

But due to this refactor I had to make those 3 parameters global because my game loop forces it's signature to be const std::function<void()>& non_rate_limited_update_func and it had to be like this because the game loop doesn't have access to character, map, hud because I wanted that not to be of it's concern.

If I want to not have globals how would I get myself out of this pickle?

bleak plinthBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.