optimize reporting and serialization for clients
This commit is contained in:
+23
-23
@@ -8,9 +8,7 @@ export default class Projectile {
|
||||
static nextId() { return this.#nextUniqueId++ }
|
||||
static #nextUniqueId = 0
|
||||
|
||||
bbox = new Float32Array(4)
|
||||
height = 50
|
||||
memory = {}
|
||||
owner = null
|
||||
position = new Vector2()
|
||||
radius = 0
|
||||
@@ -21,19 +19,26 @@ export default class Projectile {
|
||||
visualRadius = null
|
||||
|
||||
#after = null
|
||||
#bbox = new Float32Array(4)
|
||||
#dest = null
|
||||
#entitiesInVision = []
|
||||
#game = null
|
||||
#homingTarget = null
|
||||
#logic = null
|
||||
#onCollide = null
|
||||
#game = null
|
||||
#projectilesInVision = []
|
||||
|
||||
get after() { return this.#after }
|
||||
get bbox() { return this.#bbox }
|
||||
get entitiesInVision() { return this.#entitiesInVision }
|
||||
get game() { return this.#game }
|
||||
get homingTarget() { return this.#homingTarget }
|
||||
get logic() { return this.#logic }
|
||||
get onCollide() { return this.#onCollide }
|
||||
get projectilesInVision() { return this.#projectilesInVision }
|
||||
|
||||
set after(value) { this.#after = value }
|
||||
set bbox(value) { this.#bbox = value }
|
||||
set destination(value) { this.#dest = value }
|
||||
set game(value) { this.#game = value }
|
||||
set homingTarget(value) { this.#homingTarget = value }
|
||||
@@ -59,16 +64,6 @@ export default class Projectile {
|
||||
this.game?.despawn(this)
|
||||
}
|
||||
|
||||
entitiesInVision() {
|
||||
const entities = this.game?.entities
|
||||
if (entities == null) { return }
|
||||
|
||||
const entitiesInVisionRange = entities.filter((it) => it.id != this.id && it.distanceTo(this.position) <= this.visionRange + it.radius)
|
||||
const entitiesInLineOfSight = entitiesInVisionRange.filter((it) => this.isInLineOfVision(it.position))
|
||||
|
||||
return entitiesInLineOfSight.concat([this]).map((it) => it.id)
|
||||
}
|
||||
|
||||
isInLineOfVision(destination) {
|
||||
const bbox = Entity.tunnelBbox(this.position.x, this.position.y, destination.x, destination.y, 0)
|
||||
const terrains = this.game?.terrains ?? []
|
||||
@@ -90,6 +85,7 @@ export default class Projectile {
|
||||
}
|
||||
|
||||
update() {
|
||||
this.#calculateVision()
|
||||
this.#move()
|
||||
this.#checkStationaryCollisions()
|
||||
this.#checkIfArrived()
|
||||
@@ -98,16 +94,6 @@ export default class Projectile {
|
||||
}
|
||||
}
|
||||
|
||||
projectilesInVision() {
|
||||
const projectiles = this.game?.projectiles
|
||||
if (projectiles == null) { return }
|
||||
|
||||
const projectilesInVisionRange = projectiles.filter((it) => this.position.distanceTo(it.position) <= this.visionRange + it.radius)
|
||||
const projectilesInLineOfSight = projectilesInVisionRange.filter((it) => it.visibleThroughTerrain || this.isInLineOfVision(it.position))
|
||||
|
||||
return projectilesInLineOfSight.concat([this]).map((it) => it.id)
|
||||
}
|
||||
|
||||
#calculateBbox() {
|
||||
this.bbox[0] = this.position.y + this.radius
|
||||
this.bbox[1] = this.position.x + this.radius
|
||||
@@ -115,6 +101,20 @@ export default class Projectile {
|
||||
this.bbox[3] = this.position.x - this.radius
|
||||
}
|
||||
|
||||
#calculateVision() {
|
||||
const entities = this.game?.entities ?? []
|
||||
const projectiles = this.game?.projectiles ?? []
|
||||
|
||||
const entitiesInVisionRange = entities.filter((it) => it.id != this.id && it.distanceTo(this.position) <= this.visionRange + it.radius)
|
||||
const entitiesInLineOfSight = entitiesInVisionRange.filter((it) => this.isInLineOfVision(it.position))
|
||||
|
||||
const projectilesInVisionRange = projectiles.filter((it) => this.position.distanceTo(it.position) <= this.visionRange + it.radius)
|
||||
const projectilesInLineOfSight = projectilesInVisionRange.filter((it) => it.visibleThroughTerrain || this.isInLineOfVision(it.position))
|
||||
|
||||
this.#entitiesInVision = entitiesInLineOfSight.concat([this]).map((it) => it.id)
|
||||
this.#projectilesInVision = projectilesInLineOfSight.map((it) => it.id)
|
||||
}
|
||||
|
||||
#checkIfArrived() {
|
||||
if (this.destination == null) { return }
|
||||
if (!this.position.equals(this.destination)) { return }
|
||||
|
||||
Reference in New Issue
Block a user