1
0
Fork 0
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:
Robin Appelman 2017-09-02 15:26:55 +02:00
commit 32b3e41aa8
3 changed files with 78 additions and 81 deletions

View file

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

View file

@ -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) {

View file

@ -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) {