#include <akgltest.h>

SDL_AppResult SDL_AppIterate(void *appstate)
{
    //SDL_FRect dest;
    //b2Vec2 position;

    PREPARE_ERROR(e);

    ATTEMPT {
	CATCH(e, akgl_game_state_lock());
	if ( AKGL_BITMASK_HAS(game.state.flags, AKGLTEST_STATE_QUIT) ) {
	    return SDL_APP_FAILURE;
	} else if ( AKGL_BITMASK_HAS(game.state.flags, AKGLTEST_STATE_RUNNING) ) {
	    CATCH(e, akgltest_iterate_running());
	} else if ( AKGL_BITMASK_HAS(game.state.flags, AKGLTEST_STATE_WAITFORINPUT) ) {
	    CATCH(e, akgltest_iterate_waitforinput());
	} else if ( AKGL_BITMASK_HAS(game.state.flags, AKGLTEST_STATE_MAPMENU) ) {
	    CATCH(e, akgltest_iterate_mapmenu());
	} 
    } CLEANUP {
	IGNORE(akgl_game_state_unlock());
    } PROCESS(e) {
    } HANDLE_DEFAULT(e) {
	LOG_ERROR(e);
	return SDL_APP_FAILURE;
    } FINISH_NORETURN(e);
    return SDL_APP_CONTINUE;
}
