diff options
author | Henrique Alves <henrique.alves@itsjungle.xyz> | 2024-04-24 09:52:34 +0300 |
---|---|---|
committer | Henrique Alves <henrique.alves@itsjungle.xyz> | 2024-04-24 09:52:34 +0300 |
commit | 192d71918917ad12063ca6682372dfbc34d06d2c (patch) | |
tree | 209bc935af3af87dfd5196e4fdb2816c4e0c0912 | |
parent | 150738de9fb42159f6b60bc5cf817d99e6718988 (diff) | |
download | gamejam-slgj-2024-192d71918917ad12063ca6682372dfbc34d06d2c.tar.gz gamejam-slgj-2024-192d71918917ad12063ca6682372dfbc34d06d2c.tar.bz2 gamejam-slgj-2024-192d71918917ad12063ca6682372dfbc34d06d2c.zip |
Testing web export (crashing on s7_init)
-rw-r--r-- | CMakeLists.txt | 19 | ||||
-rw-r--r-- | sources/main.c | 56 |
2 files changed, 56 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f649d60..2933807 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,11 +37,22 @@ if (APPLE) target_link_libraries(${PROJECT_NAME} PRIVATE "-framework OpenGL") endif() +# Web Configurations +if (${PLATFORM} STREQUAL "Web") + # Tell Emscripten to build an example.html file. + set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html") +endif() + +if (EMSCRIPTEN) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s GL_ENABLE_GET_PROC_ADDRESS=1") + set(CMAKE_EXECUTABLE_SUFFIX ".html") # This line is used to set your executable to build with the emscripten html template so that you can directly open it. +endif () + # Setting ASSETS_PATH target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="./assets/") target_compile_definitions(${PROJECT_NAME} PUBLIC SCRIPTS_PATH="./scripts/") -add_custom_command( - TARGET ${CMAKE_PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/${CMAKE_PROJECT_NAME} ${CMAKE_SOURCE_DIR}/${CMAKE_PROJECT_NAME} -) +# add_custom_command( +# TARGET ${CMAKE_PROJECT_NAME} POST_BUILD +# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/${CMAKE_PROJECT_NAME} ${CMAKE_SOURCE_DIR}/${CMAKE_PROJECT_NAME} +# ) 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; } |