mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
parse world boundary
This commit is contained in:
parent
58852ffac7
commit
4a8745250f
6 changed files with 39 additions and 14 deletions
|
|
@ -11,12 +11,12 @@ export class Entity {
|
|||
inPVS: boolean;
|
||||
|
||||
constructor(serverClass: ServerClass, sendTable: SendTable, entityIndex: number, serialNumber: number) {
|
||||
this.serverClass = serverClass;
|
||||
this.sendTable = sendTable;
|
||||
this.entityIndex = entityIndex;
|
||||
this.serverClass = serverClass;
|
||||
this.sendTable = sendTable;
|
||||
this.entityIndex = entityIndex;
|
||||
this.serialNumber = serialNumber;
|
||||
this.props = [];
|
||||
this.inPVS = false;
|
||||
this.props = [];
|
||||
this.inPVS = false;
|
||||
}
|
||||
|
||||
getPropByDefinition(definition: SendPropDefinition) {
|
||||
|
|
@ -27,5 +27,14 @@ export class Entity {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getProperty(originTable: string, name: string) {
|
||||
for (const prop of this.props) {
|
||||
if (prop.definition.ownerTableName === originTable && prop.definition.name === name) {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
throw new Error('Property not found in entity');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import {SendProp} from "./SendProp";
|
|||
import {GameEventDefinitionMap} from "./GameEvent";
|
||||
import {BitStream} from "bit-buffer";
|
||||
import {UserInfo} from "./UserInfo";
|
||||
import {World} from "./World";
|
||||
import {Vector} from "./Vector";
|
||||
export class Match {
|
||||
tick: number;
|
||||
chat: any[];
|
||||
|
|
@ -21,6 +23,7 @@ export class Match {
|
|||
instanceBaselines: SendProp[][][];
|
||||
staticBaseLines: BitStream[];
|
||||
eventDefinitions: GameEventDefinitionMap;
|
||||
world: World;
|
||||
|
||||
constructor() {
|
||||
this.tick = 0;
|
||||
|
|
@ -38,6 +41,10 @@ export class Match {
|
|||
this.instanceBaselines = [[], []];
|
||||
this.staticBaseLines = [];
|
||||
this.eventDefinitions = {};
|
||||
this.world = {
|
||||
boundaryMin: {x: 0, y: 0, z: 0},
|
||||
boundaryMax: {x: 0, y: 0, z: 0}
|
||||
}
|
||||
}
|
||||
|
||||
getSendTable(name) {
|
||||
|
|
@ -73,11 +80,8 @@ export class Match {
|
|||
switch (packet.packetType) {
|
||||
case 'packetEntities':
|
||||
for (const entity of this.entities) {
|
||||
if (entity && entity.serverClass.name === 'CTFPlayer') {
|
||||
// console.log(entity.props.map((prop: SendProp) => {
|
||||
// return prop.definition.ownerTableName + '.' + prop.definition.name;
|
||||
// }));
|
||||
// console.log(this.getUserInfoForEntity(entity).name);
|
||||
if (entity) {
|
||||
this.handleEntity(entity);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -194,4 +198,13 @@ export class Match {
|
|||
get classBits() {
|
||||
return Math.ceil(Math.log(this.serverClasses.length) * Math.LOG2E)
|
||||
}
|
||||
|
||||
handleEntity(entity: Entity) {
|
||||
switch (entity.serverClass.name) {
|
||||
case 'CWorld':
|
||||
this.world.boundaryMin = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMins').value;
|
||||
this.world.boundaryMax = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMaxs').value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
5
src/Data/World.ts
Normal file
5
src/Data/World.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import {Vector} from "./Vector";
|
||||
export interface World {
|
||||
boundaryMin: Vector;
|
||||
boundaryMax: Vector;
|
||||
}
|
||||
|
|
@ -58,10 +58,8 @@ export class Parser extends EventEmitter {
|
|||
const message = this.readMessage(this.stream, this.match);
|
||||
if (message instanceof MessageParser) {
|
||||
this.handleMessage(message);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return !!message;
|
||||
}
|
||||
|
||||
parseMessage(data: BitStream, type: MessageType, tick: number, length: number, match: Match): MessageParser {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue