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:
parent
d5173b4548
commit
7a316ef97f
3 changed files with 13 additions and 19 deletions
|
|
@ -32,8 +32,8 @@ export class Match {
|
|||
public world: World;
|
||||
public playerEntityMap: Map<EntityId, Player>;
|
||||
public entityClasses: Map<EntityId, ServerClass> = new Map();
|
||||
public sendTableMap: {[name: string]: SendTable};
|
||||
public baseLineCache: {[serverClass: string]: PacketEntity};
|
||||
public sendTables: Map<string, SendTable> = new Map();
|
||||
public baseLineCache: Map<ServerClass, PacketEntity> = new Map();
|
||||
public weaponMap: {[entityId: string]: Weapon};
|
||||
public outerMap: {[outer: number]: number};
|
||||
public teams: Map<TeamNumber, Team> = new Map();
|
||||
|
|
@ -42,7 +42,6 @@ export class Match {
|
|||
public buildings: {[entityId: string]: Building} = {};
|
||||
public playerResources: PlayerResource[] = [];
|
||||
public stringTables: StringTable[];
|
||||
public sendTables: SendTable[];
|
||||
public serverClasses: ServerClass[];
|
||||
|
||||
constructor() {
|
||||
|
|
@ -54,7 +53,6 @@ export class Match {
|
|||
this.startTick = 0;
|
||||
this.intervalPerTick = 0;
|
||||
this.stringTables = [];
|
||||
this.sendTables = [];
|
||||
this.serverClasses = [];
|
||||
this.staticBaseLines = [];
|
||||
this.eventDefinitions = new Map();
|
||||
|
|
@ -63,8 +61,6 @@ export class Match {
|
|||
boundaryMin: {x: 0, y: 0, z: 0},
|
||||
boundaryMax: {x: 0, y: 0, z: 0},
|
||||
};
|
||||
this.sendTableMap = {};
|
||||
this.baseLineCache = {};
|
||||
this.weaponMap = {};
|
||||
this.outerMap = {};
|
||||
this.teamEntityMap = new Map();
|
||||
|
|
@ -72,14 +68,9 @@ export class Match {
|
|||
}
|
||||
|
||||
public getSendTable(name) {
|
||||
if (this.sendTableMap[name]) {
|
||||
return this.sendTableMap[name];
|
||||
}
|
||||
for (const table of this.sendTables) {
|
||||
if (table.name === name) {
|
||||
this.sendTableMap[name] = table;
|
||||
return table;
|
||||
}
|
||||
const table = this.sendTables.get(name);
|
||||
if (table) {
|
||||
return table;
|
||||
}
|
||||
throw new Error('unknown SendTable ' + name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import {Match} from '../Data/Match';
|
|||
import {DataTablePacket} from '../Data/Packet';
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ function readEnterPVS(stream: BitStream, entityId: EntityId, match: Match): Pack
|
|||
const serverClass = match.serverClasses[stream.readBits(match.classBits)];
|
||||
const serial = stream.readBits(10); // unused serial number
|
||||
|
||||
if (match.baseLineCache[serverClass.id]) {
|
||||
const result = match.baseLineCache[serverClass.id].clone();
|
||||
const cachedBaseLine = match.baseLineCache.get(serverClass);
|
||||
if (cachedBaseLine) {
|
||||
const result = cachedBaseLine.clone();
|
||||
result.entityIndex = entityId;
|
||||
result.serialNumber = serial;
|
||||
return result;
|
||||
|
|
@ -39,7 +40,7 @@ function readEnterPVS(stream: BitStream, entityId: EntityId, match: Match): Pack
|
|||
if (staticBaseLine) {
|
||||
staticBaseLine.index = 0;
|
||||
applyEntityUpdate(entity, sendTable, staticBaseLine);
|
||||
match.baseLineCache[serverClass.id] = entity.clone();
|
||||
match.baseLineCache.set(serverClass, entity.clone());
|
||||
// if (staticBaseLine.bitsLeft > 7) {
|
||||
// console.log(staticBaseLine.length, staticBaseLine.index);
|
||||
// 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) {
|
||||
const newBaseLine: SendProp[] = [];
|
||||
newBaseLine.concat(packetEntity.props);
|
||||
match.baseLineCache[packetEntity.serverClass.id] = packetEntity.clone();
|
||||
match.baseLineCache.set(packetEntity.serverClass, packetEntity.clone());
|
||||
}
|
||||
packetEntity.inPVS = true;
|
||||
receivedEntities.push(packetEntity);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue