新增jobSystem

This commit is contained in:
yhh
2021-02-01 14:23:13 +08:00
parent d7ec4d087c
commit f6513a0cf3
6 changed files with 236 additions and 38 deletions

View File

@@ -115,7 +115,8 @@ module es {
public removeFromTagList(entity: Entity) {
let list = this._entityDict.get(entity.tag);
list.delete(entity);
if (list)
list.delete(entity);
}
public update() {

View File

@@ -11,21 +11,14 @@ module es {
/**
* 创建一个worker
* @param doFunc worker所能做的事情
*
* @example const worker = es.WorkerUtils.makeWorker(()=>{
* onmessage = ({data: {jobId, meesage}}) => {
* // worker内做的事
* console.log('我是线程', message, jobId);
* };
* });
*
* worker('主线程发送消息').then(message => {
* console.log('主线程收到消息', message);
* });
*/
public static makeWorker(doFunc: Function) {
const worker = new Worker(URL.createObjectURL(new Blob([`(${doFunc.toString()})()`])));
return worker;
}
public static workerMessage(worker: Worker) {
worker.onmessage = ({ data: { result, jobId } }) => {
if (typeof this.pendingJobs[jobId] == 'function')
this.pendingJobs[jobId](result);