Add web support
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ extern bool bzMain(BzAppDesc *appDesc, int argc, const char **argv);
|
||||
#ifdef BZ_ENTRYPOINT
|
||||
#include <rlImGui.h>
|
||||
|
||||
#ifdef PLATFORM_WEB
|
||||
#include <emscripten/emscripten.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user