|
|
@@ -36,9 +36,8 @@ module.exports = { |
|
|
|
if (map.instanced) { |
|
|
|
delete obj.x; |
|
|
|
delete obj.y; |
|
|
|
thread = this.spawnMap(map); |
|
|
|
|
|
|
|
await new Promise(res => setTimeout(res, 2000)); |
|
|
|
thread = await this.spawnMap(map); |
|
|
|
} else |
|
|
|
thread = this.getThreadFromName(map.name); |
|
|
|
} |
|
|
@@ -171,27 +170,27 @@ module.exports = { |
|
|
|
.filter(m => !m.disabled && !m.instanced) |
|
|
|
.forEach(m => this.spawnMap(m)); |
|
|
|
}, |
|
|
|
spawnMap: function ({ name, path, instanced }) { |
|
|
|
const worker = childProcess.fork('./world/worker', [name]); |
|
|
|
|
|
|
|
const id = instanced ? _.getGuid() : name; |
|
|
|
|
|
|
|
const thread = { |
|
|
|
id, |
|
|
|
name, |
|
|
|
instanced, |
|
|
|
path, |
|
|
|
worker |
|
|
|
}; |
|
|
|
|
|
|
|
const onMessage = this.onMessage.bind(this, thread); |
|
|
|
worker.on('message', function (m) { |
|
|
|
onMessage(m); |
|
|
|
}); |
|
|
|
spawnMap: async function ({ name, path, instanced }) { |
|
|
|
return new Promise(resolveOnReady => { |
|
|
|
const worker = childProcess.fork('./world/worker', [name]); |
|
|
|
|
|
|
|
const id = instanced ? _.getGuid() : name; |
|
|
|
|
|
|
|
const thread = { |
|
|
|
id, |
|
|
|
name, |
|
|
|
instanced, |
|
|
|
path, |
|
|
|
worker, |
|
|
|
cbOnInitialized: resolveOnReady |
|
|
|
}; |
|
|
|
|
|
|
|
this.threads.push(thread); |
|
|
|
const onMessage = this.onMessage.bind(this, thread); |
|
|
|
worker.on('message', function (m) { |
|
|
|
onMessage(m); |
|
|
|
}); |
|
|
|
|
|
|
|
return thread; |
|
|
|
this.threads.push(thread); |
|
|
|
}, |
|
|
|
onMessage: function (thread, message) { |
|
|
|
if (message.module) { |
|
|
@@ -229,6 +228,10 @@ module.exports = { |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
onInitialized: function (thread) { |
|
|
|
thread.cbOnInitialized(thread); |
|
|
|
}, |
|
|
|
|
|
|
|
event: function (thread, message) { |
|
|
|
objects.sendEvent(message, thread); |
|
|
|
}, |
|
|
|