diff --git a/.gitignore b/.gitignore index 62ba73d..ed09431 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *~ .idea/ +build-web/ cmake-build-debug/ cmake-build-release/ tiled/PixelDefense.tiled-session diff --git a/CMakeLists.txt b/CMakeLists.txt index ff54160..f2c6eb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,3 +30,8 @@ add_executable(PixelDefense target_link_libraries(PixelDefense LINK_PRIVATE Breeze) +if (EMSCRIPTEN) + set_target_properties(PixelDefense + PROPERTIES SUFFIX ".html" + LINK_FLAGS " --bind -s WASM=1 -s STACK_SIZE=512kb -s ASSERTIONS=2 -s MIN_WEBGL_VERSION=1 --preload-file ../assets -g2 -gseparate-dwarf -gsource-map -s USE_GLFW=3") +endif() diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 2b9350d..a0f98b8 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -3,7 +3,11 @@ project(Breeze C) set(CMAKE_C_STANDARD 11) -add_compile_options(-Wall -Wextra -Wpedantic -std=c11) +if (EMSCRIPTEN) + add_compile_options(-Wall -Wextra -Wpedantic) +else() + add_compile_options(-Wall -Wextra -Wpedantic -std=c11) +endif() add_compile_definitions(DEBUG_MODE) @@ -92,6 +96,6 @@ file(COPY ${BreezeHeaders} DESTINATION "include") if (${BUILD_BREEZE_TESTS}) MESSAGE(STATUS "Building breeze tests is enabled") - add_subdirectory(tests) + #add_subdirectory(tests) endif() diff --git a/engine/breeze/game.h b/engine/breeze/game.h index 4299b90..2373898 100644 --- a/engine/breeze/game.h +++ b/engine/breeze/game.h @@ -28,6 +28,10 @@ extern bool bzMain(BzAppDesc *appDesc, int argc, const char **argv); #ifdef BZ_ENTRYPOINT #include +#ifdef PLATFORM_WEB +#include +#endif + // https://www.raylib.com/examples/core/loader.html?name=core_custom_logging static void bzRaylibLogger(int msgType, const char *text, va_list args) { BzLoggerLevel level = BZ_LOG_TRACE; @@ -57,6 +61,29 @@ static void bzRaylibLogger(int msgType, const char *text, va_list args) { bzLoggerOnlyLogV(level, text, args); } +static BzAppDesc appDesc = {0, 0}; + +static void bzGameLoopTick() { + float dt = GetFrameTime(); + if (appDesc.update) + appDesc.update(dt, appDesc.userData); + + //if (ECS) + // ecs_progress(ECS, dt); + + BeginDrawing(); + if (appDesc.render) + appDesc.render(dt, appDesc.userData); + + if (appDesc.imguiRender) { + rlImGuiBegin(); + appDesc.imguiRender(dt, appDesc.userData); + rlImGuiEnd(); + } + EndDrawing(); +} + + int main(int argc, const char **argv) { if (!bzLoggerInit()) return 1; @@ -65,7 +92,7 @@ int main(int argc, const char **argv) { SetTraceLogCallback(bzRaylibLogger); - BzAppDesc appDesc = { + appDesc = (BzAppDesc){ 1280, 720, "Breeze Engine", @@ -94,24 +121,11 @@ int main(int argc, const char **argv) { return 1; } +#ifdef PLATFORM_WEB + emscripten_set_main_loop(bzGameLoopTick, 0, 1); +#else while (!WindowShouldClose()) { - float dt = GetFrameTime(); - if (appDesc.update) - appDesc.update(dt, appDesc.userData); - - //if (ECS) - // ecs_progress(ECS, dt); - - BeginDrawing(); - if (appDesc.render) - appDesc.render(dt, appDesc.userData); - - if (appDesc.imguiRender) { - rlImGuiBegin(); - appDesc.imguiRender(dt, appDesc.userData); - rlImGuiEnd(); - } - EndDrawing(); + bzGameLoopTick(); } // User deinitialize @@ -124,6 +138,7 @@ int main(int argc, const char **argv) { CloseWindow(); bzLoggerDeinit(); +#endif return 0; }