mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 09:04:13 +02:00
add fast mode
This commit is contained in:
parent
51739e3aa8
commit
e9349d178e
9 changed files with 91 additions and 70 deletions
|
|
@ -58,7 +58,7 @@ function getPacketEntityForExisting(entityId: number, match: Match, pvs: PVS) {
|
|||
return new PacketEntity(serverClass, entityId, pvs);
|
||||
}
|
||||
|
||||
export function PacketEntities(stream: BitStream, match: Match): PacketEntitiesPacket { //26: packetEntities
|
||||
export function PacketEntities(stream: BitStream, match: Match, skip: boolean = false): PacketEntitiesPacket { //26: packetEntities
|
||||
// https://github.com/skadistats/smoke/blob/master/smoke/replay/handler/svc_packetentities.pyx
|
||||
// https://github.com/StatsHelix/demoinfo/blob/3d28ea917c3d44d987b98bb8f976f1a3fcc19821/DemoInfo/DP/Handler/PacketEntitesHandler.cs
|
||||
// https://github.com/StatsHelix/demoinfo/blob/3d28ea917c3d44d987b98bb8f976f1a3fcc19821/DemoInfo/DP/Entity.cs
|
||||
|
|
@ -74,38 +74,41 @@ export function PacketEntities(stream: BitStream, match: Match): PacketEntitiesP
|
|||
let entityId = -1;
|
||||
|
||||
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);
|
||||
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
|
||||
const removedEntityIds: number[] = [];
|
||||
|
||||
if (updatedBaseLine) {
|
||||
const newBaseLine: SendProp[] = [];
|
||||
newBaseLine.concat(packetEntity.props);
|
||||
match.baseLineCache[packetEntity.serverClass.id] = packetEntity.clone();
|
||||
}
|
||||
packetEntity.inPVS = true;
|
||||
receivedEntities.push(packetEntity);
|
||||
} else if (pvs === PVS.PRESERVE) {
|
||||
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
|
||||
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
|
||||
receivedEntities.push(packetEntity);
|
||||
} else {
|
||||
if(match.entityClasses[entityId]) {
|
||||
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
|
||||
if (!skip) {
|
||||
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);
|
||||
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
|
||||
|
||||
if (updatedBaseLine) {
|
||||
const newBaseLine: SendProp[] = [];
|
||||
newBaseLine.concat(packetEntity.props);
|
||||
match.baseLineCache[packetEntity.serverClass.id] = packetEntity.clone();
|
||||
}
|
||||
packetEntity.inPVS = true;
|
||||
receivedEntities.push(packetEntity);
|
||||
} else if (pvs === PVS.PRESERVE) {
|
||||
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
|
||||
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
|
||||
receivedEntities.push(packetEntity);
|
||||
} else {
|
||||
if (match.entityClasses[entityId]) {
|
||||
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
|
||||
receivedEntities.push(packetEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const removedEntityIds: number[] = [];
|
||||
if (isDelta) {
|
||||
while (stream.readBoolean()) {
|
||||
const entityId = stream.readBits(11);
|
||||
removedEntityIds.push(entityId);
|
||||
if (isDelta) {
|
||||
while (stream.readBoolean()) {
|
||||
const entityId = stream.readBits(11);
|
||||
removedEntityIds.push(entityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ import {Packet} from "../../Data/Packet";
|
|||
import {BitStream} from 'bit-buffer';
|
||||
import {Match} from "../../Data/Match";
|
||||
|
||||
export type Parser = (stream: BitStream, match?: Match) => Packet;
|
||||
export type Parser = (stream: BitStream, match?: Match, skip: boolean = false) => Packet;
|
||||
export type PacketParserMap = {[id: number]: Parser};
|
||||
|
|
|
|||
|
|
@ -4,35 +4,37 @@ import {Match} from "../../Data/Match";
|
|||
import {PacketEntity, PVS} from "../../Data/PacketEntity";
|
||||
import {applyEntityUpdate} from "../EntityDecoder";
|
||||
|
||||
export function TempEntities(stream: BitStream, match: Match): TempEntitiesPacket { // 10: classInfo
|
||||
export function TempEntities(stream: BitStream, match: Match, skip: boolean = false): TempEntitiesPacket { // 10: classInfo
|
||||
const entityCount = stream.readBits(8);
|
||||
const length = readVarInt(stream);
|
||||
const end = stream.index + length;
|
||||
|
||||
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 temp
|
||||
// but it's not like the -1 saves any space
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
entity = new PacketEntity(serverClass, 0, PVS.ENTER);
|
||||
applyEntityUpdate(entity, sendTable, stream);
|
||||
entities.push(entity);
|
||||
} else {
|
||||
if (entity) {
|
||||
applyEntityUpdate(entity, match.getSendTable(entity.serverClass.dataTable), stream);
|
||||
if (!skip) {
|
||||
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 temp
|
||||
// but it's not like the -1 saves any space
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
entity = new PacketEntity(serverClass, 0, PVS.ENTER);
|
||||
applyEntityUpdate(entity, sendTable, stream);
|
||||
entities.push(entity);
|
||||
} else {
|
||||
throw new Error("no entity set to update");
|
||||
if (entity) {
|
||||
applyEntityUpdate(entity, match.getSendTable(entity.serverClass.dataTable), stream);
|
||||
} else {
|
||||
throw new Error("no entity set to update");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (end - stream.index > 8) {
|
||||
throw new Error("unexpected content after TempEntities");
|
||||
if (end - stream.index > 8) {
|
||||
throw new Error("unexpected content after TempEntities");
|
||||
}
|
||||
}
|
||||
|
||||
stream.index = end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue