1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 00:54:14 +02:00

use map for outerMap

This commit is contained in:
Robin Appelman 2017-09-02 16:04:05 +02:00
commit 61f99b87cf
3 changed files with 7 additions and 6 deletions

View file

@ -35,7 +35,7 @@ export class Match {
public sendTables: Map<string, SendTable> = new Map(); public sendTables: Map<string, SendTable> = new Map();
public baseLineCache: Map<ServerClass, PacketEntity> = new Map(); public baseLineCache: Map<ServerClass, PacketEntity> = new Map();
public weaponMap: Map<EntityId, Weapon> = new Map(); public weaponMap: Map<EntityId, Weapon> = new Map();
public outerMap: {[outer: number]: number}; public outerMap: Map<number, EntityId> = new Map();
public teams: Map<TeamNumber, Team> = new Map(); public teams: Map<TeamNumber, Team> = new Map();
public teamEntityMap: Map<EntityId, Team>; public teamEntityMap: Map<EntityId, Team>;
public version: number; public version: number;
@ -61,7 +61,6 @@ export class Match {
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},
}; };
this.outerMap = {};
this.teamEntityMap = new Map(); this.teamEntityMap = new Map();
this.version = 0; this.version = 0;
} }

View file

@ -3,6 +3,7 @@ import {PlayerCondition} from './PlayerCondition';
import {UserInfo} from './UserInfo'; import {UserInfo} from './UserInfo';
import {Vector} from './Vector'; import {Vector} from './Vector';
import {Weapon} from './Weapon'; import {Weapon} from './Weapon';
import {EntityId} from './PacketEntity';
export enum LifeState { export enum LifeState {
ALIVE = 0, ALIVE = 0,
@ -32,7 +33,8 @@ export class Player {
get weapons(): Weapon[] { get weapons(): Weapon[] {
return this.weaponIds return this.weaponIds
.map((id) => this.match.weaponMap.get(this.match.outerMap[id]) as Weapon) .map(id => this.match.outerMap.get(id) as EntityId)
.filter((weapon: Weapon | undefined) => (typeof weapon !== 'undefined')); .filter(entityId => entityId > 0)
.map(entityId => this.match.weaponMap.get(entityId) as Weapon);
} }
} }

View file

@ -30,8 +30,8 @@ function saveEntity(packetEntity: PacketEntity, match: Match) {
function handleEntity(entity: PacketEntity, match: Match) { function handleEntity(entity: PacketEntity, match: Match) {
for (const prop of entity.props) { for (const prop of entity.props) {
if (prop.definition.ownerTableName === 'DT_AttributeContainer' && prop.definition.name === 'm_hOuter') { if (prop.definition.ownerTableName === 'DT_AttributeContainer' && prop.definition.name === 'm_hOuter') {
if (!match.outerMap[prop.value as number]) { if (!match.outerMap.has(prop.value as number)) {
match.outerMap[prop.value as number] = entity.entityIndex; match.outerMap.set(prop.value as number, entity.entityIndex);
} }
} }
} }