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

More precise baseline handling wip

This commit is contained in:
Robin Appelman 2017-09-16 16:10:52 +02:00
commit 357b725994
10 changed files with 90 additions and 53 deletions

View file

@ -23,6 +23,7 @@ import {Chat} from './Chat';
import {Packet} from './Packet';
import {GameEventType} from './GameEventTypes';
import {ParserState} from './ParserState';
import {SendProp} from './SendProp';
export class Match implements ParserState {
public tick: number = 0;
@ -33,6 +34,7 @@ export class Match implements ParserState {
public startTick: number = 0;
public intervalPerTick: number = 0;
public staticBaseLines: Map<ServerClassId, BitStream> = new Map();
public staticBaselineCache: Map<ServerClassId, SendProp[]> = new Map();
public eventDefinitions: Map<number, GameEventDefinition<GameEventType>> = new Map();
public world: World = {
boundaryMin: {x: 0, y: 0, z: 0},
@ -41,7 +43,7 @@ export class Match implements ParserState {
public playerEntityMap: Map<EntityId, Player> = new Map();
public entityClasses: Map<EntityId, ServerClass> = new Map();
public sendTables: Map<SendTableName, SendTable> = new Map();
public baseLineCache: Map<ServerClass, PacketEntity> = new Map();
public instanceBaselines: [Map<EntityId, SendProp[]>, Map<EntityId, SendProp[]>] = [new Map(), new Map()];
public weaponMap: Map<EntityId, Weapon> = new Map();
public outerMap: Map<number, EntityId> = new Map();
public teams: Map<TeamNumber, Team> = new Map();

View file

@ -1,4 +1,4 @@
import {SendProp} from './SendProp';
import {SendProp, SendPropValue} from './SendProp';
import {SendPropDefinition} from './SendPropDefinition';
import {ServerClass} from './ServerClass';
@ -28,15 +28,19 @@ export class PacketEntity {
this.pvs = pvs;
}
public getPropByDefinition(definition: SendPropDefinition) {
for (const prop of this.props) {
if (prop.definition.fullName === definition.fullName) {
private static getPropByFullName(props: SendProp[], fullName: string): SendProp | null {
for (const prop of props) {
if (prop.definition.fullName === fullName) {
return prop;
}
}
return null;
}
public getPropByDefinition(definition: SendPropDefinition) {
return PacketEntity.getPropByFullName(this.props, definition.fullName);
}
public getProperty(originTable: string, name: string) {
for (const prop of this.props) {
if (prop.definition.ownerTableName === originTable && prop.definition.name === name) {
@ -51,6 +55,9 @@ export class PacketEntity {
for (const prop of this.props) {
result.props.push(prop.clone());
}
result.serialNumber = this.serialNumber;
result.delay = this.delay;
result.inPVS = this.inPVS;
return result;
}
@ -65,10 +72,15 @@ export class PacketEntity {
}
}
public diffFromBaseLine(baseline: PacketEntity): SendProp[] {
public diffFromBaseLine(baselineProps: SendProp[]): SendProp[] {
return this.props.filter(prop => {
const baseProp = baseline.getPropByDefinition(prop.definition);
const baseProp = PacketEntity.getPropByFullName(baselineProps, prop.definition.fullName);
return (!baseProp || prop.value !== baseProp.value);
});
}
public getPropValue(fullName: string): SendPropValue | null {
const prop = PacketEntity.getPropByFullName(this.props, fullName);
return prop ? prop.value : null;
}
}

View file

@ -5,16 +5,18 @@ import {SendTable, SendTableName} from './SendTable';
import {ServerClass, ServerClassId} from './ServerClass';
import {StringTable} from './StringTable';
import {GameEventType} from './GameEventTypes';
import {SendProp} from './SendProp';
export interface ParserState {
staticBaseLines: Map<ServerClassId, BitStream>;
staticBaselineCache: Map<ServerClassId, SendProp[]>;
eventDefinitions: Map<number, GameEventDefinition<GameEventType>>;
entityClasses: Map<EntityId, ServerClass>;
sendTables: Map<SendTableName, SendTable>;
version: number;
stringTables: StringTable[];
serverClasses: ServerClass[];
baseLineCache: Map<ServerClass, PacketEntity>;
instanceBaselines: [Map<EntityId, SendProp[]>, Map<EntityId, SendProp[]>];
}
export function getClassBits(state: ParserState) {
@ -32,13 +34,14 @@ export function getSendTable(state: ParserState, dataTable: string): SendTable {
export function createParserState(): ParserState {
return {
staticBaseLines: new Map(),
staticBaselineCache: new Map(),
eventDefinitions: new Map(),
entityClasses: new Map(),
sendTables: new Map(),
version: 0,
stringTables: [],
serverClasses: [],
baseLineCache: new Map()
instanceBaselines: [new Map(), new Map()]
};
}