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

implement tempentities

This commit is contained in:
Robin Appelman 2016-12-24 15:26:41 +01:00
commit be00d32175
3 changed files with 33 additions and 36 deletions

View file

@ -4,6 +4,7 @@ import {SendTable} from "./SendTable";
import {StringTable} from "./StringTable"; import {StringTable} from "./StringTable";
import {SendProp} from "./SendProp"; import {SendProp} from "./SendProp";
import {GameEventDefinitionMap} from "./GameEvent"; import {GameEventDefinitionMap} from "./GameEvent";
import {BitStream} from "bit-buffer";
export class Match { export class Match {
tick: number; tick: number;
chat: any[]; chat: any[];
@ -17,7 +18,7 @@ export class Match {
serverClasses: ServerClass[]; serverClasses: ServerClass[];
sendTables: SendTable[]; sendTables: SendTable[];
instanceBaselines: SendProp[][][]; instanceBaselines: SendProp[][][];
staticBaseLines: any[]; staticBaseLines: BitStream[];
eventDefinitions: GameEventDefinitionMap; eventDefinitions: GameEventDefinitionMap;
constructor() { constructor() {

View file

@ -3,15 +3,17 @@ import {BitStream} from "bit-buffer";
import {SendProp} from "../Data/SendProp"; import {SendProp} from "../Data/SendProp";
import {SendPropParser} from "./SendPropParser"; import {SendPropParser} from "./SendPropParser";
import {readUBitVar} from "./readBitVar"; import {readUBitVar} from "./readBitVar";
export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity { export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
let index = -1; let index = -1;
const allProps = entity.sendTable.flattenedProps; const allProps = entity.sendTable.flattenedProps;
let changedProps: SendProp[] = [];
while ((index = readFieldIndex(stream, index)) != -1) { while ((index = readFieldIndex(stream, index)) != -1) {
if (index > 4096) { if (index > 4096) {
throw new Error('prop index out of bounds while applying update for ' + entity.sendTable.name+ ' got ' + index); throw new Error('prop index out of bounds while applying update for ' + entity.sendTable.name + ' got ' + index);
} }
console.log("index: " + index, allProps.length);
const propDefinition = allProps[index]; const propDefinition = allProps[index];
// console.log(propDefinition);
const existingProp = entity.getPropByDefinition(propDefinition); const existingProp = entity.getPropByDefinition(propDefinition);
let prop; let prop;
if (existingProp) { if (existingProp) {
@ -19,21 +21,15 @@ export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
} else { } else {
prop = new SendProp(propDefinition); prop = new SendProp(propDefinition);
} }
// prop.value = SendPropParser.decode(propDefinition, stream); prop.value = SendPropParser.decode(propDefinition, stream);
// console.log(prop); console.log(prop);
changedProps.push(prop);
if (!existingProp) { if (!existingProp) {
entity.props.push(prop); entity.props.push(prop);
} }
} }
for (let i = 0; i < changedProps.length; i++) {
const prop = changedProps[i];
prop.value = SendPropParser.decode(prop.definition, stream);
console.log(prop);
}
return entity; return entity;
}; }
const readFieldIndex = function (stream: BitStream, lastIndex: number): number { const readFieldIndex = function (stream: BitStream, lastIndex: number): number {
if (!stream.readBoolean()) { if (!stream.readBoolean()) {

View file

@ -9,33 +9,33 @@ export function TempEntities(stream: BitStream, match: Match): Packet { // 10: c
const length = readVarInt(stream); const length = readVarInt(stream);
const end = stream.index + length; const end = stream.index + length;
// let entity: Entity|null = null; let entity: Entity|null = null;
// let entities: Entity[] = []; let entities: Entity[] = [];
// for (let i = 0; i < entityCount; i++) { for (let i = 0; i < entityCount; i++) {
// const delay = (stream.readBoolean()) ? stream.readUint8() / 100 : 0; //unused it seems const delay = (stream.readBoolean()) ? stream.readUint8() / 100 : 0; //unused it seems
// if (stream.readBoolean()) { if (stream.readBoolean()) {
// const classId = stream.readBits(match.classBits); const classId = stream.readBits(match.classBits);
// const serverClass = match.serverClasses[classId]; const serverClass = match.serverClasses[classId - 1]; //no clue why the -1 but it works
// const sendTable = match.getSendTable(serverClass.dataTable); const sendTable = match.getSendTable(serverClass.dataTable);
// entity = new Entity(serverClass, sendTable, 0, 0); entity = new Entity(serverClass, sendTable, 0, 0);
// applyEntityUpdate(entity, stream); applyEntityUpdate(entity, stream);
// entities.push(entity); entities.push(entity);
// } else { } else {
// if (entity) { if (entity) {
// applyEntityUpdate(entity, stream); applyEntityUpdate(entity, stream);
// } else { } else {
// throw new Error("no entity set to update"); throw new Error("no entity set to update");
// } }
// } }
// console.log(entity); }
// } if (end - stream.index > 8) {
// if (end - stream.index > 8) { throw new Error("unexpected content after TempEntities");
// throw new Error("unexpected content after TempEntities"); }
// }
stream.index = end; stream.index = end;
return { return {
'packetType': 'tempEntities' 'packetType': 'tempEntities',
entities: entities
} }
} }