Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
cd1f81127a Workaround for issue with hasMember and opDispatch 2023-04-23 21:52:18 +02:00
3a3a9e0341 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
2023-03-23 22:31:20 +01:00
5e123d96b3 Add xmake 2023-03-09 14:08:42 +01:00
8 changed files with 143 additions and 26 deletions

1
.gitignore vendored
View file

@ -6,6 +6,7 @@
!.gitignore !.gitignore
!codecov.yml !codecov.yml
!skeleton.html !skeleton.html
!**/xmake.lua
!**/meson.build !**/meson.build
!**/*.wrap !**/*.wrap
!meson_options.txt !meson_options.txt

View file

@ -7,9 +7,9 @@
"description": "Dynamic Entity Component System", "description": "Dynamic Entity Component System",
"copyright": "Copyright © 2018-2023, Michał Masiukiewicz, Dawid Masiukiewicz", "copyright": "Copyright © 2018-2023, Michał Masiukiewicz, Dawid Masiukiewicz",
"license": "BSD 3-clause", "license": "BSD 3-clause",
"sourcePaths" : ["source\/"], "sourcePaths" : ["source/"],
"excludedSourceFiles":[ "excludedSourceFiles":[
"source\/ecs\/traits.d" "source/ecs/traits.d"
], ],
"configurations" : [ "configurations" : [
{ {
@ -21,7 +21,7 @@
"sourceFiles" : ["tests/tests.d"], "sourceFiles" : ["tests/tests.d"],
"targetType" : "executable", "targetType" : "executable",
"excludedSourceFiles":[ "excludedSourceFiles":[
"source\/win_dll.d" "source/win_dll.d"
] ]
}, },
{ {
@ -45,7 +45,7 @@
"sourcePaths": ["source/","tests/"], "sourcePaths": ["source/","tests/"],
"mainSourceFile":"tests/runner.d", "mainSourceFile":"tests/runner.d",
"excludedSourceFiles":[ "excludedSourceFiles":[
"source\/win_dll.d", "source/win_dll.d",
"tests/tests.d" "tests/tests.d"
], ],
"dflags": [ "dflags": [
@ -58,7 +58,7 @@
"sourcePaths": ["source/","tests/"], "sourcePaths": ["source/","tests/"],
"mainSourceFile":"tests/runner.d", "mainSourceFile":"tests/runner.d",
"excludedSourceFiles":[ "excludedSourceFiles":[
"source\/win_dll.d", "source/win_dll.d",
"tests/tests.d" "tests/tests.d"
], ],
"dflags": [ "dflags": [
@ -70,7 +70,7 @@
"name" : "library-betterC", "name" : "library-betterC",
"targetType" : "library", "targetType" : "library",
"excludedSourceFiles":[ "excludedSourceFiles":[
"source\/win_dll.d" "source/win_dll.d"
], ],
"dflags": [ "dflags": [
"-betterC", "-betterC",
@ -101,7 +101,7 @@
"targetType" : "executable", "targetType" : "executable",
"sourceFiles" : ["tests/tests.d"], "sourceFiles" : ["tests/tests.d"],
"excludedSourceFiles":[ "excludedSourceFiles":[
"source\/win_dll.d" "source/win_dll.d"
], ],
"dflags": [ "dflags": [
"-betterC" "-betterC"
@ -125,7 +125,7 @@
"sourcePaths": ["source/","tests/"], "sourcePaths": ["source/","tests/"],
"mainSourceFile":"tests/runner.d", "mainSourceFile":"tests/runner.d",
"excludedSourceFiles":[ "excludedSourceFiles":[
"source\/win_dll.d", "source/win_dll.d",
"tests/tests.d" "tests/tests.d"
] ]
} }

View file

@ -44,7 +44,7 @@ struct Entity
return cast(T*)getComponent(becsID!T); 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.EntitiesBlock* block = gEntityManager.getMetaData(&this);
EntityManager.EntityInfo* info = block.type_info; 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); 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.EntitiesBlock* block = gEntityManager.getMetaData(&this);
EntityManager.EntityInfo* info = block.type_info; EntityManager.EntityInfo* info = block.type_info;
@ -62,7 +62,7 @@ struct Entity
return true; return true;
} }
EntityMeta getMeta() const EntityMeta getMeta() const nothrow @nogc
{ {
EntityMeta meta; EntityMeta meta;
meta.block = gEntityManager.getMetaData(&this); meta.block = gEntityManager.getMetaData(&this);
@ -85,7 +85,7 @@ struct EntityMeta
return cast(T*)getComponent(becsID!T); 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; 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); 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; const EntityManager.EntityInfo* info = block.type_info;
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false; 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. 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; 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]); return cast(T*)(entity_data.ptr + info.tmpl_deltas[becsID!T]);

View file

@ -1305,7 +1305,7 @@ export struct EntityManager
// static assert(0, "Add \"mixin ECS.Component;\" in top of component structure;"); // 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) && is(ReturnType!(Comp.onDestroy) == void)
&& Parameters!(Comp.onDestroy).length == 0) && Parameters!(Comp.onDestroy).length == 0)
{ {
@ -1317,7 +1317,7 @@ export struct EntityManager
info.destroy_callback = &callDestroy; 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) && is(ReturnType!(Comp.onCreate) == void) && Parameters!(Comp.onCreate).length == 0)
{ {
static void callCreate(void* pointer) nothrow @nogc static void callCreate(void* pointer) nothrow @nogc
@ -2502,7 +2502,7 @@ export struct EntityManager
*Params: *Params:
*id = ID of entity to be copyied. *id = ID of entity to be copyied.
*/ */
export Entity* addEntityCopy(EntityID id) export Entity* addEntityCopy(EntityID id) nothrow @nogc
{ {
Entity* entity = getEntity(id); Entity* entity = getEntity(id);
EntitiesBlock* block = getMetaData(entity); EntitiesBlock* block = getMetaData(entity);
@ -2554,7 +2554,7 @@ export struct EntityManager
Params: Params:
tmpl = pointer entity template allocated by EntityManager. tmpl = pointer entity template allocated by EntityManager.
*/ */
export Entity* addEntity(EntityTemplate* tmpl) export Entity* addEntity(EntityTemplate* tmpl) nothrow @nogc
{ {
return addEntity(tmpl, null); return addEntity(tmpl, null);
} }
@ -2567,7 +2567,7 @@ export struct EntityManager
tmpl = pointer entity template allocated by 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.) 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; 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. 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; EntitiesBlock* block = info.last_block;
@ -2718,7 +2718,7 @@ export struct EntityManager
Params: Params:
id = id of entity to remove id = id of entity to remove
*/ */
export void removeEntity(EntityID id) export void removeEntity(EntityID id) nothrow @nogc
{ {
threads[threadID].entitesToRemove.add(id); threads[threadID].entitesToRemove.add(id);
} }

View file

@ -279,7 +279,7 @@ static struct Mallocator
static if (__traits(isPOD, T)) static if (__traits(isPOD, T))
{ {
__gshared immutable T init = T.init; __gshared T init = T.init;
memcpy(ret, &init, T.sizeof); memcpy(ret, &init, T.sizeof);
} }
else static if (is(T == struct)) else static if (is(T == struct))

View file

@ -13,9 +13,9 @@ tests_src = files(
exe = executable('BubelECSTests', exe = executable('BubelECSTests',
tests_src, tests_src,
include_directories : [inc, include_directories('..')], include_directories : [inc, include_directories('..')],
d_args : args, # d_args : args,
link_args : link_args, # link_args : link_args,
dependencies : decs_dep, dependencies : bubel_ecs_dep,
) )
test('basic-tests', exe) test('basic-tests', exe)

View file

@ -645,7 +645,7 @@ version (unittest)
else: else:
extern (C) int main() extern (C) int main()
{ {
version (D_BetterC)printf("BetterC\n");
void dispatch(EntityManager.JobGroup jobs) nothrow @nogc void dispatch(EntityManager.JobGroup jobs) nothrow @nogc
{ {
foreach (job; jobs.jobs) foreach (job; jobs.jobs)

116
xmake.lua Normal file
View file

@ -0,0 +1,116 @@
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("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_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("shared")
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_ldflags("-L-rpath=.", {force = true})
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_rpathdirs(".") -- this doesn't work completely
add_ldflags("-L-rpath=.", {force = true})
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
--