mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +02:00
cache entity baseline
This commit is contained in:
parent
5fcbbe540e
commit
255602d1e2
6 changed files with 33 additions and 43 deletions
|
|
@ -27,7 +27,6 @@ export class Match {
|
|||
stringTables: StringTable[];
|
||||
serverClasses: ServerClass[];
|
||||
sendTables: SendTable[];
|
||||
instanceBaselines: SendProp[][][];
|
||||
staticBaseLines: BitStream[];
|
||||
eventDefinitions: GameEventDefinitionMap;
|
||||
world: World;
|
||||
|
|
@ -47,7 +46,6 @@ export class Match {
|
|||
this.stringTables = [];
|
||||
this.sendTables = [];
|
||||
this.serverClasses = [];
|
||||
this.instanceBaselines = [[], []];
|
||||
this.staticBaseLines = [];
|
||||
this.eventDefinitions = {};
|
||||
this.players = [];
|
||||
|
|
|
|||
|
|
@ -16,15 +16,13 @@ export class PacketEntity {
|
|||
entityIndex: number;
|
||||
props: SendProp[];
|
||||
inPVS: boolean;
|
||||
updatedProps: SendProp[];
|
||||
|
||||
constructor(serverClass: ServerClass, entityIndex: number, pvs: PVS) {
|
||||
this.serverClass = serverClass;
|
||||
this.entityIndex = entityIndex;
|
||||
this.props = [];
|
||||
this.inPVS = false;
|
||||
this.updatedProps = [];
|
||||
this.pvs = pvs;
|
||||
this.serverClass = serverClass;
|
||||
this.entityIndex = entityIndex;
|
||||
this.props = [];
|
||||
this.inPVS = false;
|
||||
this.pvs = pvs;
|
||||
}
|
||||
|
||||
getPropByDefinition(definition: SendPropDefinition) {
|
||||
|
|
@ -44,5 +42,13 @@ export class PacketEntity {
|
|||
}
|
||||
throw new Error('Property not found in entity');
|
||||
}
|
||||
|
||||
clone(): PacketEntity {
|
||||
const result = new PacketEntity(this.serverClass, this.entityIndex, this.pvs);
|
||||
for (const prop of this.props) {
|
||||
result.props.push(prop.clone());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export class SendProp {
|
|||
|
||||
clone():SendProp {
|
||||
const prop = new SendProp(this.definition);
|
||||
prop.value = clone(this.value);
|
||||
prop.value = clone(this.value, false);
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
match.players.push(player);
|
||||
}
|
||||
|
||||
for (const prop of entity.updatedProps) {
|
||||
for (const prop of entity.props) {
|
||||
const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
|
||||
// console.log(propName, prop.value);
|
||||
switch (propName) {
|
||||
|
|
@ -75,5 +75,4 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
}
|
||||
|
||||
}
|
||||
entity.updatedProps = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ export function applyEntityUpdate(entity: PacketEntity, sendTable: SendTable, st
|
|||
|
||||
const prop = existingProp ? existingProp : new SendProp(propDefinition);
|
||||
prop.value = SendPropParser.decode(propDefinition, stream);
|
||||
entity.updatedProps.push(prop);
|
||||
lastProps.push(prop);
|
||||
|
||||
if (!existingProp) {
|
||||
|
|
|
|||
|
|
@ -23,37 +23,35 @@ function readPVSType(stream: BitStream): PVS {
|
|||
return pvs;
|
||||
}
|
||||
|
||||
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): PacketEntity {
|
||||
const baseLineCache: {[serverClass: string]: PacketEntity} = {};
|
||||
|
||||
function readEnterPVS(stream: BitStream, entityId: number, match: Match): PacketEntity {
|
||||
// https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs#L198
|
||||
const serverClass = match.serverClasses[stream.readBits(match.classBits)];
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
const serialNumber = stream.readBits(10); // unused it seems
|
||||
if (!sendTable) {
|
||||
throw new Error('Unknown SendTable for serverclass');
|
||||
}
|
||||
const serverClass = match.serverClasses[stream.readBits(match.classBits)];
|
||||
stream.readBits(10); // unused serial number
|
||||
|
||||
const entity = new PacketEntity(serverClass, entityId, PVS.ENTER);
|
||||
|
||||
const decodedBaseLine = match.instanceBaselines[baseLine][entityId];
|
||||
if (decodedBaseLine) {
|
||||
for (let i = 0; i < decodedBaseLine.length; i++) {
|
||||
const newProp = decodedBaseLine[i];
|
||||
if (!entity.getPropByDefinition(newProp.definition)) {
|
||||
entity.props.push(newProp.clone());
|
||||
}
|
||||
}
|
||||
if (baseLineCache[serverClass.id]) {
|
||||
const result = baseLineCache[serverClass.id].clone();
|
||||
result.entityIndex = entityId;
|
||||
return result;
|
||||
} else {
|
||||
const entity = new PacketEntity(serverClass, entityId, PVS.ENTER);
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
if (!sendTable) {
|
||||
throw new Error('Unknown SendTable for serverclass');
|
||||
}
|
||||
const staticBaseLine = match.staticBaseLines[serverClass.id];
|
||||
if (staticBaseLine) {
|
||||
staticBaseLine.index = 0;
|
||||
applyEntityUpdate(entity, sendTable, staticBaseLine);
|
||||
baseLineCache[serverClass.id] = 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');
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
function getPacketEntityForExisting(entityId: number, match: Match, pvs: PVS) {
|
||||
|
|
@ -79,29 +77,19 @@ export function PacketEntities(stream: BitStream, match: Match): PacketEntitiesP
|
|||
const end = stream.index + length;
|
||||
let entityId = -1;
|
||||
|
||||
if (updatedBaseLine) {
|
||||
if (baseLine === 0) {
|
||||
match.instanceBaselines[1] = match.instanceBaselines[0];
|
||||
match.instanceBaselines[0] = new Array((1 << 11)); // array of SendPropDefinition with size MAX_EDICTS
|
||||
} else {
|
||||
match.instanceBaselines[0] = match.instanceBaselines[1];
|
||||
match.instanceBaselines[1] = new Array((1 << 11)); // array of SendPropDefinition with size MAX_EDICTS
|
||||
}
|
||||
}
|
||||
|
||||
const receivedEntities: PacketEntity[] = [];
|
||||
for (let i = 0; i < updatedEntries; i++) {
|
||||
const diff = readUBitVar(stream);
|
||||
entityId += 1 + diff;
|
||||
const pvs = readPVSType(stream);
|
||||
if (pvs === PVS.ENTER) {
|
||||
const packetEntity = readEnterPVS(stream, entityId, match, baseLine);
|
||||
const packetEntity = readEnterPVS(stream, entityId, match);
|
||||
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
|
||||
|
||||
if (updatedBaseLine) {
|
||||
const newBaseLine: SendProp[] = [];
|
||||
newBaseLine.concat(packetEntity.props);
|
||||
match.instanceBaselines[baseLine][entityId] = newBaseLine;
|
||||
baseLineCache[packetEntity.serverClass.id] = packetEntity.clone();
|
||||
}
|
||||
packetEntity.inPVS = true;
|
||||
receivedEntities.push(packetEntity);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue