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

add entity update encoder

This commit is contained in:
Robin Appelman 2017-09-04 23:01:48 +02:00
commit c064439b4e
11 changed files with 1786 additions and 43 deletions

View file

@ -3,7 +3,7 @@ import {Match} from '../../Data/Match';
import {PacketEntitiesPacket} from '../../Data/Packet';
import {EntityId, PacketEntity, PVS} from '../../Data/PacketEntity';
import {SendProp} from '../../Data/SendProp';
import {applyEntityUpdate} from '../EntityDecoder';
import {getEntityUpdate} from '../EntityDecoder';
import {readUBitVar} from '../readBitVar';
const pvsMap = {
@ -39,7 +39,7 @@ function readEnterPVS(stream: BitStream, entityId: EntityId, match: Match): Pack
const staticBaseLine = match.staticBaseLines[serverClass.id];
if (staticBaseLine) {
staticBaseLine.index = 0;
applyEntityUpdate(entity, sendTable, staticBaseLine);
entity.props = getEntityUpdate(sendTable, staticBaseLine);
match.baseLineCache.set(serverClass, entity.clone());
// if (staticBaseLine.bitsLeft > 7) {
// console.log(staticBaseLine.length, staticBaseLine.index);
@ -85,7 +85,8 @@ export function ParsePacketEntities(stream: BitStream, match: Match, skip: boole
const pvs = readPVSType(stream);
if (pvs === PVS.ENTER) {
const packetEntity = readEnterPVS(stream, entityId, match);
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
const updatedProps = getEntityUpdate(match.getSendTable(packetEntity.serverClass.dataTable), stream);
packetEntity.applyPropUpdate(updatedProps);
if (updatedBaseLine) {
const newBaseLine: SendProp[] = [];
@ -96,7 +97,8 @@ export function ParsePacketEntities(stream: BitStream, match: Match, skip: boole
receivedEntities.push(packetEntity);
} else if (pvs === PVS.PRESERVE) {
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
const updatedProps = getEntityUpdate(match.getSendTable(packetEntity.serverClass.dataTable), stream);
packetEntity.applyPropUpdate(updatedProps);
receivedEntities.push(packetEntity);
} else if (match.entityClasses.has(entityId)) {
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);

View file

@ -2,7 +2,8 @@ import {BitStream} from 'bit-buffer';
import {Match} from '../../Data/Match';
import {TempEntitiesPacket} from '../../Data/Packet';
import {PacketEntity, PVS} from '../../Data/PacketEntity';
import {applyEntityUpdate} from '../EntityDecoder';
import {getEntityUpdate} from '../EntityDecoder';
import {readVarInt} from '../readBitVar';
export function ParseTempEntities(stream: BitStream, match: Match, skip: boolean = false): TempEntitiesPacket { // 10: classInfo
const entityCount = stream.readBits(8);
@ -23,11 +24,12 @@ export function ParseTempEntities(stream: BitStream, match: Match, skip: boolean
const sendTable = match.getSendTable(serverClass.dataTable);
entity = new PacketEntity(serverClass, 0, PVS.ENTER);
entity.delay = delay;
applyEntityUpdate(entity, sendTable, stream);
entity.props = getEntityUpdate(sendTable, stream);
entities.push(entity);
} else {
if (entity) {
applyEntityUpdate(entity, match.getSendTable(entity.serverClass.dataTable), stream);
const updatedProps = getEntityUpdate(match.getSendTable(entity.serverClass.dataTable), stream);
entity.applyPropUpdate(updatedProps);
} else {
throw new Error('no entity set to update');
}
@ -44,16 +46,3 @@ export function ParseTempEntities(stream: BitStream, match: Match, skip: boolean
entities,
};
}
function readVarInt(stream: BitStream) {
let result = 0;
for (let run = 0; run < 35; run += 7) {
const byte = stream.readUint8();
result |= ((byte & 0x7F) << run);
if ((byte >> 7) === 0) {
return result;
}
}
return result;
}