-updated wasm build scripts
-multitheaded wasm tests -updated dub.json -fixed thread pool assert issue -added windows libraries -added demos: *launcher *simple *snake *space invaders (WIP) *statistics window *changable gui styles *tips window *profile window *demo window with automatic generation *multithreaded job updater
This commit is contained in:
parent
cb7609dcaa
commit
5894e76540
26 changed files with 2562 additions and 20 deletions
199
demos/source/game_core/job_updater.d
Normal file
199
demos/source/game_core/job_updater.d
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
module game_core.job_updater;
|
||||
|
||||
import ecs.std;
|
||||
import ecs.vector;
|
||||
|
||||
import ecs_utils.utils;
|
||||
|
||||
//import core.time;
|
||||
import ecs.manager;
|
||||
import mmutils.thread_pool;
|
||||
|
||||
//import supre.core.call_graph_generator;
|
||||
|
||||
struct ECSJobUpdater
|
||||
{
|
||||
|
||||
this(uint threads)
|
||||
{
|
||||
onCreate(threads);
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
pool.waitThreads();
|
||||
//pool.unregistExternalThread(thread_data);
|
||||
if(jobs)Mallocator.dispose(jobs);
|
||||
}
|
||||
|
||||
ThreadPool pool;
|
||||
ThreadData* thread_data;
|
||||
|
||||
int job_id = 0;
|
||||
int no_dep_count = 0;
|
||||
static uint thread_id = 0;
|
||||
|
||||
struct Group
|
||||
{
|
||||
~this() nothrow
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
JobsGroup group;
|
||||
JobData[1024] jobs;
|
||||
JobCaller[1024] callers;
|
||||
uint count = 0;
|
||||
|
||||
void dependantOn(Group* dependency)
|
||||
{
|
||||
group.dependantOn(&dependency.group);
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
group.thPool.addGroupAsynchronous(&group);
|
||||
}
|
||||
|
||||
void build(ThreadPool* pool)
|
||||
{
|
||||
group.thPool = pool;
|
||||
group.jobs = jobs[0..count];
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
group = JobsGroup("name",null);
|
||||
count = 0;
|
||||
}
|
||||
|
||||
void add(JobCaller caller)
|
||||
{
|
||||
callers[count] = caller;
|
||||
jobs[count] = JobData(&callers[count].callJob,"hmm");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
Group[] jobs;
|
||||
Vector!(Group*) call_jobs;
|
||||
Group last_job;
|
||||
|
||||
//TrackData[32] trackers;
|
||||
|
||||
void onCreate(uint threads_count)
|
||||
{
|
||||
pool.initialize();
|
||||
//thread_data = pool.registerExternalThread();
|
||||
pool.setThreadsNum(threads_count);
|
||||
|
||||
jobs = Mallocator.makeArray!Group(256);
|
||||
}
|
||||
|
||||
uint getThreadID() nothrow
|
||||
{
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
void begin()
|
||||
{
|
||||
job_id = 0;
|
||||
call_jobs.clear();
|
||||
|
||||
foreach(ref job;jobs)
|
||||
{
|
||||
job.clear();
|
||||
}
|
||||
|
||||
last_job.clear();
|
||||
}
|
||||
|
||||
void clearTracker()
|
||||
{
|
||||
//foreach(ref tracker;trackers)tracker.clear();
|
||||
}
|
||||
|
||||
void call()
|
||||
{
|
||||
if(last_job.group.getDependenciesWaitCount() == 0)return;
|
||||
if(call_jobs.length == 0)return;
|
||||
|
||||
JobData[1] groupEndJobs;
|
||||
groupEndJobs[0] = JobData(&releaseMainThread, "Stop Threads");
|
||||
|
||||
last_job.group.jobs = groupEndJobs;
|
||||
last_job.group.executeOnThreadNum = 0;
|
||||
|
||||
foreach(job;call_jobs)
|
||||
{
|
||||
job.start();
|
||||
}
|
||||
ret = false;
|
||||
while(!ret)
|
||||
{
|
||||
printf("SDL\n");
|
||||
}
|
||||
printf("NonSDL\n");
|
||||
//thread_data.threadStartFunc();
|
||||
|
||||
int i = 10;
|
||||
}
|
||||
shared bool ret = false;
|
||||
void releaseMainThread(ThreadData* th_data, JobData* data)
|
||||
{
|
||||
//pool.releaseExternalThreads();
|
||||
ret = true;
|
||||
}
|
||||
|
||||
static struct JobCaller
|
||||
{
|
||||
EntityManager.Job* job;
|
||||
ECSJobUpdater* updater;
|
||||
uint id;
|
||||
|
||||
void callJob(ThreadData* th_data, JobData* data)
|
||||
{
|
||||
updater.thread_id = th_data.threadId;
|
||||
uint job_id = updater.getThreadID();
|
||||
//updater.trackers[job_id].begin(id);
|
||||
job.execute();
|
||||
//updater.trackers[job_id].end();
|
||||
}
|
||||
}
|
||||
|
||||
void dispatch(EntityManager.JobGroup group)
|
||||
{
|
||||
if(group.jobs.length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(ref job;group.jobs)
|
||||
{
|
||||
uint index = 0;
|
||||
if(job.callers.length)index = job.callers[0].system_id;
|
||||
JobCaller caller;
|
||||
caller.updater = &this;
|
||||
caller.job = &job;
|
||||
caller.id = index;
|
||||
jobs[group.id].add(caller);
|
||||
}
|
||||
|
||||
jobs[group.id].build(&pool);
|
||||
|
||||
uint deps = cast(uint)group.dependencies.length;
|
||||
|
||||
foreach(dep;group.dependencies)
|
||||
{
|
||||
if(jobs[dep.id].count && dep.caller.system.execute && dep.caller.system.enabled)jobs[group.id].dependantOn(&jobs[dep.id]);
|
||||
else deps--;
|
||||
}
|
||||
|
||||
if(deps == 0)
|
||||
{
|
||||
call_jobs.add(&jobs[group.id]);
|
||||
}
|
||||
|
||||
last_job.dependantOn(&jobs[group.id]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue