From 5f744720559029fed1c267cdb3a08fa17d6047ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pons?= Date: Tue, 25 Mar 2025 17:18:06 +0100 Subject: [PATCH] Add flecs --- .vscode/c_cpp_properties.json | 11 ++++++++--- .vscode/settings.json | 6 +++++- build.bat | 2 +- debug.bat | 2 +- src/main.c | 9 +++++++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 30f3982..03e34c7 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -20,7 +20,8 @@ "name": "Emscripten", "includePath": [ "${workspaceFolder}/../sokol", - "${workspaceFolder}/../sokol_gp" + "${workspaceFolder}/../sokol_gp", + "${workspaceFolder}/../flecs/distr" ], "defines": [ "_DEBUG", @@ -32,7 +33,6 @@ "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "windows-clang-x64", - "compilerPathInCppPropertiesJson": "C:\\Users\\c.pons\\Documents\\Perso\\Git\\emsdk\\upstream\\bin\\clang.exe", "mergeConfigurations": false, "browse": { "path": [ @@ -47,7 +47,12 @@ "-sASSERTIONS", "-sWASM_BIGINT", "-pthread", - "-sFILESYSTEM=0" + "-sFILESYSTEM=0", + "-sALLOW_MEMORY_GROWTH=1", + "-sSTACK_SIZE=1mb", + "-sEXPORTED_RUNTIME_METHODS=cwrap", + "-sMODULARIZE=1", + "-sEXPORT_NAME=\"flecs_tests\"" ] } ], diff --git a/.vscode/settings.json b/.vscode/settings.json index 1ca1277..63e89fd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,10 @@ "webgpu.h": "c", "html5.h": "c", "emscripten.h": "c", - "stddef.h": "c" + "stddef.h": "c", + "flecs.h": "c", + "stdlib.h": "c", + "math.h": "c", + "stdio.h": "c" } } \ No newline at end of file diff --git a/build.bat b/build.bat index 417bbea..38b6523 100644 --- a/build.bat +++ b/build.bat @@ -1 +1 @@ -emcc -O3 src/main.c -o app.html -sUSE_WEBGL2 -sWASM_BIGINT -pthread -I../sokol -I../sokol_gp --shell-file=shell.html -sFILESYSTEM=0 \ No newline at end of file +emcc -O3 src/main.c -o app.html -sUSE_WEBGL2 -sWASM_BIGINT -pthread -I../sokol -I../sokol_gp -I../flecs/distr --shell-file=shell.html -sFILESYSTEM=0 \ No newline at end of file diff --git a/debug.bat b/debug.bat index f700cc6..004b571 100644 --- a/debug.bat +++ b/debug.bat @@ -1 +1 @@ -emcc src/main.c -o app.html -sUSE_WEBGL2 -sASSERTIONS -sWASM_BIGINT -pthread -I../sokol -I../sokol_gp --shell-file=shell.html -sFILESYSTEM=0 -g \ No newline at end of file +emcc src/main.c -o app.html -sUSE_WEBGL2 -sASSERTIONS -sWASM_BIGINT -pthread -I../sokol -I../sokol_gp -I../flecs/distr --shell-file=shell.html -sFILESYSTEM=0 -g \ No newline at end of file diff --git a/src/main.c b/src/main.c index 3aa9996..438eedf 100644 --- a/src/main.c +++ b/src/main.c @@ -3,15 +3,20 @@ // Includes Sokol GFX, Sokol GP and Sokol APP, doing all implementations. #define SOKOL_IMPL #define SOKOL_GLES3 +#define FLECS_CUSTOM_BUILD #include "sokol_gfx.h" #include "sokol_gp.h" #include "sokol_app.h" #include "sokol_glue.h" +#include "flecs.c" + #include // for fprintf() #include // for exit() #include // for sinf() and cosf() +ecs_world_t *world; + // Called on every frame of the application. static void frame(void) { // Get current window size. @@ -68,10 +73,14 @@ static void init(void) { fprintf(stderr, "Failed to create Sokol GP context: %s\n", sgp_get_error_message(sgp_get_last_error())); exit(-1); } + + world = ecs_init(); } // Called when the application is shutting down. static void cleanup(void) { + ecs_fini(world); + // Cleanup Sokol GP and Sokol GFX resources. sgp_shutdown(); sg_shutdown();