From 5e123d96b383c3df2e7b75e2ab75b32ad306beb6 Mon Sep 17 00:00:00 2001 From: Mergul Date: Thu, 9 Mar 2023 14:08:42 +0100 Subject: [PATCH 1/3] Add xmake --- .gitignore | 1 + tests/tests.d | 2 +- xmake.lua | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 xmake.lua diff --git a/.gitignore b/.gitignore index e0e6fff..595184e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ !.gitignore !codecov.yml !skeleton.html +!**/xmake.lua !**/meson.build !**/*.wrap !meson_options.txt diff --git a/tests/tests.d b/tests/tests.d index 164eb30..5205818 100644 --- a/tests/tests.d +++ b/tests/tests.d @@ -645,7 +645,7 @@ version (unittest) else: extern (C) int main() { - + version (D_BetterC)printf("BetterC\n"); void dispatch(EntityManager.JobGroup jobs) nothrow @nogc { foreach (job; jobs.jobs) diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..6e29477 --- /dev/null +++ b/xmake.lua @@ -0,0 +1,103 @@ +add_rules("mode.debug", "mode.release") + +option("betterC") + set_default(false) + if get_config("dc") == "gcc" then + add_dcflags("-fno-druntime") + else + add_dcflags("-betterC") + end + +target("bubel-ecs") + set_kind("static") + set_basename("BubelECS") + add_files("source/bubel/**.d") + add_includedirs("source", {public = true}) + set_options("betterC") + +target("tests") + set_kind("binary") + set_basename("BubelECSTests") + add_files("tests/*.d|tests.d") + add_includedirs(".", {public = true}) + set_options("betterC") + add_deps("bubel-ecs") + add_dcflags("-unittest") + +target("test") + set_kind("binary") + set_basename("BubelECSTest") + add_files("tests/tests.d") + add_includedirs(".", {public = true}) + set_options("betterC") + add_deps("bubel-ecs") + +-- +-- If you want to known more usage about xmake, please see https://xmake.io +-- +-- ## FAQ +-- +-- You can enter the project directory firstly before building project. +-- +-- $ cd projectdir +-- +-- 1. How to build project? +-- +-- $ xmake +-- +-- 2. How to configure project? +-- +-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] +-- +-- 3. Where is the build output directory? +-- +-- The default output directory is `./build` and you can configure the output directory. +-- +-- $ xmake f -o outputdir +-- $ xmake +-- +-- 4. How to run and debug target after building project? +-- +-- $ xmake run [targetname] +-- $ xmake run -d [targetname] +-- +-- 5. How to install target to the system directory or other output directory? +-- +-- $ xmake install +-- $ xmake install -o installdir +-- +-- 6. Add some frequently-used compilation flags in xmake.lua +-- +-- @code +-- -- add debug and release modes +-- add_rules("mode.debug", "mode.release") +-- +-- -- add macro defination +-- add_defines("NDEBUG", "_GNU_SOURCE=1") +-- +-- -- set warning all as error +-- set_warnings("all", "error") +-- +-- -- set language: c99, c++11 +-- set_languages("c99", "c++11") +-- +-- -- set optimization: none, faster, fastest, smallest +-- set_optimize("fastest") +-- +-- -- add include search directories +-- add_includedirs("/usr/include", "/usr/local/include") +-- +-- -- add link libraries and search directories +-- add_links("tbox") +-- add_linkdirs("/usr/local/lib", "/usr/lib") +-- +-- -- add system link libraries +-- add_syslinks("z", "pthread") +-- +-- -- add compilation and link flags +-- add_cxflags("-stdnolib", "-fno-strict-aliasing") +-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) +-- +-- @endcode +-- + From 3a3a9e0341dba0484765b9ab10e159958a47a8ca Mon Sep 17 00:00:00 2001 From: Mergul Date: Thu, 23 Mar 2023 22:31:20 +0100 Subject: [PATCH 2/3] Add @nogc UDA, fix some small issues, xmake changes -add @nogc to some functions where it was missing -fix compilation issue in mallocator -fix Meson build -some work on xmake build --- dub.json | 16 ++++++++-------- source/bubel/ecs/entity.d | 12 ++++++------ source/bubel/ecs/manager.d | 10 +++++----- source/bubel/ecs/std.d | 2 +- tests/meson.build | 6 +++--- xmake.lua | 19 ++++++++++++++++--- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/dub.json b/dub.json index 602117d..117c762 100755 --- a/dub.json +++ b/dub.json @@ -7,9 +7,9 @@ "description": "Dynamic Entity Component System", "copyright": "Copyright © 2018-2023, Michał Masiukiewicz, Dawid Masiukiewicz", "license": "BSD 3-clause", - "sourcePaths" : ["source\/"], + "sourcePaths" : ["source/"], "excludedSourceFiles":[ - "source\/ecs\/traits.d" + "source/ecs/traits.d" ], "configurations" : [ { @@ -21,7 +21,7 @@ "sourceFiles" : ["tests/tests.d"], "targetType" : "executable", "excludedSourceFiles":[ - "source\/win_dll.d" + "source/win_dll.d" ] }, { @@ -45,7 +45,7 @@ "sourcePaths": ["source/","tests/"], "mainSourceFile":"tests/runner.d", "excludedSourceFiles":[ - "source\/win_dll.d", + "source/win_dll.d", "tests/tests.d" ], "dflags": [ @@ -58,7 +58,7 @@ "sourcePaths": ["source/","tests/"], "mainSourceFile":"tests/runner.d", "excludedSourceFiles":[ - "source\/win_dll.d", + "source/win_dll.d", "tests/tests.d" ], "dflags": [ @@ -70,7 +70,7 @@ "name" : "library-betterC", "targetType" : "library", "excludedSourceFiles":[ - "source\/win_dll.d" + "source/win_dll.d" ], "dflags": [ "-betterC", @@ -101,7 +101,7 @@ "targetType" : "executable", "sourceFiles" : ["tests/tests.d"], "excludedSourceFiles":[ - "source\/win_dll.d" + "source/win_dll.d" ], "dflags": [ "-betterC" @@ -125,7 +125,7 @@ "sourcePaths": ["source/","tests/"], "mainSourceFile":"tests/runner.d", "excludedSourceFiles":[ - "source\/win_dll.d", + "source/win_dll.d", "tests/tests.d" ] } diff --git a/source/bubel/ecs/entity.d b/source/bubel/ecs/entity.d index 9b42c31..d6b4ef8 100644 --- a/source/bubel/ecs/entity.d +++ b/source/bubel/ecs/entity.d @@ -44,7 +44,7 @@ struct Entity return cast(T*)getComponent(becsID!T); } - void* getComponent(ushort component_id) const + void* getComponent(ushort component_id) const nothrow @nogc { EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this); EntityManager.EntityInfo* info = block.type_info; @@ -54,7 +54,7 @@ struct Entity return (cast(void*)block + info.deltas[component_id] + block.entityIndex(&this) * gEntityManager.components[component_id].size); } - bool hasComponent(ushort component_id) const + bool hasComponent(ushort component_id) const nothrow @nogc { EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this); EntityManager.EntityInfo* info = block.type_info; @@ -62,7 +62,7 @@ struct Entity return true; } - EntityMeta getMeta() const + EntityMeta getMeta() const nothrow @nogc { EntityMeta meta; meta.block = gEntityManager.getMetaData(&this); @@ -85,7 +85,7 @@ struct EntityMeta return cast(T*)getComponent(becsID!T); } - void* getComponent(ushort component_id) const + void* getComponent(ushort component_id) const nothrow @nogc { const (EntityManager.EntityInfo)* info = block.type_info; @@ -95,7 +95,7 @@ struct EntityMeta return (cast(void*)block + info.deltas[component_id] + index * gEntityManager.components[component_id].size); } - bool hasComponent(ushort component_id) const + bool hasComponent(ushort component_id) const nothrow @nogc { const EntityManager.EntityInfo* info = block.type_info; if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false; @@ -124,7 +124,7 @@ export struct EntityTemplate /************************************************************************************************************************ Get specified component. If component doesn't exist function return null. Returned pointer is valid during EntityTemplate lifetime. */ - T* getComponent(T)() nothrow @nogc + T* getComponent(T)() { if(becsID!T >= info.tmpl_deltas.length || info.tmpl_deltas[becsID!T] == ushort.max)return null; return cast(T*)(entity_data.ptr + info.tmpl_deltas[becsID!T]); diff --git a/source/bubel/ecs/manager.d b/source/bubel/ecs/manager.d index 801068d..5c343e6 100644 --- a/source/bubel/ecs/manager.d +++ b/source/bubel/ecs/manager.d @@ -2502,7 +2502,7 @@ export struct EntityManager *Params: *id = ID of entity to be copyied. */ - export Entity* addEntityCopy(EntityID id) + export Entity* addEntityCopy(EntityID id) nothrow @nogc { Entity* entity = getEntity(id); EntitiesBlock* block = getMetaData(entity); @@ -2554,7 +2554,7 @@ export struct EntityManager Params: tmpl = pointer entity template allocated by EntityManager. */ - export Entity* addEntity(EntityTemplate* tmpl) + export Entity* addEntity(EntityTemplate* tmpl) nothrow @nogc { return addEntity(tmpl, null); } @@ -2567,7 +2567,7 @@ export struct EntityManager tmpl = pointer entity template allocated by EntityManager. replacement = list of components references to used. Memory form list replace data from template inside new entity. Should be used only for data which vary between most entities (like 3D position etc.) */ - export Entity* addEntity(EntityTemplate* tmpl, ComponentRef[] replacement) + export Entity* addEntity(EntityTemplate* tmpl, ComponentRef[] replacement) nothrow @nogc { EntityInfo* info = tmpl.info; @@ -2664,7 +2664,7 @@ export struct EntityManager /************************************************************************************************************************ Return block with free space for selected EntityInfo. Additional this function is multithread safe. */ - private EntitiesBlock* findBlockWithFreeSpaceMT(EntityInfo* info) + private EntitiesBlock* findBlockWithFreeSpaceMT(EntityInfo* info) nothrow @nogc { EntitiesBlock* block = info.last_block; @@ -2718,7 +2718,7 @@ export struct EntityManager Params: id = id of entity to remove */ - export void removeEntity(EntityID id) + export void removeEntity(EntityID id) nothrow @nogc { threads[threadID].entitesToRemove.add(id); } diff --git a/source/bubel/ecs/std.d b/source/bubel/ecs/std.d index 8eb0d48..879fcd5 100644 --- a/source/bubel/ecs/std.d +++ b/source/bubel/ecs/std.d @@ -279,7 +279,7 @@ static struct Mallocator static if (__traits(isPOD, T)) { - __gshared immutable T init = T.init; + __gshared T init = T.init; memcpy(ret, &init, T.sizeof); } else static if (is(T == struct)) diff --git a/tests/meson.build b/tests/meson.build index ff1a3a1..c530e3e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -13,9 +13,9 @@ tests_src = files( exe = executable('BubelECSTests', tests_src, include_directories : [inc, include_directories('..')], - d_args : args, - link_args : link_args, - dependencies : decs_dep, + # d_args : args, + # link_args : link_args, + dependencies : bubel_ecs_dep, ) test('basic-tests', exe) diff --git a/xmake.lua b/xmake.lua index 6e29477..873a69f 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,15 +1,25 @@ add_rules("mode.debug", "mode.release") +if get_config("toolchain") == "ldc" then + add_ldflags("-linker=lld", {force = true}) +end + option("betterC") set_default(false) - if get_config("dc") == "gcc" then + if get_config("toolchain") == "gdc" then add_dcflags("-fno-druntime") + elseif get_config("toolchain") == "dmd" then + add_dcflags("-betterC") -- DMD doesn't need -betterC flag during linking!? + add_ldflags("-betterC", {force = true}) + add_shflags("-betterC", {force = true}) else - add_dcflags("-betterC") + add_ldflags("-betterC", {force = true}) -- -betterC flag isn't accepted for LDC for some reason + add_dcflags("-betterC", {force = true}) + add_shflags("-betterC", {force = true}) end target("bubel-ecs") - set_kind("static") + set_kind("shared") set_basename("BubelECS") add_files("source/bubel/**.d") add_includedirs("source", {public = true}) @@ -18,6 +28,7 @@ target("bubel-ecs") target("tests") set_kind("binary") set_basename("BubelECSTests") + add_ldflags("-L-rpath=.", {force = true}) add_files("tests/*.d|tests.d") add_includedirs(".", {public = true}) set_options("betterC") @@ -27,6 +38,8 @@ target("tests") target("test") set_kind("binary") set_basename("BubelECSTest") + -- add_rpathdirs(".") -- this doesn't work completely + add_ldflags("-L-rpath=.", {force = true}) add_files("tests/tests.d") add_includedirs(".", {public = true}) set_options("betterC") From cd1f81127a1424a99d9a0e134fd9b8c673aa6492 Mon Sep 17 00:00:00 2001 From: Mergul Date: Sun, 23 Apr 2023 21:52:18 +0200 Subject: [PATCH 3/3] Workaround for issue with hasMember and opDispatch --- source/bubel/ecs/manager.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/bubel/ecs/manager.d b/source/bubel/ecs/manager.d index 5c343e6..f1edf5c 100644 --- a/source/bubel/ecs/manager.d +++ b/source/bubel/ecs/manager.d @@ -1305,7 +1305,7 @@ export struct EntityManager // static assert(0, "Add \"mixin ECS.Component;\" in top of component structure;"); // } - static if (hasMember!(Comp, "onDestroy") && isFunction!(Comp.onDestroy) + static if (__traits(hasMember, Comp.init, "onDestroy") && isFunction!(Comp.onDestroy) && is(ReturnType!(Comp.onDestroy) == void) && Parameters!(Comp.onDestroy).length == 0) { @@ -1317,7 +1317,7 @@ export struct EntityManager info.destroy_callback = &callDestroy; } - static if (hasMember!(Comp, "onCreate") && isFunction!(Comp.onCreate) + static if (__traits(hasMember, Comp.init, "onCreate") && isFunction!(Comp.onCreate) && is(ReturnType!(Comp.onCreate) == void) && Parameters!(Comp.onCreate).length == 0) { static void callCreate(void* pointer) nothrow @nogc