fix dead state
This commit is contained in:
+7
-8
@@ -19,21 +19,18 @@ export default class Game {
|
||||
tickRate = 30
|
||||
width = 0
|
||||
|
||||
#eventEmitter = new EventEmitter()
|
||||
#gameLoopIntervalId = null
|
||||
#logic = null
|
||||
#nextTickAt = 0
|
||||
#startTimestamp = 0
|
||||
#subscriptions = new Map()
|
||||
#tickBudget = 1000 / this.tickRate
|
||||
|
||||
get logic() { return this.#logic }
|
||||
get eventEmitter() { return this.#eventEmitter }
|
||||
get tickBudget() { return this.#tickBudget }
|
||||
set logic(value) { this.#logic = value }
|
||||
get subscriptions() { return this.#subscriptions }
|
||||
|
||||
constructor() {
|
||||
this.#eventEmitter.setMaxListeners(20)
|
||||
}
|
||||
set logic(value) { this.#logic = value }
|
||||
|
||||
action(id, options) {
|
||||
const entity = this.entities.find((it) => it.id == id)
|
||||
@@ -140,6 +137,10 @@ export default class Game {
|
||||
}
|
||||
|
||||
update() {
|
||||
for (const subscription of this.#subscriptions.values()) {
|
||||
subscription()
|
||||
}
|
||||
|
||||
const callUpdate = function callUpdate(object) { object.update() }
|
||||
this.entities.forEach(callUpdate) // TODO: entity with lower ID has unfair collision advantage (regular loop + until it fully loops around with an offset?)
|
||||
this.projectiles.forEach(callUpdate)
|
||||
@@ -147,8 +148,6 @@ export default class Game {
|
||||
this.#logic()
|
||||
}
|
||||
|
||||
this.eventEmitter.emit('tick')
|
||||
|
||||
this.currentTick++
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user