Web assembly #6
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)
|
void registerSystem(Sys)(int priority, const(char)[] pass_name)
|
||||||
{
|
{
|
||||||
ushort pass = passes_map.get(pass_name, ushort.max);
|
ushort pass = passes_map.get(pass_name, ushort.max);
|
||||||
version(D_BetterC)assert(pass != ushort.max, "Update pass doesn't exist.");
|
version (D_BetterC)
|
||||||
else assert(pass != ushort.max, "Update pass (Name " ~ pass_name ~ ") doesn't exist.");
|
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);
|
registerSystem!(Sys)(priority, pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -371,8 +373,10 @@ export struct EntityManager
|
||||||
|
|
||||||
assert(register_state,
|
assert(register_state,
|
||||||
"registerSystem must be called between beginRegister() and endRegister().");
|
"registerSystem must be called between beginRegister() and endRegister().");
|
||||||
version(D_BetterC)assert(pass < passes.length, "Update pass doesn't exist.");
|
version (D_BetterC)
|
||||||
else assert(pass < passes.length, "Update pass (ID " ~ pass.to!string ~ ") doesn't exist.");
|
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 system;
|
||||||
system.m_pass = pass;
|
system.m_pass = pass;
|
||||||
|
|
@ -599,7 +603,8 @@ export struct EntityManager
|
||||||
string entites_array;
|
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 req = components_info.req.length;
|
||||||
size_t opt = components_info.optional.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);
|
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||||
version (D_BetterC)
|
version (D_BetterC)
|
||||||
assert(comp != ushort.max,
|
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
|
else
|
||||||
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
|
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
|
||||||
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
|
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
|
||||||
|
|
@ -753,29 +759,49 @@ export struct EntityManager
|
||||||
foreach (iii, comp_info; components_info.excluded)
|
foreach (iii, comp_info; components_info.excluded)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
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.");
|
version (D_BetterC)
|
||||||
else assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
|
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;
|
system.m_excluded_components[iii] = comp;
|
||||||
}
|
}
|
||||||
foreach (iii, comp_info; components_info.optional)
|
foreach (iii, comp_info; components_info.optional)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
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.");
|
version (D_BetterC)
|
||||||
else assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
|
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;
|
system.m_optional_components[iii] = comp;
|
||||||
}
|
}
|
||||||
foreach (iii, comp_info; components_info.readonly)
|
foreach (iii, comp_info; components_info.readonly)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
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.");
|
version (D_BetterC)
|
||||||
else assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
|
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;
|
system.m_read_only_components[iii] = comp;
|
||||||
}
|
}
|
||||||
foreach (iii, comp_info; components_info.mutable)
|
foreach (iii, comp_info; components_info.mutable)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
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.");
|
version (D_BetterC)
|
||||||
else assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
|
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;
|
system.m_modified_components[iii] = comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1531,16 +1557,19 @@ export struct EntityManager
|
||||||
*Params:
|
*Params:
|
||||||
*components_ids = array of components allocated with template
|
*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;
|
size_t len = base_tmpl.info.components.length + components_ids.length;
|
||||||
ushort[] ids = (cast(ushort*) alloca(ushort.sizeof * len))[0
|
ushort[] ids = (cast(ushort*) alloca(ushort.sizeof * len))[0 .. len];
|
||||||
.. len];
|
memcpy(ids.ptr, base_tmpl.info.components.ptr,
|
||||||
memcpy(ids.ptr, base_tmpl.info.components.ptr, ushort.sizeof * base_tmpl.info.components.length);
|
ushort.sizeof * base_tmpl.info.components.length);
|
||||||
memcpy(ids.ptr + base_tmpl.info.components.length, components_ids.ptr, ushort.sizeof * components_ids.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(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 k = 0;
|
||||||
uint j = 1;
|
uint j = 1;
|
||||||
|
|
@ -1555,7 +1584,8 @@ export struct EntityManager
|
||||||
}
|
}
|
||||||
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])
|
if (ids[i] != ids[j - 1])
|
||||||
|
|
@ -1581,7 +1611,8 @@ export struct EntityManager
|
||||||
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],
|
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
|
else //fill with default data
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ enum string OUT_FILE = "test_report.xml";
|
||||||
static jmp_buf gEnvBuffer;
|
static jmp_buf gEnvBuffer;
|
||||||
static AssertInfo gAssertInfo;
|
static AssertInfo gAssertInfo;
|
||||||
|
|
||||||
version(D_BetterC){}
|
version (D_BetterC)
|
||||||
|
{
|
||||||
|
}
|
||||||
else version = notBetterC;
|
else version = notBetterC;
|
||||||
|
|
||||||
struct AssertInfo
|
struct AssertInfo
|
||||||
|
|
@ -158,11 +160,13 @@ struct TestRunner(Args...)
|
||||||
|
|
||||||
Test test;
|
Test test;
|
||||||
|
|
||||||
static if (attributes.length == 0)test.name = "None";
|
static if (attributes.length == 0)
|
||||||
else test.name = attributes[0];
|
test.name = "None";
|
||||||
|
else
|
||||||
|
test.name = attributes[0];
|
||||||
|
|
||||||
|
static if (__traits(hasMember, module_, "beforeEveryTest"))
|
||||||
static if(__traits(hasMember, module_, "beforeEveryTest"))module_.beforeEveryTest();
|
module_.beforeEveryTest();
|
||||||
|
|
||||||
// Save calling environment for longjmp
|
// Save calling environment for longjmp
|
||||||
int jmp_ret = setjmp(gEnvBuffer);
|
int jmp_ret = setjmp(gEnvBuffer);
|
||||||
|
|
@ -181,10 +185,13 @@ struct TestRunner(Args...)
|
||||||
test.passed = true;
|
test.passed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(test.passed)suite.passed++;
|
if (test.passed)
|
||||||
else suite.failed++;
|
suite.passed++;
|
||||||
|
else
|
||||||
|
suite.failed++;
|
||||||
suite.tests ~= test;
|
suite.tests ~= test;
|
||||||
static if(__traits(hasMember, module_, "afterEveryTest"))module_.afterEveryTest();
|
static if (__traits(hasMember, module_, "afterEveryTest"))
|
||||||
|
module_.afterEveryTest();
|
||||||
}
|
}
|
||||||
passed += suite.passed;
|
passed += suite.passed;
|
||||||
failed += suite.failed;
|
failed += suite.failed;
|
||||||
|
|
@ -194,7 +201,8 @@ struct TestRunner(Args...)
|
||||||
|
|
||||||
void writeFile()
|
void writeFile()
|
||||||
{
|
{
|
||||||
if(junit.length == 0)generateJUnit();
|
if (junit.length == 0)
|
||||||
|
generateJUnit();
|
||||||
auto file = fopen(OUT_FILE, "w");
|
auto file = fopen(OUT_FILE, "w");
|
||||||
fwrite(junit.data.ptr, junit.length, 1, file);
|
fwrite(junit.data.ptr, junit.length, 1, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
@ -204,12 +212,14 @@ struct TestRunner(Args...)
|
||||||
{
|
{
|
||||||
foreach (ref TestSuite suite; suites)
|
foreach (ref TestSuite suite; suites)
|
||||||
{
|
{
|
||||||
printf("Suite: \"%s\" Passed: %u/%u Skipped: %u\n", suite.name.ptr, suite.passed, suite.passed + suite.failed, suite.skipped);
|
printf("Suite: \"%s\" Passed: %u/%u Skipped: %u\n", suite.name.ptr,
|
||||||
|
suite.passed, suite.passed + suite.failed, suite.skipped);
|
||||||
foreach (ref Test test; suite.tests)
|
foreach (ref Test test; suite.tests)
|
||||||
{
|
{
|
||||||
if (!test.passed)
|
if (!test.passed)
|
||||||
{
|
{
|
||||||
printf("\tTest: \"%s\" Failed! Line: %u Message: %s\n",test.name.ptr, test.file_line, test.msg.ptr);
|
printf("\tTest: \"%s\" Failed! Line: %u Message: %s\n",
|
||||||
|
test.name.ptr, test.file_line, test.msg.ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -221,16 +231,21 @@ struct TestRunner(Args...)
|
||||||
uint i = 0;
|
uint i = 0;
|
||||||
foreach (char c; b)
|
foreach (char c; b)
|
||||||
{
|
{
|
||||||
if(i > a.length)return false;
|
if (i > a.length)
|
||||||
if(a[i] == c)i++;
|
return false;
|
||||||
|
if (a[i] == c)
|
||||||
|
i++;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (a[i] == '*')
|
if (a[i] == '*')
|
||||||
{
|
{
|
||||||
if(i+1 >= a.length)return true;
|
if (i + 1 >= a.length)
|
||||||
else if(a[i + 1] == c)i += 2;
|
return true;
|
||||||
|
else if (a[i + 1] == c)
|
||||||
|
i += 2;
|
||||||
}
|
}
|
||||||
else return false;
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return i == a.length;
|
return i == a.length;
|
||||||
|
|
@ -292,28 +307,33 @@ extern(C) int main(int argc, char** args)
|
||||||
version (notBetterC)
|
version (notBetterC)
|
||||||
{
|
{
|
||||||
rt_init();
|
rt_init();
|
||||||
version(D_Coverage) dmd_coverDestPath("reports");
|
version (D_Coverage)
|
||||||
|
dmd_coverDestPath("reports");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
string arg = cast(string) args[i][0 .. strlen(args[i])];
|
string arg = cast(string) args[i][0 .. strlen(args[i])];
|
||||||
if(arg.length < 2)continue;
|
if (arg.length < 2)
|
||||||
|
continue;
|
||||||
else if (arg == "-i")
|
else if (arg == "-i")
|
||||||
{
|
{
|
||||||
if(i + 1 >= argc)break;
|
if (i + 1 >= argc)
|
||||||
|
break;
|
||||||
i++;
|
i++;
|
||||||
arg = cast(string) args[i][0 .. strlen(args[i])];
|
arg = cast(string) args[i][0 .. strlen(args[i])];
|
||||||
extractStrings(include, arg);
|
extractStrings(include, arg);
|
||||||
}
|
}
|
||||||
else if (arg == "-e")
|
else if (arg == "-e")
|
||||||
{
|
{
|
||||||
if(i + 1 >= argc)break;
|
if (i + 1 >= argc)
|
||||||
|
break;
|
||||||
i++;
|
i++;
|
||||||
arg = cast(string) args[i][0 .. strlen(args[i])];
|
arg = cast(string) args[i][0 .. strlen(args[i])];
|
||||||
extractStrings(exclude, arg);
|
extractStrings(exclude, arg);
|
||||||
}
|
}
|
||||||
else if(arg.length < 10)continue;
|
else if (arg.length < 10)
|
||||||
|
continue;
|
||||||
else if (arg[0 .. 10] == "--include=")
|
else if (arg[0 .. 10] == "--include=")
|
||||||
{
|
{
|
||||||
extractStrings(include, arg[10 .. $]);
|
extractStrings(include, arg[10 .. $]);
|
||||||
|
|
@ -332,8 +352,11 @@ extern(C) int main(int argc, char** args)
|
||||||
|
|
||||||
runner.writeOutput();
|
runner.writeOutput();
|
||||||
|
|
||||||
version(notBetterC)rt_term();
|
version (notBetterC)
|
||||||
|
rt_term();
|
||||||
|
|
||||||
if(!runner.failed)return 0;
|
if (!runner.failed)
|
||||||
else return 1;
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue