Ok, I seem to have found a way to use while loops inside the app::Loop() function (yes with sync() ) but, there are a few trade-offs. The first being that there's a condition you must include in the while loops and the second is that I haven't looked into making this cross platform (but in theory, it should be achievable).
Here's how it's done. Towards the end of the core.cpp in the int APIENTRY _tWinMain() function look for this:
// message pump
MSG msg;
bool bExitLoop;
while ( !bExitLoop )
{
if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
if ( msg.message == WM_QUIT ) bExitLoop = true;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// call app each frame
try
{
App.Loop();
}
catch(...)
{
uString err = agk::GetLastError();
err.Prepend( "Uncaught exception: \n\n" );
MessageBox( NULL, err.GetStr(), "Error", 0 );
}
}
}
Make bExitLoop a global (move the declaration to the top of the core.cpp and place it after the namespace. Remember to remove its
local declaration). Then study this (template.cpp):
// Includes, namespace and prototypes
#include "template.h"
using namespace AGK;
app App;
bool update(); // returns true if user tries to exit, false otherwise
extern bool bExitLoop; // access the global which runs the loop which calls app::Loop()
// Begin app, called once at the start
void app::Begin( void )
{
}
// Main loop, called every frame
void app::Loop ( void )
{
while(!update()) {
agk::Print("Hello World");
agk::Sync();
}
// exit upon a click
//if(agk::GetPointerPressed()) PostQuitMessage(0);
agk::Sync();
}
// Called when the app ends
void app::End ( void )
{
}
// returns true if user tries to exit, false otherwise
bool update() {
MSG msg;
bool quit = false;
if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
if ( msg.message == WM_QUIT ) {
bExitLoop = true;
quit = true;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return quit;
}
The update() must be a condition of the while loop (so it can exit if necessary and run the message pump).
Edit I should say that you can copy the update() function straight into your program.