mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
support reading coord and normal floats
This commit is contained in:
parent
4d40fd4109
commit
675bf59a74
3 changed files with 32 additions and 9 deletions
|
|
@ -18,6 +18,7 @@ export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
|
||||||
|
|
||||||
const prop = existingProp ? existingProp : new SendProp(propDefinition);
|
const prop = existingProp ? existingProp : new SendProp(propDefinition);
|
||||||
prop.value = SendPropParser.decode(propDefinition, stream);
|
prop.value = SendPropParser.decode(propDefinition, stream);
|
||||||
|
// console.log(entity.props.length, prop);
|
||||||
|
|
||||||
if (!existingProp) {
|
if (!existingProp) {
|
||||||
entity.props.push(prop);
|
entity.props.push(prop);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ function readPVSType(stream: BitStream): PVS {
|
||||||
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): Entity {
|
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): Entity {
|
||||||
// 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)];
|
||||||
console.log(serverClass);
|
// console.log(serverClass);
|
||||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||||
const serialNumber = stream.readBits(10);
|
const serialNumber = stream.readBits(10);
|
||||||
if (!sendTable) {
|
if (!sendTable) {
|
||||||
|
|
@ -62,7 +62,7 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLin
|
||||||
applyEntityUpdate(entity, staticBaseLine);
|
applyEntityUpdate(entity, staticBaseLine);
|
||||||
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ export class SendPropParser {
|
||||||
static readVector(propDefinition: SendPropDefinition, stream: BitStream): Vector {
|
static readVector(propDefinition: SendPropDefinition, stream: BitStream): Vector {
|
||||||
const x = SendPropParser.readFloat(propDefinition, stream);
|
const x = SendPropParser.readFloat(propDefinition, stream);
|
||||||
const y = 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);
|
return new Vector(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,17 +72,17 @@ export class SendPropParser {
|
||||||
|
|
||||||
static readFloat(propDefinition: SendPropDefinition, stream: BitStream): number {
|
static readFloat(propDefinition: SendPropDefinition, stream: BitStream): number {
|
||||||
if (propDefinition.hasFlag(SendPropFlag.SPROP_COORD)) {
|
if (propDefinition.hasFlag(SendPropFlag.SPROP_COORD)) {
|
||||||
throw new Error("not implemented");
|
return SendPropParser.readBitCoord(stream);
|
||||||
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_COORD_MP)) {
|
} 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)) {
|
} 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)) {
|
} 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)) {
|
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_NOSCALE)) {
|
||||||
return stream.readFloat32();
|
return stream.readFloat32();
|
||||||
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_NORMAL)) {
|
} else if (propDefinition.hasFlag(SendPropFlag.SPROP_NORMAL)) {
|
||||||
throw new Error("not implemented");
|
return SendPropParser.readBitNormal(stream);
|
||||||
} else {
|
} else {
|
||||||
const raw = stream.readBits(propDefinition.bitCount);
|
const raw = stream.readBits(propDefinition.bitCount);
|
||||||
const percentage = raw / ((1 << propDefinition.bitCount) - 1);
|
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 value = 0;
|
||||||
let isNegative = false;
|
let isNegative = false;
|
||||||
const inBounds = stream.readBoolean();
|
const inBounds = stream.readBoolean();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue