mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
encoder wip
This commit is contained in:
parent
5b2665bdc9
commit
a5a1642782
13 changed files with 876 additions and 35 deletions
|
|
@ -9,11 +9,13 @@ export function getEntityUpdate(sendTable: SendTable, stream: BitStream): SendPr
|
|||
let index = -1;
|
||||
const allProps = sendTable.flattenedProps;
|
||||
const props: Map<string, SendProp> = new Map();
|
||||
let lastIndex = -1;
|
||||
while (stream.readBoolean()) {
|
||||
lastIndex = index;
|
||||
index = readFieldIndex(stream, index);
|
||||
if (index >= 4096 || index > allProps.length) {
|
||||
throw new Error('prop index out of bounds while applying update for ' + sendTable.name + ' got ' + index
|
||||
+ ' property only has ' + allProps.length + ' properties');
|
||||
throw new Error(`prop index out of bounds while applying update for ${sendTable.name}
|
||||
got ${index} property only has ${allProps.length} properties (lastProp: ${lastIndex})`);
|
||||
}
|
||||
|
||||
const propDefinition = allProps[index];
|
||||
|
|
@ -42,8 +44,8 @@ export function encodeEntityUpdate(props: SendProp[], sendTable: SendTable, stre
|
|||
}
|
||||
|
||||
if (index < lastIndex) {
|
||||
throw new Error(`Property index not incremental while encoding` +
|
||||
`${prop.definition.fullName} after ${allProps[lastIndex].fullName}` +
|
||||
throw new Error(`Property index not incremental while encoding ` +
|
||||
`${prop.definition.fullName} after ${allProps[lastIndex].fullName} ` +
|
||||
`in ${sendTable.name} (current: ${index}, last: ${lastIndex})`);
|
||||
}
|
||||
writeFieldIndex(index, stream, lastIndex);
|
||||
|
|
|
|||
14
src/Parser/Message/Stop.ts
Normal file
14
src/Parser/Message/Stop.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import {BitStream} from 'bit-buffer';
|
||||
import {MessageHandler, MessageType, StopMessage, SyncTickMessage} from '../../Data/Message';
|
||||
|
||||
export const StopHandler: MessageHandler<StopMessage> = {
|
||||
parseMessage: (stream: BitStream) => {
|
||||
return {
|
||||
type: MessageType.Stop,
|
||||
rawData: stream.readBitStream(0)
|
||||
};
|
||||
},
|
||||
encodeMessage: (message, stream) => {
|
||||
// noop
|
||||
}
|
||||
};
|
||||
|
|
@ -4,8 +4,6 @@ import {GameEvent, GameEventType} from '../../Data/GameEventTypes';
|
|||
import {GameEventListPacket} from '../../Data/Packet';
|
||||
|
||||
export function ParseGameEventList(stream: BitStream): GameEventListPacket { // 30: gameEventList
|
||||
const s = stream.index;
|
||||
|
||||
// list of game events and parameters
|
||||
const numEvents = stream.readBits(9);
|
||||
const length = stream.readBits(20);
|
||||
|
|
@ -28,6 +26,7 @@ export function ParseGameEventList(stream: BitStream): GameEventListPacket { //
|
|||
entries
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
packetType: 'gameEventList',
|
||||
eventList
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ export function ParsePacketEntities(
|
|||
const updatedEntries = stream.readBits(11);
|
||||
const length = stream.readBits(20);
|
||||
const updatedBaseLine = stream.readBoolean();
|
||||
const start = stream.index;
|
||||
const end = stream.index + length;
|
||||
let entityId = -1;
|
||||
|
||||
|
|
@ -166,6 +167,10 @@ export function ParsePacketEntities(
|
|||
if (!sendTable) {
|
||||
throw new Error(`Unknown sendTable ${packetEntity.serverClass.dataTable}`);
|
||||
}
|
||||
if (entityId === 55) {
|
||||
console.log(`decode preserve: ${entityId} = ${sendTable.name}, ${receivedEntities.length}/${i} ${stream.index} ${end} tick ${state.tick}`);
|
||||
console.log(receivedEntities[receivedEntities.length - 1], start, entityId, diff);
|
||||
}
|
||||
const updatedProps = getEntityUpdate(sendTable, stream);
|
||||
packetEntity.applyPropUpdate(updatedProps);
|
||||
receivedEntities.push(packetEntity);
|
||||
|
|
@ -173,7 +178,7 @@ export function ParsePacketEntities(
|
|||
const packetEntity = getPacketEntityForExisting(entityId, state, pvs);
|
||||
receivedEntities.push(packetEntity);
|
||||
} else {
|
||||
// throw new Error(`No existing entity to update with id ${entityId}`);
|
||||
throw new Error(`No existing entity to update with id ${entityId}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,6 +238,9 @@ export function EncodePacketEntities(packet: PacketEntitiesPacket, stream: BitSt
|
|||
writeEnterPVS(entity, stream, state, packet.baseLine);
|
||||
} else if (entity.pvs === PVS.PRESERVE) {
|
||||
const sendTable = getSendTable(state, entity.serverClass.dataTable);
|
||||
if (entity.entityIndex === 55) {
|
||||
console.log(`encode preserve: ${entity.entityIndex} = ${entity.serverClass.dataTable}`);
|
||||
}
|
||||
encodeEntityUpdate(entity.props, sendTable, stream);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ export const readUBitVar = readBitVar;
|
|||
export function readVarInt(stream: BitStream, signed: boolean = false) {
|
||||
let result = 0;
|
||||
for (let i = 0; i < 35; i += 7) {
|
||||
const byte = stream.readBits(8);
|
||||
const byte = stream.readUint8();
|
||||
result |= ((byte & 0x7F) << i);
|
||||
|
||||
if ((byte >> 7) === 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue