-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:
parent
46de0f6adb
commit
946fbf2934
18 changed files with 443 additions and 229 deletions
|
|
@ -160,14 +160,14 @@ struct CleanSystem
|
|||
|
||||
void mainLoop(void* arg)
|
||||
{
|
||||
static double time = 0;
|
||||
__gshared double time = 0;
|
||||
launcher.delta_time = launcher.getTime() - time;
|
||||
time = launcher.getTime();
|
||||
|
||||
if(launcher.delta_time > 1000)launcher.delta_time = 1000;
|
||||
|
||||
static uint temp_fps = 0;
|
||||
static double fps_time = 0;
|
||||
__gshared uint temp_fps = 0;
|
||||
__gshared double fps_time = 0;
|
||||
temp_fps++;
|
||||
fps_time += launcher.delta_time;
|
||||
while(fps_time > 1000)
|
||||
|
|
@ -295,7 +295,7 @@ void mainLoop(void* arg)
|
|||
{
|
||||
launcher.setStyle(2);
|
||||
}
|
||||
else if(igMenuItemBool("Super",null,launcher.style == 3,true))
|
||||
else if(igMenuItemBool("Default",null,launcher.style == 3,true))
|
||||
{
|
||||
launcher.setStyle(3);
|
||||
}
|
||||
|
|
@ -466,8 +466,8 @@ void mainLoop(void* arg)
|
|||
launcher.renderer.present();
|
||||
draw_time = launcher.getTime() - draw_time;
|
||||
|
||||
static float plot_time = 0;
|
||||
static uint plot_samples = 0;
|
||||
__gshared float plot_time = 0;
|
||||
__gshared uint plot_samples = 0;
|
||||
plot_time += launcher.delta_time;
|
||||
plot_samples++;
|
||||
launcher.plot_values[100].delta_time += launcher.delta_time;
|
||||
|
|
@ -602,14 +602,15 @@ int main(int argc, char** argv)
|
|||
|
||||
setStyle(3);
|
||||
|
||||
launcher.job_updater = Mallocator.make!ECSJobUpdater(8);
|
||||
launcher.job_updater = Mallocator.make!ECSJobUpdater(12);
|
||||
//launcher.job_updater.onCreate();
|
||||
|
||||
EntityManager.initialize(8);
|
||||
EntityManager.initialize(12);
|
||||
launcher.manager = EntityManager.instance;
|
||||
|
||||
launcher.manager.m_thread_id_func = &launcher.job_updater.getThreadID;
|
||||
launcher.manager.setJobDispachFunc(&launcher.job_updater.dispatch);
|
||||
//launcher.manager.m_thread_id_func = &launcher.job_updater.getThreadID;
|
||||
//launcher.manager.setJobDispachFunc(&launcher.job_updater.dispatch);
|
||||
launcher.manager.setMultithreadingCallbacks(&launcher.job_updater.dispatch, &launcher.job_updater.getThreadID);
|
||||
|
||||
launcher.manager.beginRegister();
|
||||
|
||||
|
|
@ -645,7 +646,7 @@ int main(int argc, char** argv)
|
|||
//int result = emscripten_request_fullscreen_strategy(null, true, &strategy);
|
||||
//emscripten_enter_soft_fullscreen(null, &strategy);
|
||||
//printf("Fullscreen request: %s.\n", emscripten_result_to_string(result));
|
||||
emscripten_set_main_loop_arg(&mainLoop, null, -1, 1);
|
||||
emscripten_set_main_loop_arg(&mainLoop, null, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ struct MoveSystem
|
|||
}
|
||||
}
|
||||
|
||||
Simple* simple;
|
||||
__gshared Simple* simple;
|
||||
|
||||
void simpleStart()
|
||||
{
|
||||
|
|
@ -149,7 +149,7 @@ bool simpleLoop()
|
|||
{
|
||||
if(launcher.getKeyState(SDL_SCANCODE_SPACE))
|
||||
{
|
||||
spawnEntity();
|
||||
foreach(i;0..10000)spawnEntity();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -159,7 +159,6 @@ bool simpleLoop()
|
|||
launcher.job_updater.begin();
|
||||
launcher.manager.updateMT();
|
||||
launcher.job_updater.call();
|
||||
launcher.multithreading = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ struct CleanSystem
|
|||
}
|
||||
}
|
||||
|
||||
Snake* snake;
|
||||
__gshared Snake* snake;
|
||||
|
||||
void snakeStart()
|
||||
{
|
||||
|
|
@ -500,7 +500,7 @@ bool snakeLoop()
|
|||
|
||||
float delta_time = launcher.delta_time;
|
||||
if(delta_time > 2000)delta_time = 2000;
|
||||
static float time = 0;
|
||||
__gshared float time = 0;
|
||||
|
||||
if(launcher.getKeyState(SDL_SCANCODE_SPACE))time += delta_time * 3;
|
||||
else time += delta_time;
|
||||
|
|
|
|||
|
|
@ -746,8 +746,6 @@ bool spaceInvadersLoop()
|
|||
launcher.job_updater.begin();
|
||||
launcher.manager.updateMT();
|
||||
launcher.job_updater.call();
|
||||
launcher.multithreading = false;
|
||||
printf("Disable mt\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ module game_core.job_updater;
|
|||
|
||||
import ecs.std;
|
||||
import ecs.vector;
|
||||
import ecs.atomic;
|
||||
|
||||
import ecs_utils.utils;
|
||||
|
||||
|
|
@ -9,6 +10,17 @@ import ecs_utils.utils;
|
|||
import ecs.manager;
|
||||
import mmutils.thread_pool;
|
||||
|
||||
version(LDC)
|
||||
{
|
||||
import ldc.attributes;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct optStrategy {
|
||||
string strategy;
|
||||
}
|
||||
}
|
||||
|
||||
//import supre.core.call_graph_generator;
|
||||
|
||||
struct ECSJobUpdater
|
||||
|
|
@ -24,14 +36,21 @@ struct ECSJobUpdater
|
|||
pool.waitThreads();
|
||||
//pool.unregistExternalThread(thread_data);
|
||||
if(jobs)Mallocator.dispose(jobs);
|
||||
version(WebAssembly)pthread_key_delete(tls_key);
|
||||
}
|
||||
|
||||
version(WebAssembly)
|
||||
{
|
||||
__gshared pthread_key_t tls_key;
|
||||
}
|
||||
else static uint thread_id = 0;
|
||||
|
||||
ThreadPool pool;
|
||||
ThreadData* thread_data;
|
||||
|
||||
int job_id = 0;
|
||||
int no_dep_count = 0;
|
||||
static uint thread_id = 0;
|
||||
//static uint thread_id = 0;
|
||||
|
||||
struct Group
|
||||
{
|
||||
|
|
@ -78,21 +97,25 @@ struct ECSJobUpdater
|
|||
Group[] jobs;
|
||||
Vector!(Group*) call_jobs;
|
||||
Group last_job;
|
||||
JobData[1] groupEndJobs;
|
||||
|
||||
//TrackData[32] trackers;
|
||||
|
||||
void onCreate(uint threads_count)
|
||||
{
|
||||
version(WebAssembly)pthread_key_create(&tls_key, null);
|
||||
|
||||
pool.initialize();
|
||||
//thread_data = pool.registerExternalThread();
|
||||
thread_data = pool.registerExternalThread();
|
||||
pool.setThreadsNum(threads_count);
|
||||
|
||||
jobs = Mallocator.makeArray!Group(256);
|
||||
}
|
||||
|
||||
uint getThreadID() nothrow
|
||||
uint getThreadID() @nogc nothrow
|
||||
{
|
||||
return thread_id;
|
||||
version(WebAssembly)return cast(int)pthread_getspecific(tls_key);
|
||||
else return thread_id;
|
||||
}
|
||||
|
||||
void begin()
|
||||
|
|
@ -113,36 +136,44 @@ struct ECSJobUpdater
|
|||
//foreach(ref tracker;trackers)tracker.clear();
|
||||
}
|
||||
|
||||
@optStrategy("none")
|
||||
void nop()
|
||||
{
|
||||
int i;
|
||||
i++;
|
||||
}
|
||||
|
||||
//@optStrategy("none")
|
||||
void call()
|
||||
{
|
||||
if(last_job.group.getDependenciesWaitCount() == 0)return;
|
||||
if(call_jobs.length == 0)return;
|
||||
|
||||
JobData[1] groupEndJobs;
|
||||
groupEndJobs[0] = JobData(&releaseMainThread, "Stop Threads");
|
||||
//JobData[1] groupEndJobs;
|
||||
groupEndJobs[0] = JobData(&releaseMainThread, "Stop Threads", null, null);
|
||||
|
||||
last_job.group.jobs = groupEndJobs;
|
||||
last_job.group.thPool = &pool;
|
||||
last_job.group.executeOnThreadNum = 0;
|
||||
|
||||
foreach(job;call_jobs)
|
||||
{
|
||||
job.start();
|
||||
}
|
||||
ret = false;
|
||||
while(!ret)
|
||||
|
||||
/*while(atomicLoad(ret) == 1)//!cas(&ret,0,1))
|
||||
{
|
||||
printf("SDL\n");
|
||||
}
|
||||
printf("NonSDL\n");
|
||||
//thread_data.threadStartFunc();
|
||||
nop();
|
||||
version(WebAssembly)//emscripten_main_thread_process_queued_calls();
|
||||
}//*/
|
||||
|
||||
int i = 10;
|
||||
thread_data.threadStartFunc();
|
||||
}
|
||||
shared bool ret = false;
|
||||
|
||||
void releaseMainThread(ThreadData* th_data, JobData* data)
|
||||
{
|
||||
//pool.releaseExternalThreads();
|
||||
ret = true;
|
||||
//atomicStore(ret,0);
|
||||
pool.releaseExternalThreads();
|
||||
}
|
||||
|
||||
static struct JobCaller
|
||||
|
|
@ -153,10 +184,27 @@ shared bool ret = false;
|
|||
|
||||
void callJob(ThreadData* th_data, JobData* data)
|
||||
{
|
||||
updater.thread_id = th_data.threadId;
|
||||
uint job_id = updater.getThreadID();
|
||||
|
||||
//uint job_id = updater.getThreadID();
|
||||
//updater.trackers[job_id].begin(id);
|
||||
job.execute();
|
||||
version(WebAssembly)
|
||||
{
|
||||
//updater.thread_id = th_data.threadId;
|
||||
pthread_setspecific(tls_key, cast(void*)th_data.threadId);
|
||||
if(th_data.threadId == 0)
|
||||
{
|
||||
emscripten_main_thread_process_queued_calls();
|
||||
job.execute();
|
||||
emscripten_main_thread_process_queued_calls();
|
||||
}
|
||||
else job.execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
updater.thread_id = th_data.threadId;
|
||||
job.execute();
|
||||
}
|
||||
//atomicOp!"-="(updater.jobs_count,1);
|
||||
//updater.trackers[job_id].end();
|
||||
}
|
||||
}
|
||||
|
|
@ -178,7 +226,7 @@ shared bool ret = false;
|
|||
caller.id = index;
|
||||
jobs[group.id].add(caller);
|
||||
}
|
||||
|
||||
|
||||
jobs[group.id].build(&pool);
|
||||
|
||||
uint deps = cast(uint)group.dependencies.length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue