replace most systems with THREE

This commit is contained in:
2024-12-22 23:52:56 +09:00
parent 14212afd70
commit 054d22d01a
7 changed files with 107 additions and 87 deletions
+13 -7
View File
@@ -1,25 +1,31 @@
import { System } from 'detect-collisions'
import { EventEmitter } from 'node:events'
export default class Game {
entities = []
tickRate = 30
currentTick = 0
width = 15000
height = 15000
#entities = []
#eventEmitter = new EventEmitter()
#system = new System()
#tickBudget = Math.floor(1000 / this.tickRate)
get entities() { return this.#entities }
get eventEmitter() { return this.#eventEmitter }
get system() { return this.#system }
get tickBudget() { return this.#tickBudget }
spawn_entity(entity) {
this.entities.push(entity)
this.#system.insert(entity.collider)
this.#entities.push(entity)
entity.game = this
}
state() {
return {
...this,
entities: this.#entities.map((e) => e.state()),
}
}
async start() {
const start = performance.now()
await this.update()
@@ -27,7 +33,7 @@ export default class Game {
}
async update() {
Promise.allSettled(this.entities.map((e) => e.update()))
Promise.allSettled(this.#entities.map((e) => e.update()))
this.currentTick++
this.eventEmitter.emit('tick')
}