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 staticBaseLines: BitStream[];
|
||||||
public eventDefinitions: Map<number, GameEventDefinition>;
|
public eventDefinitions: Map<number, GameEventDefinition>;
|
||||||
public world: World;
|
public world: World;
|
||||||
public players: Player[];
|
public players: Map<number, Player>;
|
||||||
public playerMap: {[entityId: number]: Player};
|
|
||||||
public entityClasses: {[entityId: string]: ServerClass};
|
public entityClasses: {[entityId: string]: ServerClass};
|
||||||
public sendTableMap: {[name: string]: SendTable};
|
public sendTableMap: {[name: string]: SendTable};
|
||||||
public baseLineCache: {[serverClass: string]: PacketEntity};
|
public baseLineCache: {[serverClass: string]: PacketEntity};
|
||||||
|
|
@ -59,8 +58,7 @@ export class Match {
|
||||||
this.serverClasses = [];
|
this.serverClasses = [];
|
||||||
this.staticBaseLines = [];
|
this.staticBaseLines = [];
|
||||||
this.eventDefinitions = new Map();
|
this.eventDefinitions = new Map();
|
||||||
this.players = [];
|
this.players = new Map();
|
||||||
this.playerMap = {};
|
|
||||||
this.world = {
|
this.world = {
|
||||||
boundaryMin: {x: 0, y: 0, z: 0},
|
boundaryMin: {x: 0, y: 0, z: 0},
|
||||||
boundaryMax: {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 {
|
public getPlayerByUserId(userId: number): Player {
|
||||||
for (const player of this.players) {
|
for (const player of this.players.values()) {
|
||||||
if (player.user.userId === userId) {
|
if (player.user.userId === userId) {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ function handlePlayerSpawn(packet: GameEventPacket, match: Match) {
|
||||||
const values = packet.event.values as PlayerSpawnEventValues;
|
const values = packet.event.values as PlayerSpawnEventValues;
|
||||||
const userId = values.userid;
|
const userId = values.userid;
|
||||||
const userState = match.getUserInfo(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';
|
userState.team = values.team === 2 ? 'red' : 'blue';
|
||||||
const classId = values.class;
|
const classId = values.class;
|
||||||
if (player) {
|
if (player) {
|
||||||
|
|
|
||||||
|
|
@ -79,12 +79,11 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
||||||
* "DT_TFPlayerShared.m_flCloakMeter": 100,
|
* "DT_TFPlayerShared.m_flCloakMeter": 100,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const player: Player = (match.playerMap[entity.entityIndex]) ?
|
const player: Player = (match.players.has(entity.entityIndex)) ?
|
||||||
match.playerMap[entity.entityIndex] :
|
match.players.get(entity.entityIndex) as Player :
|
||||||
new Player(match, match.getUserInfoForEntity(entity));
|
new Player(match, match.getUserInfoForEntity(entity));
|
||||||
if (!match.playerMap[entity.entityIndex]) {
|
if (!match.players.has(entity.entityIndex)) {
|
||||||
match.playerMap[entity.entityIndex] = player;
|
match.players.set(entity.entityIndex, player);
|
||||||
match.players.push(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const prop of entity.props) {
|
for (const prop of entity.props) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue