mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
implement tempentities
This commit is contained in:
parent
0614383a58
commit
be00d32175
3 changed files with 33 additions and 36 deletions
|
|
@ -4,6 +4,7 @@ import {SendTable} from "./SendTable";
|
|||
import {StringTable} from "./StringTable";
|
||||
import {SendProp} from "./SendProp";
|
||||
import {GameEventDefinitionMap} from "./GameEvent";
|
||||
import {BitStream} from "bit-buffer";
|
||||
export class Match {
|
||||
tick: number;
|
||||
chat: any[];
|
||||
|
|
@ -17,7 +18,7 @@ export class Match {
|
|||
serverClasses: ServerClass[];
|
||||
sendTables: SendTable[];
|
||||
instanceBaselines: SendProp[][][];
|
||||
staticBaseLines: any[];
|
||||
staticBaseLines: BitStream[];
|
||||
eventDefinitions: GameEventDefinitionMap;
|
||||
|
||||
constructor() {
|
||||
|
|
|
|||
|
|
@ -3,15 +3,17 @@ import {BitStream} from "bit-buffer";
|
|||
import {SendProp} from "../Data/SendProp";
|
||||
import {SendPropParser} from "./SendPropParser";
|
||||
import {readUBitVar} from "./readBitVar";
|
||||
|
||||
export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
|
||||
let index = -1;
|
||||
const allProps = entity.sendTable.flattenedProps;
|
||||
let changedProps: SendProp[] = [];
|
||||
while ((index = readFieldIndex(stream, index)) != -1) {
|
||||
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];
|
||||
// console.log(propDefinition);
|
||||
const existingProp = entity.getPropByDefinition(propDefinition);
|
||||
let prop;
|
||||
if (existingProp) {
|
||||
|
|
@ -19,21 +21,15 @@ export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
|
|||
} else {
|
||||
prop = new SendProp(propDefinition);
|
||||
}
|
||||
// prop.value = SendPropParser.decode(propDefinition, stream);
|
||||
// console.log(prop);
|
||||
changedProps.push(prop);
|
||||
prop.value = SendPropParser.decode(propDefinition, stream);
|
||||
console.log(prop);
|
||||
|
||||
if (!existingProp) {
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
const readFieldIndex = function (stream: BitStream, lastIndex: number): number {
|
||||
if (!stream.readBoolean()) {
|
||||
|
|
|
|||
|
|
@ -9,33 +9,33 @@ export function TempEntities(stream: BitStream, match: Match): Packet { // 10: c
|
|||
const length = readVarInt(stream);
|
||||
const end = stream.index + length;
|
||||
|
||||
// let entity: Entity|null = null;
|
||||
// let entities: Entity[] = [];
|
||||
// for (let i = 0; i < entityCount; i++) {
|
||||
// const delay = (stream.readBoolean()) ? stream.readUint8() / 100 : 0; //unused it seems
|
||||
// if (stream.readBoolean()) {
|
||||
// const classId = stream.readBits(match.classBits);
|
||||
// const serverClass = match.serverClasses[classId];
|
||||
// const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
// entity = new Entity(serverClass, sendTable, 0, 0);
|
||||
// applyEntityUpdate(entity, stream);
|
||||
// entities.push(entity);
|
||||
// } else {
|
||||
// if (entity) {
|
||||
// applyEntityUpdate(entity, stream);
|
||||
// } else {
|
||||
// throw new Error("no entity set to update");
|
||||
// }
|
||||
// }
|
||||
// console.log(entity);
|
||||
// }
|
||||
// if (end - stream.index > 8) {
|
||||
// throw new Error("unexpected content after TempEntities");
|
||||
// }
|
||||
let entity: Entity|null = null;
|
||||
let entities: Entity[] = [];
|
||||
for (let i = 0; i < entityCount; i++) {
|
||||
const delay = (stream.readBoolean()) ? stream.readUint8() / 100 : 0; //unused it seems
|
||||
if (stream.readBoolean()) {
|
||||
const classId = stream.readBits(match.classBits);
|
||||
const serverClass = match.serverClasses[classId - 1]; //no clue why the -1 but it works
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
entity = new Entity(serverClass, sendTable, 0, 0);
|
||||
applyEntityUpdate(entity, stream);
|
||||
entities.push(entity);
|
||||
} else {
|
||||
if (entity) {
|
||||
applyEntityUpdate(entity, stream);
|
||||
} else {
|
||||
throw new Error("no entity set to update");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (end - stream.index > 8) {
|
||||
throw new Error("unexpected content after TempEntities");
|
||||
}
|
||||
|
||||
stream.index = end;
|
||||
return {
|
||||
'packetType': 'tempEntities'
|
||||
'packetType': 'tempEntities',
|
||||
entities: entities
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue