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

use map for buildings

This commit is contained in:
Robin Appelman 2017-09-02 16:09:54 +02:00
commit fb54dc9b75
3 changed files with 36 additions and 54 deletions

View file

@ -20,50 +20,32 @@ import {Weapon} from './Weapon';
import {World} from './World'; import {World} from './World';
export class Match { export class Match {
public tick: number; public tick: number = 0;
public chat: any[]; public chat: any[] = [];
public users: Map<number, UserInfo>; public users: Map<number, UserInfo> = new Map();
public deaths: Death[]; public deaths: Death[] = [];
public rounds: any[]; public rounds: any[] = [];
public startTick: number; public startTick: number = 0;
public intervalPerTick: number; public intervalPerTick: number = 0;
public staticBaseLines: BitStream[]; public staticBaseLines: BitStream[] = [];
public eventDefinitions: Map<number, GameEventDefinition>; public eventDefinitions: Map<number, GameEventDefinition> = new Map();
public world: World; public world: World = {
public playerEntityMap: Map<EntityId, Player>; boundaryMin: {x: 0, y: 0, z: 0},
boundaryMax: {x: 0, y: 0, z: 0},
};
public playerEntityMap: Map<EntityId, Player> = new Map();
public entityClasses: Map<EntityId, ServerClass> = new Map(); public entityClasses: Map<EntityId, ServerClass> = new Map();
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: Map<number, EntityId> = new Map(); 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> = new Map();
public version: number; public version: number = 0;
public buildings: {[entityId: string]: Building} = {}; public buildings: Map<EntityId, Building> = new Map();
public playerResources: PlayerResource[] = []; public playerResources: PlayerResource[] = [];
public stringTables: StringTable[]; public stringTables: StringTable[] = [];
public serverClasses: ServerClass[]; public serverClasses: ServerClass[] = [];
constructor() {
this.tick = 0;
this.chat = [];
this.users = new Map();
this.deaths = [];
this.rounds = [];
this.startTick = 0;
this.intervalPerTick = 0;
this.stringTables = [];
this.serverClasses = [];
this.staticBaseLines = [];
this.eventDefinitions = new Map();
this.playerEntityMap = new Map();
this.world = {
boundaryMin: {x: 0, y: 0, z: 0},
boundaryMax: {x: 0, y: 0, z: 0},
};
this.teamEntityMap = new Map();
this.version = 0;
}
public getSendTable(name) { public getSendTable(name) {
const table = this.sendTables.get(name); const table = this.sendTables.get(name);

View file

@ -74,9 +74,9 @@ function handlePlayerSpawn(packet: GameEventPacket, match: Match) {
function handleObjectDestroyed(packet: GameEventPacket, match: Match) { function handleObjectDestroyed(packet: GameEventPacket, match: Match) {
const values = packet.event.values as ObjectDestroyedValues; const values = packet.event.values as ObjectDestroyedValues;
delete match.buildings[values.index]; match.buildings.delete(values.index);
} }
function handleRoundStart(packet: GameEventPacket, match: Match) { function handleRoundStart(packet: GameEventPacket, match: Match) {
match.buildings = {}; match.buildings.clear();
} }

View file

@ -198,8 +198,8 @@ function handleEntity(entity: PacketEntity, match: Match) {
} }
break; break;
case 'CObjectSentrygun': case 'CObjectSentrygun':
if (!match.buildings[entity.entityIndex]) { if (!match.buildings.has(entity.entityIndex)) {
match.buildings[entity.entityIndex] = { match.buildings.set(entity.entityIndex, {
type: 'sentry', type: 'sentry',
ammoRockets: 0, ammoRockets: 0,
ammoShells: 0, ammoShells: 0,
@ -216,9 +216,9 @@ function handleEntity(entity: PacketEntity, match: Match) {
isMini: false, isMini: false,
team: 0, team: 0,
angle: 0, angle: 0,
}; });
} }
const sentry = match.buildings[entity.entityIndex] as Sentry; const sentry = match.buildings.get(entity.entityIndex) as Sentry;
for (const prop of entity.props) { for (const prop of entity.props) {
const propName = prop.definition.ownerTableName + '.' + prop.definition.name; const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
applyBuildingProp(sentry, prop, propName); applyBuildingProp(sentry, prop, propName);
@ -247,12 +247,12 @@ function handleEntity(entity: PacketEntity, match: Match) {
} }
} }
if (entity.pvs & PVS.LEAVE) { if (entity.pvs & PVS.LEAVE) {
delete match.buildings[entity.entityIndex]; match.buildings.delete(entity.entityIndex);
} }
break; break;
case 'CObjectDispenser': case 'CObjectDispenser':
if (!match.buildings[entity.entityIndex]) { if (!match.buildings.has(entity.entityIndex)) {
match.buildings[entity.entityIndex] = { match.buildings.set(entity.entityIndex, {
type: 'dispenser', type: 'dispenser',
builder: 0, builder: 0,
health: 0, health: 0,
@ -265,9 +265,9 @@ function handleEntity(entity: PacketEntity, match: Match) {
healing: [], healing: [],
metal: 0, metal: 0,
angle: 0, angle: 0,
}; });
} }
const dispenser = match.buildings[entity.entityIndex] as Dispenser; const dispenser = match.buildings.get(entity.entityIndex) as Dispenser;
for (const prop of entity.props) { for (const prop of entity.props) {
const propName = prop.definition.ownerTableName + '.' + prop.definition.name; const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
applyBuildingProp(dispenser, prop, propName); applyBuildingProp(dispenser, prop, propName);
@ -281,12 +281,12 @@ function handleEntity(entity: PacketEntity, match: Match) {
} }
} }
if (entity.pvs & PVS.LEAVE) { if (entity.pvs & PVS.LEAVE) {
delete match.buildings[entity.entityIndex]; match.buildings.delete(entity.entityIndex);
} }
break; break;
case 'CObjectTeleporter': case 'CObjectTeleporter':
if (!match.buildings[entity.entityIndex]) { if (!match.buildings.has(entity.entityIndex)) {
match.buildings[entity.entityIndex] = { match.buildings.set(entity.entityIndex, {
type: 'teleporter', type: 'teleporter',
builder: 0, builder: 0,
health: 0, health: 0,
@ -303,9 +303,9 @@ function handleEntity(entity: PacketEntity, match: Match) {
timesUsed: 0, timesUsed: 0,
angle: 0, angle: 0,
yawToExit: 0, yawToExit: 0,
}; });
} }
const teleporter = match.buildings[entity.entityIndex] as Teleporter; const teleporter = match.buildings.get(entity.entityIndex) as Teleporter;
for (const prop of entity.props) { for (const prop of entity.props) {
const propName = prop.definition.ownerTableName + '.' + prop.definition.name; const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
applyBuildingProp(teleporter, prop, propName); applyBuildingProp(teleporter, prop, propName);
@ -331,7 +331,7 @@ function handleEntity(entity: PacketEntity, match: Match) {
} }
} }
if (entity.pvs & PVS.LEAVE) { if (entity.pvs & PVS.LEAVE) {
delete match.buildings[entity.entityIndex]; match.buildings.delete(entity.entityIndex);
} }
break; break;
case 'CTFPlayerResource': case 'CTFPlayerResource':