Better assertion infos and formatted code
This commit is contained in:
parent
0670aed506
commit
14839b3765
6 changed files with 163 additions and 109 deletions
|
|
@ -351,8 +351,10 @@ export struct EntityManager
|
|||
void registerSystem(Sys)(int priority, const(char)[] pass_name)
|
||||
{
|
||||
ushort pass = passes_map.get(pass_name, ushort.max);
|
||||
version(D_BetterC)assert(pass != ushort.max, "Update pass doesn't exist.");
|
||||
else assert(pass != ushort.max, "Update pass (Name " ~ pass_name ~ ") doesn't exist.");
|
||||
version (D_BetterC)
|
||||
assert(pass != ushort.max, "Update pass doesn't exist.");
|
||||
else
|
||||
assert(pass != ushort.max, "Update pass (Name " ~ pass_name ~ ") doesn't exist.");
|
||||
registerSystem!(Sys)(priority, pass);
|
||||
}
|
||||
|
||||
|
|
@ -371,8 +373,10 @@ export struct EntityManager
|
|||
|
||||
assert(register_state,
|
||||
"registerSystem must be called between beginRegister() and endRegister().");
|
||||
version(D_BetterC)assert(pass < passes.length, "Update pass doesn't exist.");
|
||||
else assert(pass < passes.length, "Update pass (ID " ~ pass.to!string ~ ") doesn't exist.");
|
||||
version (D_BetterC)
|
||||
assert(pass < passes.length, "Update pass doesn't exist.");
|
||||
else
|
||||
assert(pass < passes.length, "Update pass (ID " ~ pass.to!string ~ ") doesn't exist.");
|
||||
|
||||
System system;
|
||||
system.m_pass = pass;
|
||||
|
|
@ -599,7 +603,8 @@ export struct EntityManager
|
|||
string entites_array;
|
||||
}
|
||||
|
||||
static void allocateSystemComponents(ComponentsIndices!component_counts components_info)(ref System system)
|
||||
static void allocateSystemComponents(ComponentsIndices!component_counts components_info)(
|
||||
ref System system)
|
||||
{
|
||||
size_t req = components_info.req.length;
|
||||
size_t opt = components_info.optional.length;
|
||||
|
|
@ -744,7 +749,8 @@ export struct EntityManager
|
|||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||
version (D_BetterC)
|
||||
assert(comp != ushort.max,
|
||||
"Can't register system due to non existing component.");
|
||||
"Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component.");
|
||||
else
|
||||
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
|
||||
|
|
@ -753,29 +759,49 @@ export struct EntityManager
|
|||
foreach (iii, comp_info; components_info.excluded)
|
||||
{
|
||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||
version (D_BetterC)assert(comp != ushort.max, "Can't register system due to non existing component.");
|
||||
else assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
|
||||
version (D_BetterC)
|
||||
assert(comp != ushort.max,
|
||||
"Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component.");
|
||||
else
|
||||
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
|
||||
system.m_excluded_components[iii] = comp;
|
||||
}
|
||||
foreach (iii, comp_info; components_info.optional)
|
||||
{
|
||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||
version (D_BetterC)assert(comp != ushort.max, "Can't register system due to non existing component.");
|
||||
else assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
|
||||
version (D_BetterC)
|
||||
assert(comp != ushort.max,
|
||||
"Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component.");
|
||||
else
|
||||
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
|
||||
system.m_optional_components[iii] = comp;
|
||||
}
|
||||
foreach (iii, comp_info; components_info.readonly)
|
||||
{
|
||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||
version (D_BetterC)assert(comp != ushort.max, "Can't register system due to non existing component.");
|
||||
else assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
|
||||
version (D_BetterC)
|
||||
assert(comp != ushort.max,
|
||||
"Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component.");
|
||||
else
|
||||
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
|
||||
system.m_read_only_components[iii] = comp;
|
||||
}
|
||||
foreach (iii, comp_info; components_info.mutable)
|
||||
{
|
||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||
version (D_BetterC)assert(comp != ushort.max, "Can't register system due to non existing component.");
|
||||
else assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
|
||||
version (D_BetterC)
|
||||
assert(comp != ushort.max,
|
||||
"Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component.");
|
||||
else
|
||||
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
|
||||
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
|
||||
system.m_modified_components[iii] = comp;
|
||||
}
|
||||
|
||||
|
|
@ -1531,31 +1557,35 @@ export struct EntityManager
|
|||
*Params:
|
||||
*components_ids = array of components allocated with template
|
||||
*/
|
||||
export EntityTemplate* allocateTemplate(EntityTemplate* base_tmpl, ushort[] components_ids, ushort[] remove_components_ids = null)
|
||||
export EntityTemplate* allocateTemplate(EntityTemplate* base_tmpl,
|
||||
ushort[] components_ids, ushort[] remove_components_ids = null)
|
||||
{
|
||||
size_t len = base_tmpl.info.components.length + components_ids.length;
|
||||
ushort[] ids = (cast(ushort*) alloca(ushort.sizeof * len))[0
|
||||
.. len];
|
||||
memcpy(ids.ptr, base_tmpl.info.components.ptr, ushort.sizeof * base_tmpl.info.components.length);
|
||||
memcpy(ids.ptr + base_tmpl.info.components.length, components_ids.ptr, ushort.sizeof * components_ids.length);
|
||||
|
||||
ushort[] ids = (cast(ushort*) alloca(ushort.sizeof * len))[0 .. len];
|
||||
memcpy(ids.ptr, base_tmpl.info.components.ptr,
|
||||
ushort.sizeof * base_tmpl.info.components.length);
|
||||
memcpy(ids.ptr + base_tmpl.info.components.length, components_ids.ptr,
|
||||
ushort.sizeof * components_ids.length);
|
||||
|
||||
qsort(ids.ptr, ids.length, ushort.sizeof, &compareUShorts);
|
||||
qsort(remove_components_ids.ptr, remove_components_ids.length, ushort.sizeof, &compareUShorts);
|
||||
qsort(remove_components_ids.ptr, remove_components_ids.length,
|
||||
ushort.sizeof, &compareUShorts);
|
||||
{
|
||||
uint k = 0;
|
||||
uint j = 1;
|
||||
foreach (i; 1 .. ids.length)
|
||||
{
|
||||
assert(ids[i] != ushort.max);
|
||||
if(k < remove_components_ids.length)
|
||||
if (k < remove_components_ids.length)
|
||||
{
|
||||
while(k < remove_components_ids.length && remove_components_ids[k] < ids[i])
|
||||
while (k < remove_components_ids.length && remove_components_ids[k] < ids[i])
|
||||
{
|
||||
k++;
|
||||
}
|
||||
if(k < remove_components_ids.length)
|
||||
if (k < remove_components_ids.length)
|
||||
{
|
||||
if(remove_components_ids[k] == ids[i])continue;
|
||||
if (remove_components_ids[k] == ids[i])
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (ids[i] != ids[j - 1])
|
||||
|
|
@ -1578,10 +1608,11 @@ export struct EntityManager
|
|||
//fill components with default data and copy from base template
|
||||
foreach (comp; info.components)
|
||||
{
|
||||
if(comp < base_tmpl.info.deltas.length && base_tmpl.info.deltas[comp] != ushort.max) //copy data from base component
|
||||
if (comp < base_tmpl.info.deltas.length && base_tmpl.info.deltas[comp] != ushort.max) //copy data from base component
|
||||
{
|
||||
memcpy(temp.entity_data.ptr + info.tmpl_deltas[comp],
|
||||
base_tmpl.entity_data.ptr + base_tmpl.info.tmpl_deltas[comp], components[comp].size);
|
||||
base_tmpl.entity_data.ptr + base_tmpl.info.tmpl_deltas[comp],
|
||||
components[comp].size);
|
||||
}
|
||||
else //fill with default data
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue