render optimization
This commit is contained in:
@@ -7,6 +7,7 @@ export default class Room {
|
||||
id: number
|
||||
players: Set<Player> = new Set()
|
||||
lastSyncTime?: number
|
||||
timers: NodeJS.Timer[] = []
|
||||
|
||||
private inputs: Array<IClientInput> = []
|
||||
|
||||
@@ -30,6 +31,7 @@ export default class Room {
|
||||
player.rid = -1
|
||||
this.players.delete(player)
|
||||
if (!this.players.size) {
|
||||
this.timers.forEach(t => clearInterval(t))
|
||||
RoomManager.Instance.closeRoom(this.id)
|
||||
}
|
||||
}
|
||||
@@ -57,9 +59,9 @@ export default class Room {
|
||||
y: 0
|
||||
},
|
||||
hp: 100,
|
||||
type: EntityTypeEnum.Actor1,
|
||||
weaponType: EntityTypeEnum.Weapon1,
|
||||
bulletType: EntityTypeEnum.Bullet1,
|
||||
type: EntityTypeEnum.Actor2,
|
||||
weaponType: EntityTypeEnum.Weapon2,
|
||||
bulletType: EntityTypeEnum.Bullet2,
|
||||
})),
|
||||
bullets: [],
|
||||
nextBulletId: 1
|
||||
@@ -71,12 +73,13 @@ export default class Room {
|
||||
})
|
||||
}
|
||||
this.listenPlayer()
|
||||
setInterval(() => {
|
||||
let t1 = setInterval(() => {
|
||||
this.syncInput()
|
||||
}, 100)
|
||||
setInterval(() => {
|
||||
let t2 = setInterval(() => {
|
||||
this.timePast()
|
||||
}, 16)
|
||||
this.timers = [t1, t2]
|
||||
}
|
||||
|
||||
listenPlayer() {
|
||||
@@ -105,6 +108,5 @@ export default class Room {
|
||||
dt: toFixed(dt)
|
||||
})
|
||||
this.lastSyncTime = now;
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user