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

support reading coord and normal floats

This commit is contained in:
Robin Appelman 2017-02-11 16:17:26 +01:00
commit 675bf59a74
3 changed files with 32 additions and 9 deletions

View file

@ -18,6 +18,7 @@ export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
const prop = existingProp ? existingProp : new SendProp(propDefinition);
prop.value = SendPropParser.decode(propDefinition, stream);
// console.log(entity.props.length, prop);
if (!existingProp) {
entity.props.push(prop);

View file

@ -35,7 +35,7 @@ function readPVSType(stream: BitStream): PVS {
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): Entity {
// https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs#L198
const serverClass = match.serverClasses[stream.readBits(match.classBits)];
console.log(serverClass);
// console.log(serverClass);
const sendTable = match.getSendTable(serverClass.dataTable);
const serialNumber = stream.readBits(10);
if (!sendTable) {
@ -62,7 +62,7 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLin
applyEntityUpdate(entity, 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');
// throw new Error('Unexpected data left at the end of staticBaseline, ' + staticBaseLine.bitsLeft + ' bits left');
}
}
}

View file

@ -60,7 +60,7 @@ export class SendPropParser {
static readVector(propDefinition: SendPropDefinition, stream: BitStream): Vector {
const x = SendPropParser.readFloat(propDefinition, stream);
const y = SendPropParser.readFloat(propDefinition, stream);
const z = (!propDefinition.hasFlag(SendPropFlag.SPROP_NORMAL)) ? SendPropParser.readFloat(propDefinition, stream) : 0;
const z = SendPropParser.readFloat(propDefinition, stream);
return new Vector(x, y, z);
}
@ -72,17 +72,17 @@ export class SendPropParser {
static readFloat(propDefinition: SendPropDefinition, stream: BitStream): number {
if (propDefinition.hasFlag(SendPropFlag.SPROP_COORD)) {
throw new Error("not implemented");
return SendPropParser.readBitCoord(stream);
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_COORD_MP)) {
return SendPropParser.readBitCoord(propDefinition, stream, false, false);
return SendPropParser.readBitCoordMP(propDefinition, stream, false, false);
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_COORD_MP_LOWPRECISION)) {
return SendPropParser.readBitCoord(propDefinition, stream, false, true);
return SendPropParser.readBitCoordMP(propDefinition, stream, false, true);
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_COORD_MP_INTEGRAL)) {
return SendPropParser.readBitCoord(propDefinition, stream, true, false);
return SendPropParser.readBitCoordMP(propDefinition, stream, true, false);
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_NOSCALE)) {
return stream.readFloat32();
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_NORMAL)) {
throw new Error("not implemented");
return SendPropParser.readBitNormal(stream);
} else {
const raw = stream.readBits(propDefinition.bitCount);
const percentage = raw / ((1 << propDefinition.bitCount) - 1);
@ -90,7 +90,29 @@ export class SendPropParser {
}
}
static readBitCoord(propDefinition: SendPropDefinition, stream: BitStream, isIntegral: boolean, isLowPrecision: boolean): number {
static readBitNormal(stream: BitStream) {
const isNegative = stream.readBoolean();
const fractVal = stream.readBits(11);
const value = fractVal * (1 / ((1 << 11) - 1));
return (isNegative) ? -value : value;
}
static readBitCoord(stream: BitStream) {
const hasIntVal = stream.readBoolean();
const hasFractVal = stream.readBoolean();
if (hasIntVal || hasFractVal) {
const isNegative = stream.readBoolean();
const intVal = (hasIntVal) ? stream.readBits(14) + 1 : 0;
const fractVal = (hasFractVal) ? stream.readBits(5) : 0;
const value = intVal + fractVal * (1 / (1 << 5));
return (isNegative) ? -value : value;
}
return 0;
}
static readBitCoordMP(propDefinition: SendPropDefinition, stream: BitStream, isIntegral: boolean, isLowPrecision: boolean): number {
let value = 0;
let isNegative = false;
const inBounds = stream.readBoolean();