mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +02:00
add test for new celt codec
This commit is contained in:
parent
c2e79f552a
commit
1ef9fe444b
7 changed files with 2043 additions and 27 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
src
|
src
|
||||||
typings
|
typings
|
||||||
|
build/tests
|
||||||
*.dem
|
*.dem
|
||||||
*.txt
|
*.txt
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ export class Match {
|
||||||
playerMap: {[entityId: number]: Player};
|
playerMap: {[entityId: number]: Player};
|
||||||
entityClasses: {[entityId: string]: ServerClass};
|
entityClasses: {[entityId: string]: ServerClass};
|
||||||
sendTableMap: {[name: string]: SendTable};
|
sendTableMap: {[name: string]: SendTable};
|
||||||
|
baseLineCache: {[serverClass: string]: PacketEntity};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.tick = 0;
|
this.tick = 0;
|
||||||
|
|
@ -55,6 +56,7 @@ export class Match {
|
||||||
};
|
};
|
||||||
this.entityClasses = {};
|
this.entityClasses = {};
|
||||||
this.sendTableMap = {};
|
this.sendTableMap = {};
|
||||||
|
this.baseLineCache = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
getSendTable(name) {
|
getSendTable(name) {
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,13 @@ function readPVSType(stream: BitStream): PVS {
|
||||||
return pvs;
|
return pvs;
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseLineCache: {[serverClass: string]: PacketEntity} = {};
|
|
||||||
|
|
||||||
function readEnterPVS(stream: BitStream, entityId: number, match: Match): PacketEntity {
|
function readEnterPVS(stream: BitStream, entityId: number, match: Match): PacketEntity {
|
||||||
// https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs#L198
|
// 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)];
|
||||||
stream.readBits(10); // unused serial number
|
stream.readBits(10); // unused serial number
|
||||||
|
|
||||||
if (baseLineCache[serverClass.id]) {
|
if (match.baseLineCache[serverClass.id]) {
|
||||||
const result = baseLineCache[serverClass.id].clone();
|
const result = match.baseLineCache[serverClass.id].clone();
|
||||||
result.entityIndex = entityId;
|
result.entityIndex = entityId;
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -44,7 +42,7 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match): Packet
|
||||||
if (staticBaseLine) {
|
if (staticBaseLine) {
|
||||||
staticBaseLine.index = 0;
|
staticBaseLine.index = 0;
|
||||||
applyEntityUpdate(entity, sendTable, staticBaseLine);
|
applyEntityUpdate(entity, sendTable, staticBaseLine);
|
||||||
baseLineCache[serverClass.id] = entity.clone();
|
match.baseLineCache[serverClass.id] = entity.clone();
|
||||||
if (staticBaseLine.bitsLeft > 7) {
|
if (staticBaseLine.bitsLeft > 7) {
|
||||||
// console.log(staticBaseLine.length, staticBaseLine.index);
|
// console.log(staticBaseLine.length, staticBaseLine.index);
|
||||||
// throw new Error('Unexpected data left at the end of staticBaseline, ' + staticBaseLine.bitsLeft + ' bits left');
|
// throw new Error('Unexpected data left at the end of staticBaseline, ' + staticBaseLine.bitsLeft + ' bits left');
|
||||||
|
|
@ -56,7 +54,7 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match): Packet
|
||||||
|
|
||||||
function getPacketEntityForExisting(entityId: number, match: Match, pvs: PVS) {
|
function getPacketEntityForExisting(entityId: number, match: Match, pvs: PVS) {
|
||||||
if (!match.entityClasses[entityId]) {
|
if (!match.entityClasses[entityId]) {
|
||||||
throw new Error("unknown entity");
|
throw new Error("unknown entity " + entityId + " for " + PVS[pvs]);
|
||||||
}
|
}
|
||||||
const serverClass = match.entityClasses[entityId];
|
const serverClass = match.entityClasses[entityId];
|
||||||
return new PacketEntity(serverClass, entityId, pvs);
|
return new PacketEntity(serverClass, entityId, pvs);
|
||||||
|
|
@ -89,7 +87,7 @@ export function PacketEntities(stream: BitStream, match: Match): PacketEntitiesP
|
||||||
if (updatedBaseLine) {
|
if (updatedBaseLine) {
|
||||||
const newBaseLine: SendProp[] = [];
|
const newBaseLine: SendProp[] = [];
|
||||||
newBaseLine.concat(packetEntity.props);
|
newBaseLine.concat(packetEntity.props);
|
||||||
baseLineCache[packetEntity.serverClass.id] = packetEntity.clone();
|
match.baseLineCache[packetEntity.serverClass.id] = packetEntity.clone();
|
||||||
}
|
}
|
||||||
packetEntity.inPVS = true;
|
packetEntity.inPVS = true;
|
||||||
receivedEntities.push(packetEntity);
|
receivedEntities.push(packetEntity);
|
||||||
|
|
|
||||||
BIN
src/tests/data/celt.dem
Normal file
BIN
src/tests/data/celt.dem
Normal file
Binary file not shown.
2011
src/tests/data/celt.json
Normal file
2011
src/tests/data/celt.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -17,4 +17,8 @@ suite('Parse basic demo info', () => {
|
||||||
test('Parse snakewater.dem', () => {
|
test('Parse snakewater.dem', () => {
|
||||||
testDemo('snakewater');
|
testDemo('snakewater');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Parse demo with new celt voice codec', () => {
|
||||||
|
testDemo('celt');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
"es2015.promise",
|
"es2015.promise",
|
||||||
"es6"
|
"es5"
|
||||||
],
|
],
|
||||||
"module": "ES6",
|
"module": "commonjs",
|
||||||
"target": "ES6",
|
"target": "ES5",
|
||||||
"outDir": "build",
|
"outDir": "build",
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue