From 7703f2a74122c771070f19259fc40eb2167df9ac Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Fri, 21 Jun 2024 00:05:07 +0100 Subject: Refactor code to use emscripten_set_main_loop Supposed to give better perf, better to leave frame control to the browser. --- main.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 2b1677c..9d65338 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,10 @@ #include "raylib.h" #include +#ifdef __EMSCRIPTEN__ +#include +#endif + #define RAYGUI_IMPLEMENTATION #include "raygui.h" @@ -112,6 +116,24 @@ void DrawOutput(); void HandleDroppedFiles(); +void UpdateDrawFrame() +{ + HandleDroppedFiles(); + + BeginDrawing(); + ClearBackground(RAYWHITE); + + DrawElementBorders(); + SetupDifference(); + DrawUI(); + ResolveMouseState(); + DrawCodeDisplay(); + CheckDifference(); + DrawOutput(); + + EndDrawing(); +} + int main() { InitWindow(screenWidth, screenHeight, "DrawTexturePro Example"); @@ -139,24 +161,14 @@ int main() elementRender.height - 20 ); - +#ifdef __EMSCRIPTEN__ + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else while (!WindowShouldClose()) { - HandleDroppedFiles(); - - BeginDrawing(); - ClearBackground(RAYWHITE); - - DrawElementBorders(); - SetupDifference(); - DrawUI(); - ResolveMouseState(); - DrawCodeDisplay(); - CheckDifference(); - DrawOutput(); - - EndDrawing(); + UpdateDrawFrame(); } +#endif CloseWindow(); return 0; -- cgit v1.2.3