increase process priority instead of offloading to workers
This commit is contained in:
+5
-6
@@ -5,7 +5,6 @@ import Buff from './buff.js'
|
||||
import Entity from './entity.js'
|
||||
import Projectile from './projectile.js'
|
||||
import Terrain from './terrain.js'
|
||||
import { Worker } from 'node:worker_threads'
|
||||
|
||||
export default class Game {
|
||||
id = crypto.randomUUID()
|
||||
@@ -32,6 +31,10 @@ export default class Game {
|
||||
get tickBudget() { return this.#tickBudget }
|
||||
set logic(value) { this.#logic = value }
|
||||
|
||||
constructor() {
|
||||
this.#eventEmitter.setMaxListeners(20)
|
||||
}
|
||||
|
||||
action(id, options) {
|
||||
const entity = this.entities.find((it) => it.id == id)
|
||||
if (entity == null) {
|
||||
@@ -122,10 +125,6 @@ export default class Game {
|
||||
}
|
||||
|
||||
subscription(websocket, id) {
|
||||
const worker = new Worker('./src/worker/object-to-json.js')
|
||||
const sendToWebSocket = function sendToWebSocket(message) { websocket.send(message) } // TODO: latency because workers wait for the main thread's next tick which is ~33ms
|
||||
worker.on('message', sendToWebSocket)
|
||||
|
||||
return function builtSubscription() {
|
||||
const game = this
|
||||
|
||||
@@ -136,7 +135,7 @@ export default class Game {
|
||||
const state = game.visionByTeam(team)
|
||||
state.currentTick = game.currentTick
|
||||
|
||||
worker.postMessage(state)
|
||||
websocket.send(JSON.stringify(state))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user