mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
use map for players
This commit is contained in:
parent
c41928c97a
commit
32b3e41aa8
3 changed files with 78 additions and 81 deletions
|
|
@ -30,8 +30,7 @@ export class Match {
|
|||
public staticBaseLines: BitStream[];
|
||||
public eventDefinitions: Map<number, GameEventDefinition>;
|
||||
public world: World;
|
||||
public players: Player[];
|
||||
public playerMap: {[entityId: number]: Player};
|
||||
public players: Map<number, Player>;
|
||||
public entityClasses: {[entityId: string]: ServerClass};
|
||||
public sendTableMap: {[name: string]: SendTable};
|
||||
public baseLineCache: {[serverClass: string]: PacketEntity};
|
||||
|
|
@ -59,8 +58,7 @@ export class Match {
|
|||
this.serverClasses = [];
|
||||
this.staticBaseLines = [];
|
||||
this.eventDefinitions = new Map();
|
||||
this.players = [];
|
||||
this.playerMap = {};
|
||||
this.players = new Map();
|
||||
this.world = {
|
||||
boundaryMin: {x: 0, y: 0, z: 0},
|
||||
boundaryMax: {x: 0, y: 0, z: 0},
|
||||
|
|
@ -192,7 +190,7 @@ export class Match {
|
|||
}
|
||||
|
||||
public getPlayerByUserId(userId: number): Player {
|
||||
for (const player of this.players) {
|
||||
for (const player of this.players.values()) {
|
||||
if (player.user.userId === userId) {
|
||||
return player;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ function handlePlayerSpawn(packet: GameEventPacket, match: Match) {
|
|||
const values = packet.event.values as PlayerSpawnEventValues;
|
||||
const userId = values.userid;
|
||||
const userState = match.getUserInfo(userId);
|
||||
const player = match.playerMap[userState.entityId];
|
||||
const player = match.players.get(userState.entityId);
|
||||
userState.team = values.team === 2 ? 'red' : 'blue';
|
||||
const classId = values.class;
|
||||
if (player) {
|
||||
|
|
|
|||
|
|
@ -79,12 +79,11 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
* "DT_TFPlayerShared.m_flCloakMeter": 100,
|
||||
*/
|
||||
|
||||
const player: Player = (match.playerMap[entity.entityIndex]) ?
|
||||
match.playerMap[entity.entityIndex] :
|
||||
const player: Player = (match.players.has(entity.entityIndex)) ?
|
||||
match.players.get(entity.entityIndex) as Player :
|
||||
new Player(match, match.getUserInfoForEntity(entity));
|
||||
if (!match.playerMap[entity.entityIndex]) {
|
||||
match.playerMap[entity.entityIndex] = player;
|
||||
match.players.push(player);
|
||||
if (!match.players.has(entity.entityIndex)) {
|
||||
match.players.set(entity.entityIndex, player);
|
||||
}
|
||||
|
||||
for (const prop of entity.props) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue