From 3a3a9e0341dba0484765b9ab10e159958a47a8ca Mon Sep 17 00:00:00 2001 From: Mergul Date: Thu, 23 Mar 2023 22:31:20 +0100 Subject: [PATCH] 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")