Handmade Hero»Forums»Code
17 posts
Day 030 - Initialize game_memory or game_state?
This is only a small question:

Going through my code I noticed that I have placed the bool32 IsInitialized flag in the game_state struct (handmade.h). So in our game update and render function I check:

1
2
3
4
5
6
7
    if(!GameState->IsInitialized)
    {
        GameState->PlayerX = 150;
        GameState->PlayerY = 150;

        GameState->IsInitialized = true;
    }

I noticed the original code has the flag in the game_memory struct (handmade_platform.h).

To me, it seems that it makes more sense to have the flag in the game_state struct, because it is only after we set some game_state members that we declare it initialized, but maybe I am wrong.

So, just a small question, but does it matter where this flag is placed, and if so what is the reasoning behind putting it there?
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Day 030 - Initialize game_memory or game_state?
Originally the reasoning was because the operating system layer wants to be able to set it back to "false" if it restarts things, but since we have now formally stated that OS-provided memory has to be cleared to zero, we could go ahead and move it into the game state without issue.

- Casey
17 posts
Day 030 - Initialize game_memory or game_state?
I got it. Thanks Casey.