Test out an optional render callback
This commit is contained in:
parent
67359073ca
commit
200968a2ab
4 changed files with 77 additions and 18 deletions
35
src/rcore.c
35
src/rcore.c
|
|
@ -318,6 +318,8 @@ typedef struct CoreData {
|
|||
char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW)
|
||||
unsigned int dropFileCount; // Count dropped files strings
|
||||
|
||||
bool(*updateCallback)(void); // Optional user defined callback to draw a frame
|
||||
|
||||
} Window;
|
||||
struct {
|
||||
const char *basePath; // Base path for data storage
|
||||
|
|
@ -737,6 +739,39 @@ void CloseWindow(void)
|
|||
TRACELOG(LOG_INFO, "Window closed successfully");
|
||||
}
|
||||
|
||||
static bool RunLoop = false;
|
||||
|
||||
void ProcessSingleFrame(void)
|
||||
{
|
||||
BeginDrawing();
|
||||
RunLoop = CORE.Window.updateCallback();
|
||||
EndDrawing();
|
||||
|
||||
#if defined(SUPPORT_CUSTOM_FRAME_CONTROL)
|
||||
SwapBuffers();
|
||||
PollInputEvents();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
void RunGameLoop(bool(*processFrame)(void))
|
||||
{
|
||||
RunLoop = true;
|
||||
CORE.Window.updateCallback = processFrame;
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(ProcessSingleFrame, 0, 1);
|
||||
#else
|
||||
while (RunLoop)
|
||||
{
|
||||
ProcessSingleFrame();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Check if window has been initialized successfully
|
||||
bool IsWindowReady(void)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue