From 192d71918917ad12063ca6682372dfbc34d06d2c Mon Sep 17 00:00:00 2001 From: Henrique Alves Date: Wed, 24 Apr 2024 09:52:34 +0300 Subject: Testing web export (crashing on s7_init) --- sources/main.c | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) (limited to 'sources/main.c') diff --git a/sources/main.c b/sources/main.c index 3ee655a..ee07e0b 100644 --- a/sources/main.c +++ b/sources/main.c @@ -1,3 +1,8 @@ +#ifdef __EMSCRIPTEN__ +#include +#include +#endif + #include "raylib.h" #include "text.h" #include "s7.h" @@ -6,11 +11,36 @@ #include #include +s7_scheme *s7; +s7_pointer s7_update_fn; +s7_pointer s7_draw_fn; + +#ifdef __EMSCRIPTEN__ +EM_BOOL main_loop_web(double time, void* userData) { + s7_call(s7, s7_update_fn, s7_list(s7, 0)); + + BeginDrawing(); + ClearBackground(RAYWHITE); + s7_call(s7, s7_draw_fn, s7_list(s7, 0)); + EndDrawing(); + return EM_TRUE; +} +#else +void main_loop(){ + s7_call(s7, s7_update_fn, s7_list(s7, 0)); + + BeginDrawing(); + ClearBackground(RAYWHITE); + s7_call(s7, s7_draw_fn, s7_list(s7, 0)); + EndDrawing(); +} +#endif + int main(int argc, char* argv[]) { - s7_scheme *s7 = s7_init(); + s7 = s7_init(); - rl_text_define_methods(s7); + // rl_text_define_methods(s7); const int screen_width = 800; const int screen_height = 600; @@ -21,22 +51,18 @@ int main(int argc, char* argv[]) { char filename[] = SCRIPTS_PATH"main.scm"; s7_load(s7, filename); - s7_pointer s7_update_fn = s7_name_to_value(s7, "update"); - s7_pointer s7_draw_fn = s7_name_to_value(s7, "draw"); - - while (!WindowShouldClose()) - { - s7_call(s7, s7_update_fn, s7_list(s7, 0)); - - BeginDrawing(); - ClearBackground(RAYWHITE); - s7_call(s7, s7_draw_fn, s7_list(s7, 0)); - EndDrawing(); + s7_update_fn = s7_name_to_value(s7, "update"); + s7_draw_fn = s7_name_to_value(s7, "draw"); - s7_eval_c_string(s7, "(display 'noice')"); - } +#ifdef __EMSCRIPTEN__ + emscripten_request_animation_frame_loop(main_loop_web, 0); +#else + while (!WindowShouldClose()) { + main_loop(); + } CloseWindow(); +#endif return 0; } -- cgit v1.2.3