mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
only apply updates for entities from the current packet
This commit is contained in:
parent
641f5419df
commit
7cb74d93de
8 changed files with 46 additions and 50 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import {Entity} from "./Entity";
|
||||
import {PacketEntity} from "./PacketEntity";
|
||||
import {ServerClass} from "./ServerClass";
|
||||
import {SendTable} from "./SendTable";
|
||||
import {StringTable} from "./StringTable";
|
||||
|
|
@ -22,7 +22,7 @@ export class Match {
|
|||
rounds: any[];
|
||||
startTick: number;
|
||||
intervalPerTick: number;
|
||||
entities: (Entity|null)[];
|
||||
packetEntities: (PacketEntity|null)[];
|
||||
stringTables: StringTable[];
|
||||
serverClasses: ServerClass[];
|
||||
sendTables: SendTable[];
|
||||
|
|
@ -41,11 +41,11 @@ export class Match {
|
|||
this.rounds = [];
|
||||
this.startTick = 0;
|
||||
this.intervalPerTick = 0;
|
||||
this.entities = [];
|
||||
this.packetEntities = [];
|
||||
this.stringTables = [];
|
||||
this.sendTables = [];
|
||||
this.serverClasses = [];
|
||||
this.entities = [];
|
||||
this.packetEntities = [];
|
||||
this.instanceBaselines = [[], []];
|
||||
this.staticBaseLines = [];
|
||||
this.eventDefinitions = {};
|
||||
|
|
@ -147,7 +147,7 @@ export class Match {
|
|||
return this.users[userId];
|
||||
}
|
||||
|
||||
getUserInfoForEntity(entity: Entity): UserInfo {
|
||||
getUserInfoForEntity(entity: PacketEntity): UserInfo {
|
||||
for (const id of Object.keys(this.users)) {
|
||||
const user = this.users[id];
|
||||
if (user && user.entityId === entity.entityIndex) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {StringTable} from "./StringTable";
|
||||
import {Vector} from "./Vector";
|
||||
import {GameEvent} from "./GameEvent";
|
||||
import {Entity} from "./Entity";
|
||||
import {PacketEntity} from "./PacketEntity";
|
||||
|
||||
export interface StringTablePacket {
|
||||
packetType: 'stringTable';
|
||||
|
|
@ -46,6 +46,7 @@ export interface GameEventListPacket {
|
|||
|
||||
export interface PacketEntitiesPacket {
|
||||
packetType: 'packetEntities';
|
||||
entities: PacketEntity[];
|
||||
}
|
||||
|
||||
export interface ParseSoundsPacket {
|
||||
|
|
@ -62,7 +63,7 @@ export interface SetConVarPacket {
|
|||
|
||||
export interface TempEntitiesPacket {
|
||||
packetType: 'tempEntities';
|
||||
entities: Entity[];
|
||||
entities: PacketEntity[];
|
||||
}
|
||||
|
||||
export interface SayText2Packet {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import {ServerClass} from "./ServerClass";
|
|||
import {SendTable} from "./SendTable";
|
||||
import {SendProp} from "./SendProp";
|
||||
import {SendPropDefinition} from "./SendPropDefinition";
|
||||
export class Entity {
|
||||
export class PacketEntity {
|
||||
serverClass: ServerClass;
|
||||
sendTable: SendTable;
|
||||
entityIndex: number;
|
||||
|
|
@ -1,18 +1,16 @@
|
|||
import {PacketEntitiesPacket} from "../Data/Packet";
|
||||
import {Match} from "../Data/Match";
|
||||
import {Entity} from "../Data/Entity";
|
||||
import {PacketEntity} from "../Data/PacketEntity";
|
||||
import {Vector} from "../Data/Vector";
|
||||
import {Player} from "../Data/Player";
|
||||
|
||||
export function handlePacketEntities(packet: PacketEntitiesPacket, match: Match) {
|
||||
for (const entity of match.entities) {
|
||||
if (entity) {
|
||||
handleEntity(entity, match);
|
||||
}
|
||||
for (const entity of packet.entities) {
|
||||
handleEntity(entity, match);
|
||||
}
|
||||
}
|
||||
|
||||
function handleEntity(entity: Entity, match: Match) {
|
||||
function handleEntity(entity: PacketEntity, match: Match) {
|
||||
switch (entity.serverClass.name) {
|
||||
case 'CWorld':
|
||||
match.world.boundaryMin = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMins').value;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
import {Entity} from "../Data/Entity";
|
||||
import {PacketEntity} from "../Data/PacketEntity";
|
||||
import {BitStream} from "bit-buffer";
|
||||
import {SendProp} from "../Data/SendProp";
|
||||
import {SendPropParser} from "./SendPropParser";
|
||||
import {readUBitVar} from "./readBitVar";
|
||||
import {SendTable} from "../Data/SendTable";
|
||||
|
||||
export function applyEntityUpdate(entity: Entity, stream: BitStream, sendTable?: SendTable): Entity {
|
||||
if (!sendTable) {
|
||||
sendTable = entity.sendTable;
|
||||
}
|
||||
export function applyEntityUpdate(entity: PacketEntity, sendTable: SendTable, stream: BitStream): PacketEntity {
|
||||
let index = -1;
|
||||
const allProps = sendTable.flattenedProps;
|
||||
let lastProps:SendProp[] = [];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {Entity} from '../../Data/Entity';
|
||||
import {PacketEntity} from '../../Data/PacketEntity';
|
||||
import {SendProp} from '../../Data/SendProp';
|
||||
import {PacketEntitiesPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
|
|
@ -30,19 +30,16 @@ function readPVSType(stream: BitStream): PVS {
|
|||
return pvs;
|
||||
}
|
||||
|
||||
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): Entity {
|
||||
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): PacketEntity {
|
||||
// https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs#L198
|
||||
const serverClass = match.serverClasses[stream.readBits(match.classBits)];
|
||||
const serverClass = match.serverClasses[stream.readBits(match.classBits)];
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
const serialNumber = stream.readBits(10);
|
||||
if (!sendTable) {
|
||||
throw new Error('Unknown SendTable for serverclass');
|
||||
}
|
||||
|
||||
// if (match.entities[entityId]) {
|
||||
// console.log('overwriting entity');
|
||||
// }
|
||||
const entity = new Entity(serverClass, sendTable, entityId, serialNumber);
|
||||
const entity = new PacketEntity(serverClass, sendTable, entityId, serialNumber);
|
||||
|
||||
const decodedBaseLine = match.instanceBaselines[baseLine][entityId];
|
||||
if (decodedBaseLine) {
|
||||
|
|
@ -56,7 +53,7 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLin
|
|||
const staticBaseLine = match.staticBaseLines[serverClass.id];
|
||||
if (staticBaseLine) {
|
||||
staticBaseLine.index = 0;
|
||||
applyEntityUpdate(entity, staticBaseLine, sendTable);
|
||||
applyEntityUpdate(entity, sendTable, staticBaseLine);
|
||||
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');
|
||||
|
|
@ -68,7 +65,7 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLin
|
|||
|
||||
function readLeavePVS(match, entityId, shouldDelete) {
|
||||
if (shouldDelete) {
|
||||
match.entities[entityId] = null;
|
||||
match.packetEntities[entityId] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,14 +94,15 @@ export function PacketEntities(stream: BitStream, match: Match): PacketEntitiesP
|
|||
}
|
||||
}
|
||||
|
||||
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 entity = readEnterPVS(stream, entityId, match, baseLine);
|
||||
applyEntityUpdate(entity, stream);
|
||||
match.entities[entityId] = entity;
|
||||
applyEntityUpdate(entity, entity.sendTable, stream);
|
||||
match.packetEntities[entityId] = entity;
|
||||
|
||||
if (updatedBaseLine) {
|
||||
const newBaseLine: SendProp[] = [];
|
||||
|
|
@ -112,16 +110,18 @@ export function PacketEntities(stream: BitStream, match: Match): PacketEntitiesP
|
|||
match.instanceBaselines[baseLine][entityId] = newBaseLine;
|
||||
}
|
||||
entity.inPVS = true;
|
||||
receivedEntities.push(entity);
|
||||
} else if (pvs === PVS.PRESERVE) {
|
||||
const entity = match.entities[entityId];
|
||||
const entity = match.packetEntities[entityId];
|
||||
if (entity) {
|
||||
applyEntityUpdate(entity, stream);
|
||||
applyEntityUpdate(entity, entity.sendTable, stream);
|
||||
receivedEntities.push(entity);
|
||||
} else {
|
||||
console.log(entityId, match.entities.length);
|
||||
console.log(entityId, match.packetEntities.length);
|
||||
throw new Error("unknown entity");
|
||||
}
|
||||
} else {
|
||||
const entity = match.entities[entityId];
|
||||
const entity = match.packetEntities[entityId];
|
||||
if (entity) {
|
||||
entity.inPVS = false;
|
||||
}
|
||||
|
|
@ -131,13 +131,14 @@ export function PacketEntities(stream: BitStream, match: Match): PacketEntitiesP
|
|||
|
||||
if (isDelta) {
|
||||
while (stream.readBoolean()) {
|
||||
const ent = stream.readBits(11);
|
||||
match.entities[ent] = null;
|
||||
const ent = stream.readBits(11);
|
||||
match.packetEntities[ent] = null;
|
||||
}
|
||||
}
|
||||
|
||||
stream.index = end;
|
||||
return {
|
||||
packetType: 'packetEntities'
|
||||
packetType: 'packetEntities',
|
||||
entities: receivedEntities
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {GameEventDefinitionMap} from "../../Data/GameEvent";
|
||||
import {Match} from "../../Data/Match";
|
||||
import {Entity} from "../../Data/Entity";
|
||||
|
||||
export type Parser = (stream: BitStream, match?: Match) => Packet;
|
||||
export type PacketParserMap = {[id: number]: Parser};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {TempEntitiesPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {Match} from "../../Data/Match";
|
||||
import {Entity} from "../../Data/Entity";
|
||||
import {PacketEntity} from "../../Data/PacketEntity";
|
||||
import {applyEntityUpdate} from "../EntityDecoder";
|
||||
|
||||
export function TempEntities(stream: BitStream, match: Match): TempEntitiesPacket { // 10: classInfo
|
||||
|
|
@ -9,22 +9,23 @@ export function TempEntities(stream: BitStream, match: Match): TempEntitiesPacke
|
|||
const length = readVarInt(stream);
|
||||
const end = stream.index + length;
|
||||
|
||||
let entity: Entity|null = null;
|
||||
let entities: Entity[] = [];
|
||||
let entity: PacketEntity|null = null;
|
||||
let entities: PacketEntity[] = [];
|
||||
for (let i = 0; i < entityCount; i++) {
|
||||
const delay = (stream.readBoolean()) ? stream.readUint8() / 100 : 0; //unused it seems
|
||||
if (stream.readBoolean()) {
|
||||
const classId = stream.readBits(match.classBits);
|
||||
const serverClass = match.serverClasses[classId - 1]; // no clue why the -1 but it works
|
||||
// maybe because world (id=0) can never be tem
|
||||
// but it's not like the -1 saves any space
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
entity = new Entity(serverClass, sendTable, 0, 0);
|
||||
applyEntityUpdate(entity, stream);
|
||||
const serverClass = match.serverClasses[classId - 1];
|
||||
// no clue why the -1 but it works
|
||||
// maybe because world (id=0) can never be temp
|
||||
// but it's not like the -1 saves any space
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
entity = new PacketEntity(serverClass, sendTable, 0, 0);
|
||||
applyEntityUpdate(entity, sendTable, stream);
|
||||
entities.push(entity);
|
||||
} else {
|
||||
if (entity) {
|
||||
applyEntityUpdate(entity, stream);
|
||||
applyEntityUpdate(entity, entity.sendTable, stream);
|
||||
} else {
|
||||
throw new Error("no entity set to update");
|
||||
}
|
||||
|
|
@ -37,7 +38,7 @@ export function TempEntities(stream: BitStream, match: Match): TempEntitiesPacke
|
|||
stream.index = end;
|
||||
return {
|
||||
packetType: 'tempEntities',
|
||||
entities: entities
|
||||
entities: entities
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue