I am writing a small game on my phone in SDL2. In main I have a while loop and basic game control conditions which are bools. I pass 'initialise', 'update', 'quit' and the 'renderer' to a game function by reference that deals with the game logic. Now it's getting more complicated I want to separate certain logic to outside of game, and to do that I have to pass the references from main, to game, to more functions outside of game. Main would pass to game, game would pass to func2, and possibly func2 needs to pass to func3.
Do the C++ standards/specification limit the use of pass by reference? You could have a chain of 10+ functions passing down quit, update, etc.
//
// extra functions here
// which break up game
// each need quit, initialise, update and renderer
// so I pass by reference
//
// void func2(&rend, &quit, &update, &initialise)
void game(SDL_Renderer *rend, bool &initialise, bool &quit, bool &update)
{
static Table t{};
if (initialise)
{
// setup game
func2(rend, initialise, quit, update);
}
if(update)
{
// refresh screen
}
while (PollTouchEvent)
{
// touching screen
// can quit here
}
}
int main(int argc, char *argv[])
{
// initialise SDL
// ...
// game stuff
bool quit = false;
bool update = true;
bool initialise = true;
while (!quit)
{
game(renderer, initialise, quit, update);
}
// quit SDL
return 0;
}