#ifndef RT_MAIN_LOOP_H
#define RT_MAIN_LOOP_H

#include "runtime/runtime.h"
#include "runtime/threading.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef void rt_main_loop_update_fn(unsigned int frame_id);
typedef void rt_main_loop_render_fn(unsigned int frame_id);

typedef struct {
    unsigned int u_frame_id;
    unsigned int r_frame_id;

    rt_semaphore update_proceed;
    rt_semaphore render_proceed;

    rt_thread *update_thread;
    rt_thread *render_thread;

    rt_main_loop_update_fn *GameUpdate;
    rt_main_loop_render_fn *GameRender;

    volatile int shutdown;
} rt_main_loop;

#ifndef RT_DONT_DEFINE_MAIN_LOOP_GLOBAL
/* The applications main-loop */
extern RT_DLLIMPORT rt_main_loop g_main_loop;
#endif

RT_DLLEXPORT rt_result rtInitMainLoop(rt_main_loop_update_fn *update_cb,
                                      rt_main_loop_render_fn *render_cb);

RT_DLLEXPORT void rtShutdownMainLoop(void);

#ifdef __cplusplus
}
#endif

#endif
