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

use map for sendtables and baselinecache

This commit is contained in:
Robin Appelman 2017-09-02 15:50:25 +02:00
commit 7a316ef97f
3 changed files with 13 additions and 19 deletions

View file

@ -32,8 +32,8 @@ export class Match {
public world: World; public world: World;
public playerEntityMap: Map<EntityId, Player>; public playerEntityMap: Map<EntityId, Player>;
public entityClasses: Map<EntityId, ServerClass> = new Map(); public entityClasses: Map<EntityId, ServerClass> = new Map();
public sendTableMap: {[name: string]: SendTable}; public sendTables: Map<string, SendTable> = new Map();
public baseLineCache: {[serverClass: string]: PacketEntity}; public baseLineCache: Map<ServerClass, PacketEntity> = new Map();
public weaponMap: {[entityId: string]: Weapon}; public weaponMap: {[entityId: string]: Weapon};
public outerMap: {[outer: number]: number}; public outerMap: {[outer: number]: number};
public teams: Map<TeamNumber, Team> = new Map(); public teams: Map<TeamNumber, Team> = new Map();
@ -42,7 +42,6 @@ export class Match {
public buildings: {[entityId: string]: Building} = {}; public buildings: {[entityId: string]: Building} = {};
public playerResources: PlayerResource[] = []; public playerResources: PlayerResource[] = [];
public stringTables: StringTable[]; public stringTables: StringTable[];
public sendTables: SendTable[];
public serverClasses: ServerClass[]; public serverClasses: ServerClass[];
constructor() { constructor() {
@ -54,7 +53,6 @@ export class Match {
this.startTick = 0; this.startTick = 0;
this.intervalPerTick = 0; this.intervalPerTick = 0;
this.stringTables = []; this.stringTables = [];
this.sendTables = [];
this.serverClasses = []; this.serverClasses = [];
this.staticBaseLines = []; this.staticBaseLines = [];
this.eventDefinitions = new Map(); this.eventDefinitions = new Map();
@ -63,8 +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.sendTableMap = {};
this.baseLineCache = {};
this.weaponMap = {}; this.weaponMap = {};
this.outerMap = {}; this.outerMap = {};
this.teamEntityMap = new Map(); this.teamEntityMap = new Map();
@ -72,15 +68,10 @@ export class Match {
} }
public getSendTable(name) { public getSendTable(name) {
if (this.sendTableMap[name]) { const table = this.sendTables.get(name);
return this.sendTableMap[name]; if (table) {
}
for (const table of this.sendTables) {
if (table.name === name) {
this.sendTableMap[name] = table;
return table; return table;
} }
}
throw new Error('unknown SendTable ' + name); throw new Error('unknown SendTable ' + name);
} }

View file

@ -2,6 +2,8 @@ import {Match} from '../Data/Match';
import {DataTablePacket} from '../Data/Packet'; import {DataTablePacket} from '../Data/Packet';
export function handleDataTable(packet: DataTablePacket, match: Match) { export function handleDataTable(packet: DataTablePacket, match: Match) {
match.sendTables = packet.tables; for (const table of packet.tables) {
match.sendTables.set(table.name, table);
}
match.serverClasses = packet.serverClasses; match.serverClasses = packet.serverClasses;
} }

View file

@ -24,8 +24,9 @@ function readEnterPVS(stream: BitStream, entityId: EntityId, match: Match): Pack
const serverClass = match.serverClasses[stream.readBits(match.classBits)]; const serverClass = match.serverClasses[stream.readBits(match.classBits)];
const serial = stream.readBits(10); // unused serial number const serial = stream.readBits(10); // unused serial number
if (match.baseLineCache[serverClass.id]) { const cachedBaseLine = match.baseLineCache.get(serverClass);
const result = match.baseLineCache[serverClass.id].clone(); if (cachedBaseLine) {
const result = cachedBaseLine.clone();
result.entityIndex = entityId; result.entityIndex = entityId;
result.serialNumber = serial; result.serialNumber = serial;
return result; return result;
@ -39,7 +40,7 @@ function readEnterPVS(stream: BitStream, entityId: EntityId, match: Match): Pack
if (staticBaseLine) { if (staticBaseLine) {
staticBaseLine.index = 0; staticBaseLine.index = 0;
applyEntityUpdate(entity, sendTable, staticBaseLine); applyEntityUpdate(entity, sendTable, staticBaseLine);
match.baseLineCache[serverClass.id] = entity.clone(); match.baseLineCache.set(serverClass, entity.clone());
// if (staticBaseLine.bitsLeft > 7) { // if (staticBaseLine.bitsLeft > 7) {
// console.log(staticBaseLine.length, staticBaseLine.index); // console.log(staticBaseLine.length, staticBaseLine.index);
// throw new Error('Unexpected data left at the end of staticBaseline, ' + staticBaseLine.bitsLeft + ' bits left'); // throw new Error('Unexpected data left at the end of staticBaseline, ' + staticBaseLine.bitsLeft + ' bits left');
@ -89,7 +90,7 @@ export function ParsePacketEntities(stream: BitStream, match: Match, skip: boole
if (updatedBaseLine) { if (updatedBaseLine) {
const newBaseLine: SendProp[] = []; const newBaseLine: SendProp[] = [];
newBaseLine.concat(packetEntity.props); newBaseLine.concat(packetEntity.props);
match.baseLineCache[packetEntity.serverClass.id] = packetEntity.clone(); match.baseLineCache.set(packetEntity.serverClass, packetEntity.clone());
} }
packetEntity.inPVS = true; packetEntity.inPVS = true;
receivedEntities.push(packetEntity); receivedEntities.push(packetEntity);