diff options
author | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-12-23 00:19:19 -0700 |
---|---|---|
committer | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-12-23 00:19:19 -0700 |
commit | 2c046ef3dca9e128a801c7a92c3a3a63e01fdd98 (patch) | |
tree | da7261da961ba59ba8799f0aa441dbb47b22ed25 | |
parent | 670ef2efe90f94a950a4465ce029fb07d2a6ae73 (diff) |
Ready for web assembly
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/main.c | 23 |
2 files changed, 24 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 83edba2..b37f16b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,11 @@ set(C_STANDARD 99) set(C_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +if (EMSCRIPTEN) + set(CMAKE_C_FLAGS "${CMAKE_C_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 taht you can directly open it. +endif () + # Add source files. file(GLOB SRC_FILES src/*.c src/entities/*.c src/levels/*.c src/screens/*.c) @@ -1,13 +1,28 @@ #include "gameCommon.h" #include "game.h" +//#define PLATFORM_WEB + +#if defined(PLATFORM_WEB) + #include <emscripten/emscripten.h> +#endif + +Game game; + +void updateFrame() { + updateGame(&game); +} + int main(int argc, char ** argv) { - Game game; initGame(&game); - while (!WindowShouldClose()) { - updateGame(&game); - } +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(updateFrame, 0, 1); +#else + while (!WindowShouldClose()) { + updateFrame(); + } +#endif closeGame(&game); return 0; |