Let the platform handle the game loop in case it has some existing callback method (like web does)

This commit is contained in:
Jeffery Myers 2026-07-03 11:08:34 -07:00
commit f95bd9d997
10 changed files with 105 additions and 16 deletions

View file

@ -1603,4 +1603,15 @@ static int android_close(void *cookie)
return 0;
}
extern void ProcessSingleFrame();
void PlatformRunGameLoop()
{
while (CORE.Window.updateCallback != NULL)
{
ProcessSingleFrame();
}
}
// EOF

View file

@ -2249,4 +2249,22 @@ static void JoystickCallback(int jid, int event)
# define WIN32_CLIPBOARD_IMPLEMENTATION
# include "../external/win32_clipboard.h"
#endif
extern void ProcessSingleFrame();
#if defined(PLATFORM_WEB)
#include <emscripten.h>
#endif
void PlatformRunGameLoop()
{
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(ProcessSingleFrame, 0, 1);
#else
while (CORE.Window.updateCallback != NULL)
{
ProcessSingleFrame();
}
#endif
}
// EOF

View file

@ -2100,3 +2100,14 @@ double GetTimeSeconds(void)
return currentTime;
}
extern void ProcessSingleFrame();
void PlatformRunGameLoop()
{
while (CORE.Window.updateCallback != NULL)
{
ProcessSingleFrame();
}
}

View file

@ -2312,3 +2312,13 @@ static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
for (int i = CORE.Input.Touch.pointCount; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentTouchState[i] = 0;
}
extern void ProcessSingleFrame();
void PlatformRunGameLoop()
{
while (CORE.Window.updateCallback != NULL)
{
ProcessSingleFrame();
}
}

View file

@ -2275,3 +2275,14 @@ static bool IsWglExtensionAvailable(HDC hdc, const char *extension)
return result;
}
extern void ProcessSingleFrame();
void PlatformRunGameLoop()
{
while (CORE.Window.updateCallback != NULL)
{
ProcessSingleFrame();
}
}

View file

@ -2732,4 +2732,15 @@ static void SetupFramebuffer(int width, int height)
}
}
extern void ProcessSingleFrame();
void PlatformRunGameLoop()
{
while (CORE.Window.updateCallback != NULL)
{
ProcessSingleFrame();
}
}
// EOF

View file

@ -592,4 +592,15 @@ static int kbhit(void)
}
#endif
extern void ProcessSingleFrame();
void PlatformRunGameLoop()
{
while (CORE.Window.updateCallback != NULL)
{
ProcessSingleFrame();
}
}
// EOF

View file

@ -532,4 +532,14 @@ void ClosePlatform(void)
// TODO: De-initialize graphics, inputs and more
}
extern void ProcessSingleFrame();
void PlatformRunGameLoop()
{
while (CORE.Window.updateCallback != NULL)
{
ProcessSingleFrame();
}
}
// EOF

View file

@ -1946,4 +1946,13 @@ static EM_BOOL EmscriptenVisibilityChangeCallback(int eventType, const Emscripte
}
//-------------------------------------------------------------------------------------------------------
void void ProcessSingleFrame();
void RunGameLoop(bool(*processFrame)(void))
{
emscripten_set_main_loop(ProcessSingleFrame, 0, 1);
}
// EOF

View file

@ -739,8 +739,6 @@ void CloseWindow(void)
TRACELOG(LOG_INFO, "Window closed successfully");
}
static bool RunLoop = false;
void ProcessSingleFrame(void)
{
// if the dirty callback rendered this frame, don't double render, skip it until the next frame
@ -751,7 +749,7 @@ void ProcessSingleFrame(void)
}
BeginDrawing();
RunLoop = CORE.Window.updateCallback();
if (!CORE.Window.updateCallback()) CORE.Window.updateCallback = NULL;
EndDrawing();
#if SUPPORT_CUSTOM_FRAME_CONTROL
@ -760,23 +758,12 @@ void ProcessSingleFrame(void)
#endif
}
#if defined(PLATFORM_WEB)
#include <emscripten.h>
#endif
void PlatformRunGameLoop();
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
PlatformRunGameLoop();
}
// Check if window has been initialized successfully