Browse Source

work

1993-leagues
Shaun 11 months ago
parent
commit
45715686a2
4 changed files with 18 additions and 9 deletions
  1. +2
    -0
      src/client/ui/templates/characters/characters.js
  2. +3
    -0
      src/server/config/consts.js
  3. +2
    -2
      src/server/world/instancer.js
  4. +11
    -7
      src/server/world/threadManager.js

+ 2
- 0
src/client/ui/templates/characters/characters.js View File

@@ -216,6 +216,8 @@ define([
this.find('.name').html(charName + ' (hc - rip)');
this.find('.btnPlay').addClass('disabled');
}

events.emit('afterGetCharacter', { character: result });
},

setMessage: function (msg) {


+ 3
- 0
src/server/config/consts.js View File

@@ -21,6 +21,9 @@ module.exports = {
//How far a player can see objects vertically
viewDistanceY: 14,

//How many milliseconds to wait to kill a thread after it's been empty
destroyThreadWhenEmptyForMs: 10 * 60 * 1000,

init: function (threadArgs) {
const emBeforeGetConsts = {
threadArgs,


+ 2
- 2
src/server/world/instancer.js View File

@@ -68,7 +68,7 @@ module.exports = {
map.randomMap.init(fakeInstance);
this.startRegen();
} else
_.log(`Ready: ${JSON.stringify(this.threadArgs, null, '\t')}`);
_.log(`Ready: ${this.threadArgs.id}`);

map.clientMap.zoneId = this.zoneId;

@@ -167,7 +167,7 @@ module.exports = {

this.addQueue = [];

_.log(`Ready: ${JSON.stringify(this.threadArgs, null, '\t')}`);
_.log(`Ready: ${this.threadArgs.id}`);
},

tick: function () {


+ 11
- 7
src/server/world/threadManager.js View File

@@ -166,7 +166,9 @@ const onMessage = (thread, message) => {
messageHandlers[message.method](thread, message);
};

const spawnThread = async ({ map: { name, path, instanced, destroyWhenEmptyForMs = -1 }, obj }) => {
const spawnThread = async ({ map: { name, path, instanced, destroyWhenEmptyForMs }, obj }) => {
destroyWhenEmptyForMs = destroyWhenEmptyForMs ?? consts.destroyThreadWhenEmptyForMs;

let cbOnInitialized;

const promise = new Promise(resolveOnReady => {
@@ -188,7 +190,8 @@ const spawnThread = async ({ map: { name, path, instanced, destroyWhenEmptyForMs
birthEpoch: +new Date(),
destroyWhenEmptyForMs,
emptySinceEpoch: null,
sendArgsToWorker: ['name', 'id']
sendArgsToWorker: ['name', 'id'],
workerArgs: null
};

const emBeforeSpawnThread = {
@@ -197,13 +200,12 @@ const spawnThread = async ({ map: { name, path, instanced, destroyWhenEmptyForMs
};
events.emit('beforeSpawnThread', emBeforeSpawnThread);

const workerArgs = JSON.stringify(
Object.fromEntries(
thread.sendArgsToWorker.map(a => [a, thread[a]])
)
thread.workerArgs = Object.fromEntries(
thread.sendArgsToWorker.map(a => [a, thread[a]])
);

thread.worker = childProcess.fork('./world/worker', [workerArgs]);
_.log(`Spawning: ${JSON.stringify(thread.workerArgs, null, '\t')}`);
thread.worker = childProcess.fork('./world/worker', [JSON.stringify(thread.workerArgs)]);

thread.worker.on('message', onMessage.bind(null, thread));

@@ -248,6 +250,8 @@ const getThread = async ({ zoneName, zoneId, obj }) => {
};

const killThread = thread => {
_.log(`Killing: ${thread.workerArgs.id}`);

thread.worker.kill();
threads.spliceWhere(t => t === thread);
};


Loading…
Cancel
Save