-updated tests:

*updated build scripts
 *removed tls variables from code (needed to support WebAssembly)
 *some mmutils tweaks
 *some fixes
 *pthread TLS thread ID implementation
-added Atomic file (reimplementation of atomics templates for emscripten)
-added emscripten support to ecs.std
This commit is contained in:
Mergul 2019-11-25 20:06:16 +00:00
parent 46de0f6adb
commit 946fbf2934
18 changed files with 443 additions and 229 deletions

View file

@ -7,7 +7,7 @@ import std.algorithm : max;
import std.conv : to;
import std.traits;
import core.atomic;
//import core.atomic;
//import core.stdc.stdlib : qsort;
//import core.stdc.string;
@ -21,6 +21,7 @@ import ecs.simple_vector;
import ecs.std;
import ecs.traits;
import ecs.vector;
import ecs.atomic;
export alias gEM = EntityManager.instance;
export alias gEntityManager = EntityManager.instance;
@ -1119,10 +1120,16 @@ export struct EntityManager
}
}
export void setJobDispachFunc(void delegate(JobGroup) func) nothrow @nogc
export void setMultithreadingCallbacks(void delegate(JobGroup) dispatch_callback, uint delegate() get_id_callback)
{
m_dispatch_jobs = cast(void delegate(JobGroup jobs) nothrow @nogc)dispatch_callback;
m_thread_id_func = cast(uint delegate() nothrow @nogc)get_id_callback;
}
/*export void setJobDispachFunc(void delegate(JobGroup) @nogc nothrow func) nothrow @nogc
{
m_dispatch_jobs = func;
}
}*/
static void alignNum(ref ushort num, ushort alignment) nothrow @nogc pure
{
@ -1502,7 +1509,7 @@ export struct EntityManager
*/
export void removeComponents(EntityID entity_id, ushort[] del_ids) nothrow @nogc
{
ThreadData* data = &threads[thread_id];
ThreadData* data = &threads[threadID];
uint num = cast(uint) del_ids.length;
data.change_entities_list.add(0);
data.change_entities_list.add((cast(ubyte*)&entity_id)[0 .. EntityID.sizeof]);
@ -1753,7 +1760,7 @@ export struct EntityManager
new_ids[i] = comp.component_id;
}
ThreadData* data = &threads[thread_id];
ThreadData* data = &threads[threadID];
data.change_entities_list.add(cast(ubyte)1u);
data.change_entities_list.add((cast(ubyte*)&entity_id)[0 .. EntityID.sizeof]);
data.change_entities_list.add((cast(ubyte*)&num)[0 .. uint.sizeof]);
@ -1820,7 +1827,7 @@ export struct EntityManager
}
if (new_index == 1)
threads[thread_id].blocks_to_update.add(new_block);
threads[threadID].blocks_to_update.add(new_block);
Entity* new_entity = cast(Entity*) start;
//add_mutex.lock_nothrow();
@ -1870,7 +1877,7 @@ export struct EntityManager
}
if (index == 1)
threads[thread_id].blocks_to_update.add(block);
threads[threadID].blocks_to_update.add(block);
Entity* entity = cast(Entity*) start;
//add_mutex.lock_nothrow();
@ -1961,7 +1968,7 @@ export struct EntityManager
*/
export void removeEntity(EntityID id)
{
threads[thread_id].entities_to_remove.add(id);
threads[threadID].entities_to_remove.add(id);
}
private void __removeEntity(EntityID id) nothrow @nogc
@ -2301,17 +2308,17 @@ export struct EntityManager
commit();
}
private void getThreadID() nothrow @nogc
/*private void getThreadID() nothrow @nogc
{
if (m_thread_id_func)
thread_id = (cast(uint delegate() nothrow @nogc) m_thread_id_func)();
else
thread_id = 0;
}
}*/
void sendEvent(Ev)(EntityID id, Ev event) nothrow @nogc
{
event_manager.sendEvent(id, event, thread_id);
event_manager.sendEvent(id, event, threadID);
}
private void generateDependencies() nothrow @nogc
@ -2722,7 +2729,7 @@ export struct EntityManager
export void execute() nothrow @nogc
{
EntityManager.instance.getThreadID();
//EntityManager.instance.getThreadID();
foreach (ref caller; callers)
{
caller.update();
@ -2789,7 +2796,27 @@ export struct EntityManager
Vector!(SystemCaller*) system_callers;
}
static uint thread_id;
export uint threadID() @nogc nothrow
{
if (m_thread_id_func)
return m_thread_id_func();
else
return 0;
}
/*uint thread_id() @nogc nothrow
{
if (m_thread_id_func)
return (cast(uint delegate() nothrow @nogc) m_thread_id_func)();
else
return 0;
}
void thread_id(uint) @nogc nothrow
{
}*/
//static uint thread_id;
ThreadData[] threads;
@ -2809,8 +2836,8 @@ export struct EntityManager
EventManager event_manager;
void delegate(JobGroup jobs) m_dispatch_jobs;
uint delegate() m_thread_id_func;
void delegate(JobGroup jobs) nothrow @nogc m_dispatch_jobs;
uint delegate() nothrow @nogc m_thread_id_func;
HashMap!(ushort[], EntityInfo*) entities_infos;
HashMap!(char[], ushort) systems_map;