render optimization

This commit is contained in:
sli97
2022-12-06 23:10:03 +08:00
parent 1b215bfbb4
commit b7c95c5ca9
6 changed files with 32 additions and 20 deletions

View File

@@ -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;
}
}