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:
Mergul 2020-05-14 22:18:57 +02:00
parent f731b4cedb
commit 9589a5cb2d
11 changed files with 174 additions and 94 deletions

View file

@ -126,7 +126,7 @@ export struct EntityManager
//if(info.components)Mallocator.dispose(info.components);
Mallocator.dispose(info);
} //*/
}
foreach (UpdatePass* pass; passes)
{
@ -472,50 +472,52 @@ export struct EntityManager
if (member == "length" || member == "thread_id"
|| is(MemberType == Entity[]) || is(MemberType == const(Entity)[]))
{
continue;
//continue;
}
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)))
else
{
is_read_only = true;
}
foreach (att; __traits(getAttributes, __traits(getMember,
Sys.EntitiesData, member)))
{
if (att == "optional")
{
is_optional = true;
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;
}
if (att == "readonly")
bool is_optional;
bool is_read_only;
if (is(CopyConstness!(ForeachType!(MemberType), int) == const(int)))
{
is_read_only = true;
}
}
if (is_read_only)
{
components_counts.readonly++;
}
else
{
components_counts.mutable++;
}
if (is_optional)
{
components_counts.optional++;
}
else
{
components_counts.req++;
foreach (att; __traits(getAttributes, __traits(getMember,
Sys.EntitiesData, member)))
{
if (att == "optional")
{
is_optional = true;
}
if (att == "readonly")
{
is_read_only = true;
}
}
if (is_read_only)
{
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)[]))
components_info.entites_array = member;
continue;
//continue;
}
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)))
else
{
is_read_only = true;
}
foreach (att; __traits(getAttributes, __traits(getMember,
Sys.EntitiesData, member)))
{
if (att == "optional")
{
is_optional = true;
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;
}
if (att == "readonly")
bool is_optional;
bool is_read_only;
if (is(CopyConstness!(ForeachType!(MemberType), int) == const(int)))
{
is_read_only = true;
}
}
if (is_read_only)
{
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));
foreach (att; __traits(getAttributes, __traits(getMember,
Sys.EntitiesData, member)))
{
if (att == "optional")
{
is_optional = true;
}
if (att == "readonly")
{
is_read_only = true;
}
}
if (is_read_only)
{
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)
{
//enum ComponentsIndices components_info = getComponentsInfo();
@ -2863,7 +2867,11 @@ export struct EntityManager
id_manager.optimize();
updateBlocks();
changeEntities();
updateEvents();
id_manager.optimize();
updateBlocks();
removeEntities();
event_manager.clearEvents();
}