mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
switch to base parser for entity message
This commit is contained in:
parent
ca2083c64a
commit
a0f471cf9a
4 changed files with 14 additions and 20 deletions
|
|
@ -4,7 +4,6 @@ import {EncodeBSPDecal, ParseBSPDecal} from '../Packet/BSPDecal';
|
||||||
import {EncodeClassInfo, ParseClassInfo} from '../Packet/ClassInfo';
|
import {EncodeClassInfo, ParseClassInfo} from '../Packet/ClassInfo';
|
||||||
import {ParseCmdKeyValues} from '../Packet/CmdKeyValues';
|
import {ParseCmdKeyValues} from '../Packet/CmdKeyValues';
|
||||||
import {EncodeCreateStringTable, ParseCreateStringTable} from '../Packet/CreateStringTable';
|
import {EncodeCreateStringTable, ParseCreateStringTable} from '../Packet/CreateStringTable';
|
||||||
import {ParseEntityMessage} from '../Packet/EntityMessage';
|
|
||||||
import {ParseGameEvent} from '../Packet/GameEvent';
|
import {ParseGameEvent} from '../Packet/GameEvent';
|
||||||
import {ParseGameEventList} from '../Packet/GameEventList';
|
import {ParseGameEventList} from '../Packet/GameEventList';
|
||||||
import {ParseMenu} from '../Packet/Menu';
|
import {ParseMenu} from '../Packet/Menu';
|
||||||
|
|
@ -50,7 +49,7 @@ export class Packet extends Parser {
|
||||||
19: make('fixAngle', 'relative{b}x{16}y{16}z{16}'),
|
19: make('fixAngle', 'relative{b}x{16}y{16}z{16}'),
|
||||||
21: {parser: ParseBSPDecal, encoder: EncodeBSPDecal},
|
21: {parser: ParseBSPDecal, encoder: EncodeBSPDecal},
|
||||||
23: {parser: ParseUserMessage, encoder: voidEncoder},
|
23: {parser: ParseUserMessage, encoder: voidEncoder},
|
||||||
24: {parser: ParseEntityMessage, encoder: voidEncoder},
|
24: make('entityMessage', 'index{11}classId{9}length{11}data{$length}'),
|
||||||
25: {parser: ParseGameEvent, encoder: voidEncoder},
|
25: {parser: ParseGameEvent, encoder: voidEncoder},
|
||||||
26: {parser: ParsePacketEntities, encoder: voidEncoder},
|
26: {parser: ParsePacketEntities, encoder: voidEncoder},
|
||||||
27: {parser: ParseTempEntities, encoder: voidEncoder},
|
27: {parser: ParseTempEntities, encoder: voidEncoder},
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
import {make} from './ParserGenerator';
|
|
||||||
|
|
||||||
import {BitStream} from 'bit-buffer';
|
|
||||||
import {Match} from '../../Data/Match';
|
|
||||||
import {EntityMessagePacket} from '../../Data/Packet';
|
|
||||||
|
|
||||||
const baseParser = make('entityMessage', 'index{11}classId{9}length{11}data{$length}');
|
|
||||||
|
|
||||||
export function ParseEntityMessage(stream: BitStream, match: Match): EntityMessagePacket { // 24: entityMessage
|
|
||||||
// entity messages seem pretty unimportant, they are unreliable messages and from testing only the "clear decals"
|
|
||||||
// message seems to be used in practice, probably safe to just leave as is
|
|
||||||
return baseParser.parser(stream) as EntityMessagePacket;
|
|
||||||
}
|
|
||||||
|
|
@ -49,13 +49,13 @@ function readItem(stream: BitStream, description: string, data) {
|
||||||
return stream.readBits(length);
|
return stream.readBits(length);
|
||||||
} else if (description[0] === '$') {
|
} else if (description[0] === '$') {
|
||||||
const variable = description.substr(1);
|
const variable = description.substr(1);
|
||||||
return stream.readBits(data[variable]);
|
return stream.readBitStream(data[variable]);
|
||||||
} else {
|
} else {
|
||||||
return stream.readBits(parseInt(description, 10), true);
|
return stream.readBits(parseInt(description, 10), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeItem(stream: BitStream, description: string, data, value: boolean | string | number) {
|
function writeItem(stream: BitStream, description: string, data, value: boolean | string | number | BitStream) {
|
||||||
if (description[0] === 'b') {
|
if (description[0] === 'b') {
|
||||||
return stream.writeBoolean(value as boolean);
|
return stream.writeBoolean(value as boolean);
|
||||||
} else if (description[0] === 's') {
|
} else if (description[0] === 's') {
|
||||||
|
|
@ -72,7 +72,7 @@ function writeItem(stream: BitStream, description: string, data, value: boolean
|
||||||
return stream.writeBits(value as number, length);
|
return stream.writeBits(value as number, length);
|
||||||
} else if (description[0] === '$') {
|
} else if (description[0] === '$') {
|
||||||
const variable = description.substr(1);
|
const variable = description.substr(1);
|
||||||
return stream.writeBits(value as number, data[variable]);
|
return stream.writeBitStream(value as BitStream, data[variable]);
|
||||||
} else {
|
} else {
|
||||||
return stream.writeBits(value as number, parseInt(description, 10));
|
return stream.writeBits(value as number, parseInt(description, 10));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,11 @@ suite('Parser generator', () => {
|
||||||
stream.writeASCIIString('remaining');
|
stream.writeASCIIString('remaining');
|
||||||
stream.index = 0;
|
stream.index = 0;
|
||||||
|
|
||||||
assertGeneratedParser('length{u2}foo{$length}', stream, {length: 3, foo: 7}, 5);
|
const expectedStream = new BitStream(new ArrayBuffer(4));
|
||||||
|
expectedStream.writeUint8(7);
|
||||||
|
expectedStream.index = 0;
|
||||||
|
|
||||||
|
assertGeneratedParser('length{u2}foo{$length}', stream, {length: 3, foo: expectedStream.readBitStream(3)}, 5);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Float32', () => {
|
test('Float32', () => {
|
||||||
|
|
@ -108,9 +112,13 @@ suite('Parser generator', () => {
|
||||||
}, 2 + 12);
|
}, 2 + 12);
|
||||||
});
|
});
|
||||||
test('Encode variable length', () => {
|
test('Encode variable length', () => {
|
||||||
|
const expectedStream = new BitStream(new ArrayBuffer(4));
|
||||||
|
expectedStream.writeUint8(7);
|
||||||
|
expectedStream.index = 0;
|
||||||
|
|
||||||
assertGeneratedEncoder('foo{u2}bar{$foo}', {
|
assertGeneratedEncoder('foo{u2}bar{$foo}', {
|
||||||
foo: 3,
|
foo: 3,
|
||||||
bar: 4
|
bar: expectedStream.readBitStream(3)
|
||||||
}, 2 + 3);
|
}, 2 + 3);
|
||||||
});
|
});
|
||||||
test('Encode float', () => {
|
test('Encode float', () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue