summaryrefslogtreecommitdiff
path: root/sources/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'sources/main.c')
-rw-r--r--sources/main.c56
1 files changed, 41 insertions, 15 deletions
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 <emscripten.h>
+#include <emscripten/html5.h>
+#endif
+
#include "raylib.h"
#include "text.h"
#include "s7.h"
@@ -6,11 +11,36 @@
#include <stdio.h>
#include <stdlib.h>
+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;
}