From 45422940ade9b303a1ca0b07e3bd02421f494f12 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Wed, 6 Mar 2024 22:47:02 +0100 Subject: [PATCH] Update for web --- src/Tree.cpp | 2 +- src/main.cpp | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Tree.cpp b/src/Tree.cpp index d47d952..e1b147f 100644 --- a/src/Tree.cpp +++ b/src/Tree.cpp @@ -12,7 +12,7 @@ Tree::Tree(int size) start.x = size / 2; start.y = size; - branches.assign(11, {0}); + branches.assign(11, {}); } Tree::~Tree() diff --git a/src/main.cpp b/src/main.cpp index 2818fcb..bf2d2df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,20 @@ #include "raylib.h" #include "App.hpp" +#if defined(PLATFORM_WEB) +#include +#endif + +static App app; + +void UpdateDrawFrame() +{ + app.update(); + BeginDrawing(); + app.draw(); + EndDrawing(); +} + int main(void) { char name[] = "treender"; @@ -14,17 +28,19 @@ int main(void) #else InitWindow(screenWidth, screenHeight, name); #endif - SetTargetFPS(60); - App app; app.init(screenWidth, screenHeight); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + SetTargetFPS(60); while (!WindowShouldClose()) { - app.update(); - BeginDrawing(); - app.draw(); - EndDrawing(); + UpdateDrawFrame(); } +#endif + app.deinit(); CloseWindow();