-getComponent functions for Template and Entity
-error information about adding system with non existing component (prints name of system and component) -fill components in template with default values
This commit is contained in:
parent
4b19907c03
commit
624c899c8c
2 changed files with 30 additions and 5 deletions
|
|
@ -51,11 +51,15 @@ class EntityManager
|
|||
|
||||
static string genCompList()()
|
||||
{
|
||||
string ret;
|
||||
string ret = "uint comp;";
|
||||
foreach (i; 1 .. (Parameters!(Sys.update)).length)
|
||||
{
|
||||
ret ~= "system.m_components[" ~ (i - 1)
|
||||
.to!string ~ "] = components_map.get(types[" ~ i.to!string ~ "].stringof);\n";
|
||||
ret ~= "comp = components_map.get(types[" ~ i.to!string ~ "].stringof, ushort.max);\n
|
||||
if(comp == ushort.max)assert(0,\"Can't register system \\\"" ~ Sys.stringof
|
||||
~ "\\\" due to non existing component \\\"\"~types[" ~ i.to!string ~ "].stringof~\"\\\".\");
|
||||
system.m_components[" ~ (i - 1)
|
||||
.to!string ~ "] = comp;";
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -131,10 +135,11 @@ class EntityManager
|
|||
static assert(0, "Component should have \"__gshared ushort component_id");
|
||||
}
|
||||
|
||||
ushort size = Comp.sizeof;
|
||||
ComponentInfo info;
|
||||
info.size = size;
|
||||
info.size = Comp.sizeof;
|
||||
info.aligment = Comp.alignof; //8;
|
||||
info.init_data = Mallocator.instance.makeArray!ubyte(Comp.sizeof);
|
||||
*cast(Comp*)info.init_data.ptr = Comp();
|
||||
|
||||
components.add(info);
|
||||
Comp.component_id = cast(ushort)(components.length - 1);
|
||||
|
|
@ -196,6 +201,13 @@ class EntityManager
|
|||
EntityTemplate* temp = Mallocator.instance.make!EntityTemplate;
|
||||
temp.entity_data = Mallocator.instance.makeArray!ubyte(info.size);
|
||||
temp.info = info;
|
||||
|
||||
//fill components with default data
|
||||
foreach(comp;info.components)
|
||||
{
|
||||
temp.entity_data[info.deltas[comp]..info.deltas[comp]+components[comp].size] = components[comp].init_data;
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
|
@ -475,6 +487,7 @@ class EntityManager
|
|||
{
|
||||
ushort size;
|
||||
ushort aligment;
|
||||
ubyte[] init_data;
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue