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

@@ -1,4 +1,4 @@
import { Node, Prefab, SpriteFrame } from 'cc'
import { Node, Prefab, SpriteFrame, clamp } from 'cc'
import Singleton from '../Base/Singleton'
import { EntityTypeEnum, IBullet, IClientInput, InputTypeEnum, IRoom, IState, toFixed } from '../Common'
import { ActorManager } from '../Entity/Actor/ActorManager'
@@ -84,6 +84,10 @@ export default class DataManager extends Singleton {
player.position.x += toFixed(x * PLAYER_SPEED * dt)
player.position.y += toFixed(y * PLAYER_SPEED * dt)
player.position.x = clamp(player.position.x, -this.mapSize.x / 2, this.mapSize.x / 2)
player.position.y = clamp(player.position.y, -this.mapSize.y / 2, this.mapSize.y / 2)
player.direction = { x, y }
break
}

View File

@@ -91,8 +91,10 @@ export default class NetworkManager extends Singleton {
})
}
sendMsg<T extends keyof IModel['msg']>(name: T, data: IModel['msg'][T]) {
async sendMsg<T extends keyof IModel['msg']>(name: T, data: IModel['msg'][T]) {
const view = binaryEncode(name, data)
let networkLag = parseInt(new URLSearchParams(location.search).get('lag') || '0') || 0;
await new Promise((r) => setTimeout(r, networkLag))
this.ws.send(view.buffer)
}