mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +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 {ParseCmdKeyValues} from '../Packet/CmdKeyValues';
|
||||
import {EncodeCreateStringTable, ParseCreateStringTable} from '../Packet/CreateStringTable';
|
||||
import {ParseEntityMessage} from '../Packet/EntityMessage';
|
||||
import {ParseGameEvent} from '../Packet/GameEvent';
|
||||
import {ParseGameEventList} from '../Packet/GameEventList';
|
||||
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}'),
|
||||
21: {parser: ParseBSPDecal, encoder: EncodeBSPDecal},
|
||||
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},
|
||||
26: {parser: ParsePacketEntities, 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);
|
||||
} else if (description[0] === '$') {
|
||||
const variable = description.substr(1);
|
||||
return stream.readBits(data[variable]);
|
||||
return stream.readBitStream(data[variable]);
|
||||
} else {
|
||||
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') {
|
||||
return stream.writeBoolean(value as boolean);
|
||||
} 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);
|
||||
} else if (description[0] === '$') {
|
||||
const variable = description.substr(1);
|
||||
return stream.writeBits(value as number, data[variable]);
|
||||
return stream.writeBitStream(value as BitStream, data[variable]);
|
||||
} else {
|
||||
return stream.writeBits(value as number, parseInt(description, 10));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,11 @@ suite('Parser generator', () => {
|
|||
stream.writeASCIIString('remaining');
|
||||
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', () => {
|
||||
|
|
@ -108,9 +112,13 @@ suite('Parser generator', () => {
|
|||
}, 2 + 12);
|
||||
});
|
||||
test('Encode variable length', () => {
|
||||
const expectedStream = new BitStream(new ArrayBuffer(4));
|
||||
expectedStream.writeUint8(7);
|
||||
expectedStream.index = 0;
|
||||
|
||||
assertGeneratedEncoder('foo{u2}bar{$foo}', {
|
||||
foo: 3,
|
||||
bar: 4
|
||||
bar: expectedStream.readBitStream(3)
|
||||
}, 2 + 3);
|
||||
});
|
||||
test('Encode float', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue