-support for 'length' parameter in EntitiesData (for convenience)

This commit is contained in:
Mergul 2018-10-01 15:08:14 +02:00
parent 0e13fafefd
commit 125c9e7d40
3 changed files with 24 additions and 5 deletions

View file

@ -78,11 +78,17 @@ class EntityManager
{
static if (isFunction!(__traits(getMember, Sys.EntitiesData, member)))
static assert(0, "EntitiesData can't have any function!");
else static if(member == "length")
{
static assert(isIntegral!(typeof(__traits(getMember,Sys.EntitiesData, member))),"EntitiesData 'length' member must be integral type.");
static assert(typeof(__traits(getMember,Sys.EntitiesData, member)).sizeof > 1,"EntitiesData 'length' member can't be byte or ubyte.");
}
else static if (!(isArray!(typeof(__traits(getMember,
Sys.EntitiesData, member)))))
static assert(0, "EntitiesData members should be arrays of elements!");
else static if (is(typeof(__traits(getMember, Sys.EntitiesData,
member)) == Entity[]))
member)) == Entity[]) || is(typeof(__traits(getMember,
Sys.EntitiesData, member)) == const(Entity)[]))
{
//ret ~= "const string entities_name = \"" ~ member ~ "\";";
}
@ -124,6 +130,10 @@ class EntityManager
Sys.EntitiesData, member)) == const(Entity)[]))
{
//ret ~= "const string entities_name = \"" ~ member ~ "\";";
}
else static if(member == "length")
{
}
else
{
@ -198,6 +208,11 @@ class EntityManager
ret ~= "input_data." ~ member
~ " = (cast(Entity*) block.dataBegin())[0 .. block.entities_count];";
}
else if(member == "length")
{
ret ~= "input_data." ~ member
~ " = block.entities_count;";
}
else
{
{
@ -306,8 +321,8 @@ class EntityManager
}
else
{
string name = Mallocator.instance.makeArray(Sys.stringof);
systems_map.add(name, cast(ushort) systems.length);
system.name = Mallocator.instance.makeArray(Sys.stringof);
systems_map.add(system.name, cast(ushort) systems.length);
systems.add(system);
@ -1240,7 +1255,7 @@ class EntityManager
Vector!ubyte change_entities_list;
HashMap!(ushort[], EntityInfo*) entities_infos;
HashMap!(string, ushort) systems_map;
HashMap!(const (char)[], ushort) systems_map;
HashMap!(string, ushort) components_map;
HashMap!(string, ushort) events_map;
Vector!System systems;

View file

@ -38,6 +38,8 @@ package:
///pointer to system implementation
void* m_system_pointer;
const (char)[] name;
ushort[] m_components;
ushort[] m_absen_components;
ushort[] m_optional_components;

View file

@ -127,6 +127,7 @@ int main()
static struct EntitiesData
{
size_t length;
TestComp[] test;
TestComp2[] test2;
@optional TestComp3[] test3;
@ -147,7 +148,7 @@ int main()
void update(ref EntitiesData data)
{
foreach(i;0..data.test.length)
foreach(i;0..data.length)
{
data.test[i].a += 1000;
data.test[i].b += 2000;
@ -193,6 +194,7 @@ int main()
static struct EntitiesData
{
short length;
Entity[] entity;
TestComp3[] test;
}