FIxed GDC compilation (basic betterC WIP) and some improvements
-fixed issue with adding/removing entities inside events handling -fixed EntityMeta.getComponent() (added check if component_id is valid) -added function hasComponent to entity to check if component exists
This commit is contained in:
parent
f731b4cedb
commit
9589a5cb2d
11 changed files with 174 additions and 94 deletions
7
demos/external/sources/mmutils/thread_pool.d
vendored
7
demos/external/sources/mmutils/thread_pool.d
vendored
|
|
@ -182,6 +182,12 @@ void instructionPause()
|
||||||
|
|
||||||
__builtin_ia32_pause();
|
__builtin_ia32_pause();
|
||||||
}
|
}
|
||||||
|
else version(GNU)
|
||||||
|
{
|
||||||
|
import gcc.builtins;
|
||||||
|
|
||||||
|
__builtin_ia32_pause();
|
||||||
|
}
|
||||||
else version (DigitalMars)
|
else version (DigitalMars)
|
||||||
{
|
{
|
||||||
asm
|
asm
|
||||||
|
|
@ -189,7 +195,6 @@ void instructionPause()
|
||||||
rep;
|
rep;
|
||||||
nop;
|
nop;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import ecs_utils.gfx.texture;
|
||||||
import ecs_utils.math.vector;
|
import ecs_utils.math.vector;
|
||||||
import ecs_utils.utils;
|
import ecs_utils.utils;
|
||||||
|
|
||||||
import std.array : staticArray;
|
//import std.array : staticArray;
|
||||||
|
|
||||||
enum float px = 1.0/512.0;
|
enum float px = 1.0/512.0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,19 @@ float randomRangef(float min, float max)
|
||||||
return rand()%4096;
|
return rand()%4096;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
extern(C) int printf(scope const char* format, ...) @nogc nothrow @system;
|
version(GNU)
|
||||||
|
{
|
||||||
|
public import core.stdc.stdio : printf;
|
||||||
|
pragma(inline, true) T[n] staticArray(T, size_t n)(auto ref T[n] a)
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
extern(C) int printf(scope const char* format, ...) @nogc nothrow @system;
|
||||||
|
public import std.array : staticArray;
|
||||||
|
}
|
||||||
extern(C) int rand();
|
extern(C) int rand();
|
||||||
|
|
||||||
version(D_BetterC)
|
version(D_BetterC)
|
||||||
|
|
|
||||||
14
dub.json
14
dub.json
|
|
@ -74,6 +74,9 @@
|
||||||
"dflags": [
|
"dflags": [
|
||||||
"-betterC",
|
"-betterC",
|
||||||
"-defaultlib="
|
"-defaultlib="
|
||||||
|
],
|
||||||
|
"dflags-gdc": [
|
||||||
|
"-fno-druntime"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -88,9 +91,7 @@
|
||||||
],
|
],
|
||||||
"dflags-gdc": [
|
"dflags-gdc": [
|
||||||
"-fno-druntime",
|
"-fno-druntime",
|
||||||
"-fvisibility=hidden"
|
"-fvisibility=hidden",
|
||||||
],
|
|
||||||
"lflags-gdc": [
|
|
||||||
"-lpthread"
|
"-lpthread"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -105,9 +106,7 @@
|
||||||
"-betterC"
|
"-betterC"
|
||||||
],
|
],
|
||||||
"dflags-gdc": [
|
"dflags-gdc": [
|
||||||
"-fno-druntime"
|
"-fno-druntime",
|
||||||
],
|
|
||||||
"lflags-gdc": [
|
|
||||||
"-lpthread"
|
"-lpthread"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -118,6 +117,9 @@
|
||||||
"-betterC",
|
"-betterC",
|
||||||
"-unittest"
|
"-unittest"
|
||||||
],
|
],
|
||||||
|
"dflags-gdc": [
|
||||||
|
"-fno-druntime"
|
||||||
|
],
|
||||||
"sourcePaths": ["source/","tests/"],
|
"sourcePaths": ["source/","tests/"],
|
||||||
"mainSourceFile":"tests/runner.d",
|
"mainSourceFile":"tests/runner.d",
|
||||||
"excludedSourceFiles":[
|
"excludedSourceFiles":[
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,14 @@ struct Entity
|
||||||
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + ind * T.sizeof);
|
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + ind * T.sizeof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasComponent(ushort component_id)
|
||||||
|
{
|
||||||
|
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
||||||
|
EntityManager.EntityInfo* info = block.type_info;
|
||||||
|
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
EntityMeta getMeta()
|
EntityMeta getMeta()
|
||||||
{
|
{
|
||||||
EntityMeta meta;
|
EntityMeta meta;
|
||||||
|
|
@ -65,8 +73,18 @@ struct EntityMeta
|
||||||
|
|
||||||
T* getComponent(T)() const
|
T* getComponent(T)() const
|
||||||
{
|
{
|
||||||
|
const (EntityManager.EntityInfo)* info = block.type_info;
|
||||||
|
if (T.component_id >= info.deltas.length || info.deltas[T.component_id] == 0)
|
||||||
|
return null;
|
||||||
return cast(T*)(cast(void*)block + block.type_info.deltas[T.component_id] + index * T.sizeof);
|
return cast(T*)(cast(void*)block + block.type_info.deltas[T.component_id] + index * T.sizeof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasComponent(ushort component_id)
|
||||||
|
{
|
||||||
|
EntityManager.EntityInfo* info = block.type_info;
|
||||||
|
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************************************************
|
/************************************************************************************************************************
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ export struct EntityManager
|
||||||
//if(info.components)Mallocator.dispose(info.components);
|
//if(info.components)Mallocator.dispose(info.components);
|
||||||
|
|
||||||
Mallocator.dispose(info);
|
Mallocator.dispose(info);
|
||||||
} //*/
|
}
|
||||||
|
|
||||||
foreach (UpdatePass* pass; passes)
|
foreach (UpdatePass* pass; passes)
|
||||||
{
|
{
|
||||||
|
|
@ -472,50 +472,52 @@ export struct EntityManager
|
||||||
if (member == "length" || member == "thread_id"
|
if (member == "length" || member == "thread_id"
|
||||||
|| is(MemberType == Entity[]) || is(MemberType == const(Entity)[]))
|
|| is(MemberType == Entity[]) || is(MemberType == const(Entity)[]))
|
||||||
{
|
{
|
||||||
continue;
|
//continue;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
string name;
|
|
||||||
static if (isArray!MemberType)
|
|
||||||
{ // Workaround. This code is never called with: not an array type, but compiler prints an error
|
|
||||||
name = Unqual!(ForeachType!MemberType).stringof;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_optional;
|
|
||||||
bool is_read_only;
|
|
||||||
|
|
||||||
if (is(CopyConstness!(ForeachType!(MemberType), int) == const(int)))
|
|
||||||
{
|
{
|
||||||
is_read_only = true;
|
string name;
|
||||||
}
|
static if (isArray!MemberType)
|
||||||
|
{ // Workaround. This code is never called with: not an array type, but compiler prints an error
|
||||||
foreach (att; __traits(getAttributes, __traits(getMember,
|
name = Unqual!(ForeachType!MemberType).stringof;
|
||||||
Sys.EntitiesData, member)))
|
|
||||||
{
|
|
||||||
if (att == "optional")
|
|
||||||
{
|
|
||||||
is_optional = true;
|
|
||||||
}
|
}
|
||||||
if (att == "readonly")
|
|
||||||
|
bool is_optional;
|
||||||
|
bool is_read_only;
|
||||||
|
|
||||||
|
if (is(CopyConstness!(ForeachType!(MemberType), int) == const(int)))
|
||||||
{
|
{
|
||||||
is_read_only = true;
|
is_read_only = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (is_read_only)
|
foreach (att; __traits(getAttributes, __traits(getMember,
|
||||||
{
|
Sys.EntitiesData, member)))
|
||||||
components_counts.readonly++;
|
{
|
||||||
}
|
if (att == "optional")
|
||||||
else
|
{
|
||||||
{
|
is_optional = true;
|
||||||
components_counts.mutable++;
|
}
|
||||||
}
|
if (att == "readonly")
|
||||||
if (is_optional)
|
{
|
||||||
{
|
is_read_only = true;
|
||||||
components_counts.optional++;
|
}
|
||||||
}
|
}
|
||||||
else
|
if (is_read_only)
|
||||||
{
|
{
|
||||||
components_counts.req++;
|
components_counts.readonly++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
components_counts.mutable++;
|
||||||
|
}
|
||||||
|
if (is_optional)
|
||||||
|
{
|
||||||
|
components_counts.optional++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
components_counts.req++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -695,50 +697,52 @@ export struct EntityManager
|
||||||
{
|
{
|
||||||
if (is(MemberType == Entity[]) || is(MemberType == const(Entity)[]))
|
if (is(MemberType == Entity[]) || is(MemberType == const(Entity)[]))
|
||||||
components_info.entites_array = member;
|
components_info.entites_array = member;
|
||||||
continue;
|
//continue;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
string name;
|
|
||||||
static if (isArray!MemberType)
|
|
||||||
{ // Workaround. This code is never called with: not an array type, but compiler prints an error
|
|
||||||
name = Unqual!(ForeachType!MemberType).stringof;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_optional;
|
|
||||||
bool is_read_only;
|
|
||||||
|
|
||||||
if (is(CopyConstness!(ForeachType!(MemberType), int) == const(int)))
|
|
||||||
{
|
{
|
||||||
is_read_only = true;
|
string name;
|
||||||
}
|
static if (isArray!MemberType)
|
||||||
|
{ // Workaround. This code is never called with: not an array type, but compiler prints an error
|
||||||
foreach (att; __traits(getAttributes, __traits(getMember,
|
name = Unqual!(ForeachType!MemberType).stringof;
|
||||||
Sys.EntitiesData, member)))
|
|
||||||
{
|
|
||||||
if (att == "optional")
|
|
||||||
{
|
|
||||||
is_optional = true;
|
|
||||||
}
|
}
|
||||||
if (att == "readonly")
|
|
||||||
|
bool is_optional;
|
||||||
|
bool is_read_only;
|
||||||
|
|
||||||
|
if (is(CopyConstness!(ForeachType!(MemberType), int) == const(int)))
|
||||||
{
|
{
|
||||||
is_read_only = true;
|
is_read_only = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (is_read_only)
|
foreach (att; __traits(getAttributes, __traits(getMember,
|
||||||
{
|
Sys.EntitiesData, member)))
|
||||||
components_info.addReadonly(CompInfo(member, name));
|
{
|
||||||
}
|
if (att == "optional")
|
||||||
else
|
{
|
||||||
{
|
is_optional = true;
|
||||||
components_info.addMutable(CompInfo(member, name));
|
}
|
||||||
}
|
if (att == "readonly")
|
||||||
if (is_optional)
|
{
|
||||||
{
|
is_read_only = true;
|
||||||
components_info.addOptional(CompInfo(member, name));
|
}
|
||||||
}
|
}
|
||||||
else
|
if (is_read_only)
|
||||||
{
|
{
|
||||||
components_info.addReq(CompInfo(member, name));
|
components_info.addReadonly(CompInfo(member, name));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
components_info.addMutable(CompInfo(member, name));
|
||||||
|
}
|
||||||
|
if (is_optional)
|
||||||
|
{
|
||||||
|
components_info.addOptional(CompInfo(member, name));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
components_info.addReq(CompInfo(member, name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -874,7 +878,7 @@ export struct EntityManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fillInputData(ref Sys.EntitiesData input_data, EntityInfo* info,
|
static void fillInputData()(ref Sys.EntitiesData input_data, EntityInfo* info,
|
||||||
EntitiesBlock* block, uint offset, uint entities_count, System* system)
|
EntitiesBlock* block, uint offset, uint entities_count, System* system)
|
||||||
{
|
{
|
||||||
//enum ComponentsIndices components_info = getComponentsInfo();
|
//enum ComponentsIndices components_info = getComponentsInfo();
|
||||||
|
|
@ -2863,7 +2867,11 @@ export struct EntityManager
|
||||||
id_manager.optimize();
|
id_manager.optimize();
|
||||||
updateBlocks();
|
updateBlocks();
|
||||||
changeEntities();
|
changeEntities();
|
||||||
|
|
||||||
updateEvents();
|
updateEvents();
|
||||||
|
|
||||||
|
id_manager.optimize();
|
||||||
|
updateBlocks();
|
||||||
removeEntities();
|
removeEntities();
|
||||||
event_manager.clearEvents();
|
event_manager.clearEvents();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,14 @@ else version(D_BetterC)
|
||||||
alloca_pos += length;
|
alloca_pos += length;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version(GNU)
|
||||||
|
{
|
||||||
|
extern(C) void __gdc_personality_v0()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,8 @@ public:
|
||||||
/*foreach (ref el; array[0 .. used]) {
|
/*foreach (ref el; array[0 .. used]) {
|
||||||
destroy(el);
|
destroy(el);
|
||||||
}*/
|
}*/
|
||||||
freeData(cast(void[]) array);
|
//freeData(cast(void[]) array);
|
||||||
|
freeData((cast(void*)array.ptr)[0 .. array.length * T.sizeof]);
|
||||||
gVectorsDestroyed++;
|
gVectorsDestroyed++;
|
||||||
}
|
}
|
||||||
array = null;
|
array = null;
|
||||||
|
|
@ -78,7 +79,9 @@ public:
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach (ref el; array[newLength .. used]) {
|
foreach (ref el; array[newLength .. used]) {
|
||||||
destroy(el);
|
//destroy(el);
|
||||||
|
static if(__traits(hasMember, T, "__xdtor"))el.__xdtor();
|
||||||
|
else static if(__traits(hasMember, T, "__dtor"))el.__dtor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
used = newLength;
|
used = newLength;
|
||||||
|
|
@ -122,7 +125,8 @@ public:
|
||||||
T* memory = cast(T*) malloc(newSize);
|
T* memory = cast(T*) malloc(newSize);
|
||||||
memcpy(cast(void*) memory, cast(void*) oldArray.ptr, oldSize);
|
memcpy(cast(void*) memory, cast(void*) oldArray.ptr, oldSize);
|
||||||
array = memory[0 .. newNumOfElements];
|
array = memory[0 .. newNumOfElements];
|
||||||
return cast(void[]) oldArray;
|
//return cast(void[]) oldArray;
|
||||||
|
return (cast(void*)oldArray.ptr)[0 .. oldArray.length * T.sizeof];
|
||||||
}
|
}
|
||||||
|
|
||||||
export Vector!T copy()() {
|
export Vector!T copy()() {
|
||||||
|
|
@ -169,7 +173,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
export void remove(size_t elemNum) {
|
export void remove(size_t elemNum) {
|
||||||
destroy(array[elemNum]);
|
//destroy(array[elemNum]);
|
||||||
|
static if(__traits(hasMember, T, "__xdtor"))array[elemNum].__xdtor();
|
||||||
|
else static if(__traits(hasMember, T, "__dtor"))array[elemNum].__dtor();
|
||||||
//swap(array[elemNum], array[used - 1]);
|
//swap(array[elemNum], array[used - 1]);
|
||||||
array[elemNum] = array[used - 1];
|
array[elemNum] = array[used - 1];
|
||||||
used--;
|
used--;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,14 @@ import bubel.ecs.core;
|
||||||
import bubel.ecs.manager;
|
import bubel.ecs.manager;
|
||||||
import bubel.ecs.entity;
|
import bubel.ecs.entity;
|
||||||
|
|
||||||
import std.array : staticArray;
|
version(GNU)
|
||||||
|
{
|
||||||
|
pragma(inline, true) T[n] staticArray(T, size_t n)(auto ref T[n] a)
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else import std.array : staticArray;
|
||||||
|
|
||||||
import core.stdc.stdio;
|
import core.stdc.stdio;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,14 @@ import bubel.ecs.manager;
|
||||||
import bubel.ecs.system;
|
import bubel.ecs.system;
|
||||||
import bubel.ecs.attributes;
|
import bubel.ecs.attributes;
|
||||||
|
|
||||||
import std.array : staticArray;
|
version(GNU)
|
||||||
|
{
|
||||||
|
pragma(inline, true) T[n] staticArray(T, size_t n)(auto ref T[n] a)
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else import std.array : staticArray;
|
||||||
|
|
||||||
struct CInt
|
struct CInt
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,14 @@ import bubel.ecs.core;
|
||||||
import bubel.ecs.manager;
|
import bubel.ecs.manager;
|
||||||
import bubel.ecs.entity;
|
import bubel.ecs.entity;
|
||||||
|
|
||||||
import std.array : staticArray;
|
version(GNU)
|
||||||
|
{
|
||||||
|
pragma(inline, true) T[n] staticArray(T, size_t n)(auto ref T[n] a)
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else import std.array : staticArray;
|
||||||
|
|
||||||
import core.stdc.stdio;
|
import core.stdc.stdio;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue