Messy? Too big?
It is set up to deal with multiple compiler environments. The code is designed to be used on all platforms without having to edit the files for each. That is what the '#ifdef' bits are for. (FYI, I've been doing C++ coding for more than 20 years. I believe in heavy commenting. You never know when you have to go back to something you haven't looked at in years. Or have someone in the future have to deal with your code.)
This was an example of how to use state machines to deal with the the Tier 2 handling of the Synch() command. In Tier 2, when you call 'agk::Sync()', it updates displays and physics but not user and device inputs. Those are updated once per app::Loop() execution by the AppGameKit engine.
In Tier 1, you can do something like this and actually get to the print statement:
while GetPointerPressed() = 0
rem do something
endwhile
print "something"
In Tier 2, this leaves your app completely hung, you will never get to the Print statement:
while (agk::GetPointerPressed() == 0)
{
// do something
}
agk::Print('something');
The important bit for closing the app on demand is this method:
void app::closeThisApp()
{
// completely exit the app
#ifdef AGKWINDOWS
PostQuitMessage(0);
#endif
#ifdef AGKIOS
// forcing a quit in iOS is against recommended guidelines - use HOME button
// the exit button is disabled on AGKIOS builds
// but if you want to do so, this is the code
agk::MasterReset();
exit(0);
#endif
#ifdef IDE_ANDROID
// similar to iOS, an exit button should not be done
// but if you want to do so, this is the code
agk::MasterReset();
exit(0);
#endif
#ifdef IDE_MAC
glfwCloseWindow();
#endif
}
Add this to your template.h file:
private:
void closeThisApp();
Then, you call 'closeThisApp()' somewhere in your app::Loop() when you are ready to close the application.
The Windows 'PostQuitMessage(0)' version is the event that is captured in Core.cpp when it does this check '(msg.message == WM_QUIT)'.
In Windows, when you close an application by clicking on the 'X' in the upper right of the window, that is the message being intercepted in Core.cpp.
My code example shows how to generate that message to be caught by the AppGameKit engine. This then lets the engine do whatever it needs to clean up and close the application.
If you think that you are only ever going to code your app for the Windows program, skip adding the stuff I showed and just call 'PostQuitMessage(0)' when you want it to end. My example (and this is how I do it in my apps) is set up for dealing with compiling the same code files in the multiple environments supported by AGK.
Cheers,
Ancient Lady