-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathBitMsg.h
703 lines (564 loc) · 21.3 KB
/
BitMsg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/*****************************************************************************
The Dark Mod GPL Source Code
This file is part of the The Dark Mod Source Code, originally based
on the Doom 3 GPL Source Code as published in 2011.
The Dark Mod Source Code is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version. For details, see LICENSE.TXT.
Project: The Dark Mod (http://www.thedarkmod.com/)
******************************************************************************/
#ifndef __BITMSG_H__
#define __BITMSG_H__
/*
===============================================================================
idBitMsg
Handles byte ordering and avoids alignment errors.
Allows concurrent writing and reading.
The data set with Init is never freed.
===============================================================================
*/
class idBitMsg {
public:
idBitMsg();
~idBitMsg() {}
void Init( byte *data, int length );
void Init( const byte *data, int length );
byte * GetData( void ); // get data for writing
const byte * GetData( void ) const; // get data for reading
int GetMaxSize( void ) const; // get the maximum message size
void SetAllowOverflow( bool set ); // generate error if not set and message is overflowed
bool IsOverflowed( void ) const; // returns true if the message was overflowed
int GetSize( void ) const; // size of the message in bytes
void SetSize( int size ); // set the message size
int GetWriteBit( void ) const; // get current write bit
void SetWriteBit( int bit ); // set current write bit
int GetNumBitsWritten( void ) const; // returns number of bits written
int GetRemainingWriteBits( void ) const; // space left in bits for writing
void SaveWriteState( int &s, int &b ) const; // save the write state
void RestoreWriteState( int s, int b ); // restore the write state
int GetReadCount( void ) const; // bytes read so far
void SetReadCount( int bytes ); // set the number of bytes and bits read
int GetReadBit( void ) const; // get current read bit
void SetReadBit( int bit ); // set current read bit
int GetNumBitsRead( void ) const; // returns number of bits read
int GetRemainingReadBits( void ) const; // number of bits left to read
void SaveReadState( int &c, int &b ) const; // save the read state
void RestoreReadState( int c, int b ); // restore the read state
void BeginWriting( void ); // begin writing
int GetRemainingSpace( void ) const; // space left in bytes
void WriteByteAlign( void ); // write up to the next byte boundary
void WriteBits( int value, int numBits ); // write the specified number of bits
void WriteChar( int c );
void WriteByte( int c );
void WriteShort( int c );
void WriteUShort( int c );
void WriteInt( int c );
void WriteLong( int c );
void WriteFloat( float f );
void WriteFloat( float f, int exponentBits, int mantissaBits );
void WriteAngle8( float f );
void WriteAngle16( float f );
void WriteDir( const idVec3 &dir, int numBits );
void WriteString( const char *s, int maxLength = -1, bool make7Bit = true );
void WriteData( const void *data, int length );
void WriteNetadr( const netadr_t adr );
void WriteDeltaChar( int oldValue, int newValue );
void WriteDeltaByte( int oldValue, int newValue );
void WriteDeltaShort( int oldValue, int newValue );
void WriteDeltaInt( int oldValue, int newValue );
void WriteDeltaLong( int oldValue, int newValue );
void WriteDeltaFloat( float oldValue, float newValue );
void WriteDeltaFloat( float oldValue, float newValue, int exponentBits, int mantissaBits );
void WriteDeltaByteCounter( int oldValue, int newValue );
void WriteDeltaShortCounter( int oldValue, int newValue );
void WriteDeltaLongCounter( int oldValue, int newValue );
bool WriteDeltaDict( const idDict &dict, const idDict *base );
void BeginReading( void ) const; // begin reading.
int GetRemaingData( void ) const; // number of bytes left to read
void ReadByteAlign( void ) const; // read up to the next byte boundary
int ReadBits( int numBits ) const; // read the specified number of bits
int ReadChar( void ) const;
int ReadByte( void ) const;
int ReadShort( void ) const;
int ReadUShort( void ) const;
int ReadInt( void ) const;
int ReadLong( void ) const;
float ReadFloat( void ) const;
float ReadFloat( int exponentBits, int mantissaBits ) const;
float ReadAngle8( void ) const;
float ReadAngle16( void ) const;
idVec3 ReadDir( int numBits ) const;
int ReadString( char *buffer, int bufferSize ) const;
int ReadData( void *data, int length ) const;
void ReadNetadr( netadr_t *adr ) const;
int ReadDeltaChar( int oldValue ) const;
int ReadDeltaByte( int oldValue ) const;
int ReadDeltaShort( int oldValue ) const;
int ReadDeltaInt( int oldValue ) const;
int ReadDeltaLong( int oldValue ) const;
float ReadDeltaFloat( float oldValue ) const;
float ReadDeltaFloat( float oldValue, int exponentBits, int mantissaBits ) const;
int ReadDeltaByteCounter( int oldValue ) const;
int ReadDeltaShortCounter( int oldValue ) const;
int ReadDeltaLongCounter( int oldValue ) const;
bool ReadDeltaDict( idDict &dict, const idDict *base ) const;
static int DirToBits( const idVec3 &dir, int numBits );
static idVec3 BitsToDir( int bits, int numBits );
private:
byte * writeData; // pointer to data for writing
const byte * readData; // pointer to data for reading
int maxSize; // maximum size of message in bytes
int curSize; // current size of message in bytes
int writeBit; // number of bits written to the last written byte
mutable int readCount; // number of bytes read so far
mutable int readBit; // number of bits read from the last read byte
bool allowOverflow; // if false, generate an error when the message is overflowed
bool overflowed; // set to true if the buffer size failed (with allowOverflow set)
private:
bool CheckOverflow( int numBits );
byte * GetByteSpace( int length );
void WriteDelta( int oldValue, int newValue, int numBits );
int ReadDelta( int oldValue, int numBits ) const;
};
ID_INLINE void idBitMsg::Init( byte *data, int length ) {
writeData = data;
readData = data;
maxSize = length;
}
ID_INLINE void idBitMsg::Init( const byte *data, int length ) {
writeData = NULL;
readData = data;
maxSize = length;
}
ID_INLINE byte *idBitMsg::GetData( void ) {
return writeData;
}
ID_INLINE const byte *idBitMsg::GetData( void ) const {
return readData;
}
ID_INLINE int idBitMsg::GetMaxSize( void ) const {
return maxSize;
}
ID_INLINE void idBitMsg::SetAllowOverflow( bool set ) {
allowOverflow = set;
}
ID_INLINE bool idBitMsg::IsOverflowed( void ) const {
return overflowed;
}
ID_INLINE int idBitMsg::GetSize( void ) const {
return curSize;
}
ID_INLINE void idBitMsg::SetSize( int size ) {
if ( size > maxSize ) {
curSize = maxSize;
} else {
curSize = size;
}
}
ID_INLINE int idBitMsg::GetWriteBit( void ) const {
return writeBit;
}
ID_INLINE void idBitMsg::SetWriteBit( int bit ) {
writeBit = bit & 7;
if ( writeBit ) {
writeData[curSize - 1] &= ( 1 << writeBit ) - 1;
}
}
ID_INLINE int idBitMsg::GetNumBitsWritten( void ) const {
return ( ( curSize << 3 ) - ( ( 8 - writeBit ) & 7 ) );
}
ID_INLINE int idBitMsg::GetRemainingWriteBits( void ) const {
return ( maxSize << 3 ) - GetNumBitsWritten();
}
ID_INLINE void idBitMsg::SaveWriteState( int &s, int &b ) const {
s = curSize;
b = writeBit;
}
ID_INLINE void idBitMsg::RestoreWriteState( int s, int b ) {
curSize = s;
writeBit = b & 7;
if ( writeBit ) {
writeData[curSize - 1] &= ( 1 << writeBit ) - 1;
}
}
ID_INLINE int idBitMsg::GetReadCount( void ) const {
return readCount;
}
ID_INLINE void idBitMsg::SetReadCount( int bytes ) {
readCount = bytes;
}
ID_INLINE int idBitMsg::GetReadBit( void ) const {
return readBit;
}
ID_INLINE void idBitMsg::SetReadBit( int bit ) {
readBit = bit & 7;
}
ID_INLINE int idBitMsg::GetNumBitsRead( void ) const {
return ( ( readCount << 3 ) - ( ( 8 - readBit ) & 7 ) );
}
ID_INLINE int idBitMsg::GetRemainingReadBits( void ) const {
return ( curSize << 3 ) - GetNumBitsRead();
}
ID_INLINE void idBitMsg::SaveReadState( int &c, int &b ) const {
c = readCount;
b = readBit;
}
ID_INLINE void idBitMsg::RestoreReadState( int c, int b ) {
readCount = c;
readBit = b & 7;
}
ID_INLINE void idBitMsg::BeginWriting( void ) {
curSize = 0;
overflowed = false;
writeBit = 0;
}
ID_INLINE int idBitMsg::GetRemainingSpace( void ) const {
return maxSize - curSize;
}
ID_INLINE void idBitMsg::WriteByteAlign( void ) {
writeBit = 0;
}
ID_INLINE void idBitMsg::WriteChar( int c ) {
WriteBits( c, -8 );
}
ID_INLINE void idBitMsg::WriteByte( int c ) {
WriteBits( c, 8 );
}
ID_INLINE void idBitMsg::WriteShort( int c ) {
WriteBits( c, -16 );
}
ID_INLINE void idBitMsg::WriteLong( int c ) {
WriteBits( c, 32 );
}
ID_INLINE void idBitMsg::WriteUShort( int c ) {
WriteBits( c, 16 );
}
ID_INLINE void idBitMsg::WriteInt( int c ) {
WriteBits( c, 32 );
}
ID_INLINE void idBitMsg::WriteFloat( float f ) {
WriteBits( *reinterpret_cast<int *>(&f), 32 );
}
ID_INLINE void idBitMsg::WriteFloat( float f, int exponentBits, int mantissaBits ) {
int bits = idMath::FloatToBits( f, exponentBits, mantissaBits );
WriteBits( bits, 1 + exponentBits + mantissaBits );
}
ID_INLINE void idBitMsg::WriteAngle8( float f ) {
WriteByte( ANGLE2BYTE( f ) );
}
ID_INLINE void idBitMsg::WriteAngle16( float f ) {
WriteShort( ANGLE2SHORT(f) );
}
ID_INLINE void idBitMsg::WriteDir( const idVec3 &dir, int numBits ) {
WriteBits( DirToBits( dir, numBits ), numBits );
}
ID_INLINE void idBitMsg::WriteDeltaChar( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, -8 );
}
ID_INLINE void idBitMsg::WriteDeltaByte( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, 8 );
}
ID_INLINE void idBitMsg::WriteDeltaShort( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, -16 );
}
ID_INLINE void idBitMsg::WriteDeltaLong( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, 32 );
}
ID_INLINE void idBitMsg::WriteDeltaInt( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, 32 );
}
ID_INLINE void idBitMsg::WriteDeltaFloat( float oldValue, float newValue ) {
WriteDelta( *reinterpret_cast<int *>(&oldValue), *reinterpret_cast<int *>(&newValue), 32 );
}
ID_INLINE void idBitMsg::WriteDeltaFloat( float oldValue, float newValue, int exponentBits, int mantissaBits ) {
int oldBits = idMath::FloatToBits( oldValue, exponentBits, mantissaBits );
int newBits = idMath::FloatToBits( newValue, exponentBits, mantissaBits );
WriteDelta( oldBits, newBits, 1 + exponentBits + mantissaBits );
}
ID_INLINE void idBitMsg::BeginReading( void ) const {
readCount = 0;
readBit = 0;
}
ID_INLINE int idBitMsg::GetRemaingData( void ) const {
return curSize - readCount;
}
ID_INLINE void idBitMsg::ReadByteAlign( void ) const {
readBit = 0;
}
ID_INLINE int idBitMsg::ReadChar( void ) const {
return (signed char)ReadBits( -8 );
}
ID_INLINE int idBitMsg::ReadByte( void ) const {
return (unsigned char)ReadBits( 8 );
}
ID_INLINE int idBitMsg::ReadShort( void ) const {
return (short)ReadBits( -16 );
}
ID_INLINE int idBitMsg::ReadUShort( void ) const {
return (unsigned short)ReadBits( 16 );
}
ID_INLINE int idBitMsg::ReadLong( void ) const {
return ReadBits( 32 );
}
ID_INLINE int idBitMsg::ReadInt( void ) const {
return ReadBits( 32 );
}
ID_INLINE float idBitMsg::ReadFloat( void ) const {
float value;
*reinterpret_cast<int *>(&value) = ReadBits( 32 );
return value;
}
ID_INLINE float idBitMsg::ReadFloat( int exponentBits, int mantissaBits ) const {
int bits = ReadBits( 1 + exponentBits + mantissaBits );
return idMath::BitsToFloat( bits, exponentBits, mantissaBits );
}
ID_INLINE float idBitMsg::ReadAngle8( void ) const {
return BYTE2ANGLE( ReadByte() );
}
ID_INLINE float idBitMsg::ReadAngle16( void ) const {
return SHORT2ANGLE( ReadShort() );
}
ID_INLINE idVec3 idBitMsg::ReadDir( int numBits ) const {
return BitsToDir( ReadBits( numBits ), numBits );
}
ID_INLINE int idBitMsg::ReadDeltaChar( int oldValue ) const {
return (signed char)ReadDelta( oldValue, -8 );
}
ID_INLINE int idBitMsg::ReadDeltaByte( int oldValue ) const {
return (unsigned char)ReadDelta( oldValue, 8 );
}
ID_INLINE int idBitMsg::ReadDeltaShort( int oldValue ) const {
return (short)ReadDelta( oldValue, -16 );
}
ID_INLINE int idBitMsg::ReadDeltaLong( int oldValue ) const {
return ReadDelta( oldValue, 32 );
}
ID_INLINE int idBitMsg::ReadDeltaInt( int oldValue ) const {
return ReadDelta( oldValue, 32 );
}
ID_INLINE float idBitMsg::ReadDeltaFloat( float oldValue ) const {
float value;
*reinterpret_cast<int *>(&value) = ReadDelta( *reinterpret_cast<int *>(&oldValue), 32 );
return value;
}
ID_INLINE float idBitMsg::ReadDeltaFloat( float oldValue, int exponentBits, int mantissaBits ) const {
int oldBits = idMath::FloatToBits( oldValue, exponentBits, mantissaBits );
int newBits = ReadDelta( oldBits, 1 + exponentBits + mantissaBits );
return idMath::BitsToFloat( newBits, exponentBits, mantissaBits );
}
/*
===============================================================================
idBitMsgDelta
===============================================================================
*/
class idBitMsgDelta {
public:
idBitMsgDelta();
~idBitMsgDelta() {}
void Init( const idBitMsg *base, idBitMsg *newBase, idBitMsg *delta );
void Init( const idBitMsg *base, idBitMsg *newBase, const idBitMsg *delta );
bool HasChanged( void ) const;
void WriteBits( int value, int numBits );
void WriteChar( int c );
void WriteByte( int c );
void WriteShort( int c );
void WriteUShort( int c );
void WriteInt( int c );
void WriteLong( int c );
void WriteFloat( float f );
void WriteFloat( float f, int exponentBits, int mantissaBits );
void WriteAngle8( float f );
void WriteAngle16( float f );
void WriteDir( const idVec3 &dir, int numBits );
void WriteString( const char *s, int maxLength = -1 );
void WriteData( const void *data, int length );
void WriteDict( const idDict &dict );
void WriteDeltaChar( int oldValue, int newValue );
void WriteDeltaByte( int oldValue, int newValue );
void WriteDeltaShort( int oldValue, int newValue );
void WriteDeltaInt( int oldValue, int newValue );
void WriteDeltaLong( int oldValue, int newValue );
void WriteDeltaFloat( float oldValue, float newValue );
void WriteDeltaFloat( float oldValue, float newValue, int exponentBits, int mantissaBits );
void WriteDeltaByteCounter( int oldValue, int newValue );
void WriteDeltaShortCounter( int oldValue, int newValue );
void WriteDeltaLongCounter( int oldValue, int newValue );
int ReadBits( int numBits ) const;
int ReadChar( void ) const;
int ReadByte( void ) const;
int ReadShort( void ) const;
int ReadUShort( void ) const;
int ReadLong( void ) const;
int ReadInt( void ) const;
float ReadFloat( void ) const;
float ReadFloat( int exponentBits, int mantissaBits ) const;
float ReadAngle8( void ) const;
float ReadAngle16( void ) const;
idVec3 ReadDir( int numBits ) const;
void ReadString( char *buffer, int bufferSize ) const;
void ReadData( void *data, int length ) const;
void ReadDict( idDict &dict );
int ReadDeltaChar( int oldValue ) const;
int ReadDeltaByte( int oldValue ) const;
int ReadDeltaShort( int oldValue ) const;
int ReadDeltaLong( int oldValue ) const;
int ReadDeltaInt( int oldValue ) const;
float ReadDeltaFloat( float oldValue ) const;
float ReadDeltaFloat( float oldValue, int exponentBits, int mantissaBits ) const;
int ReadDeltaByteCounter( int oldValue ) const;
int ReadDeltaShortCounter( int oldValue ) const;
int ReadDeltaLongCounter( int oldValue ) const;
private:
const idBitMsg *base; // base
idBitMsg * newBase; // new base
idBitMsg * writeDelta; // delta from base to new base for writing
const idBitMsg *readDelta; // delta from base to new base for reading
mutable bool changed; // true if the new base is different from the base
private:
void WriteDelta( int oldValue, int newValue, int numBits );
int ReadDelta( int oldValue, int numBits ) const;
};
ID_INLINE idBitMsgDelta::idBitMsgDelta() {
base = NULL;
newBase = NULL;
writeDelta = NULL;
readDelta = NULL;
changed = false;
}
ID_INLINE void idBitMsgDelta::Init( const idBitMsg *base, idBitMsg *newBase, idBitMsg *delta ) {
this->base = base;
this->newBase = newBase;
this->writeDelta = delta;
this->readDelta = delta;
this->changed = false;
}
ID_INLINE void idBitMsgDelta::Init( const idBitMsg *base, idBitMsg *newBase, const idBitMsg *delta ) {
this->base = base;
this->newBase = newBase;
this->writeDelta = NULL;
this->readDelta = delta;
this->changed = false;
}
ID_INLINE bool idBitMsgDelta::HasChanged( void ) const {
return changed;
}
ID_INLINE void idBitMsgDelta::WriteChar( int c ) {
WriteBits( c, -8 );
}
ID_INLINE void idBitMsgDelta::WriteByte( int c ) {
WriteBits( c, 8 );
}
ID_INLINE void idBitMsgDelta::WriteShort( int c ) {
WriteBits( c, -16 );
}
ID_INLINE void idBitMsgDelta::WriteUShort( int c ) {
WriteBits( c, 16 );
}
ID_INLINE void idBitMsgDelta::WriteLong( int c ) {
WriteBits( c, 32 );
}
ID_INLINE void idBitMsgDelta::WriteInt( int c ) {
WriteBits( c, 32 );
}
ID_INLINE void idBitMsgDelta::WriteFloat( float f ) {
WriteBits( *reinterpret_cast<int *>(&f), 32 );
}
ID_INLINE void idBitMsgDelta::WriteFloat( float f, int exponentBits, int mantissaBits ) {
int bits = idMath::FloatToBits( f, exponentBits, mantissaBits );
WriteBits( bits, 1 + exponentBits + mantissaBits );
}
ID_INLINE void idBitMsgDelta::WriteAngle8( float f ) {
WriteBits( ANGLE2BYTE( f ), 8 );
}
ID_INLINE void idBitMsgDelta::WriteAngle16( float f ) {
WriteBits( ANGLE2SHORT(f), 16 );
}
ID_INLINE void idBitMsgDelta::WriteDir( const idVec3 &dir, int numBits ) {
WriteBits( idBitMsg::DirToBits( dir, numBits ), numBits );
}
ID_INLINE void idBitMsgDelta::WriteDeltaChar( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, -8 );
}
ID_INLINE void idBitMsgDelta::WriteDeltaByte( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, 8 );
}
ID_INLINE void idBitMsgDelta::WriteDeltaShort( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, -16 );
}
ID_INLINE void idBitMsgDelta::WriteDeltaLong( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, 32 );
}
ID_INLINE void idBitMsgDelta::WriteDeltaInt( int oldValue, int newValue ) {
WriteDelta( oldValue, newValue, 32 );
}
ID_INLINE void idBitMsgDelta::WriteDeltaFloat( float oldValue, float newValue ) {
WriteDelta( *reinterpret_cast<int *>(&oldValue), *reinterpret_cast<int *>(&newValue), 32 );
}
ID_INLINE void idBitMsgDelta::WriteDeltaFloat( float oldValue, float newValue, int exponentBits, int mantissaBits ) {
int oldBits = idMath::FloatToBits( oldValue, exponentBits, mantissaBits );
int newBits = idMath::FloatToBits( newValue, exponentBits, mantissaBits );
WriteDelta( oldBits, newBits, 1 + exponentBits + mantissaBits );
}
ID_INLINE int idBitMsgDelta::ReadChar( void ) const {
return (signed char)ReadBits( -8 );
}
ID_INLINE int idBitMsgDelta::ReadByte( void ) const {
return (unsigned char)ReadBits( 8 );
}
ID_INLINE int idBitMsgDelta::ReadShort( void ) const {
return (short)ReadBits( -16 );
}
ID_INLINE int idBitMsgDelta::ReadUShort( void ) const {
return (unsigned short)ReadBits( 16 );
}
ID_INLINE int idBitMsgDelta::ReadLong( void ) const {
return ReadBits( 32 );
}
ID_INLINE int idBitMsgDelta::ReadInt( void ) const {
return ReadBits( 32 );
}
ID_INLINE float idBitMsgDelta::ReadFloat( void ) const {
float value;
*reinterpret_cast<int *>(&value) = ReadBits( 32 );
return value;
}
ID_INLINE float idBitMsgDelta::ReadFloat( int exponentBits, int mantissaBits ) const {
int bits = ReadBits( 1 + exponentBits + mantissaBits );
return idMath::BitsToFloat( bits, exponentBits, mantissaBits );
}
ID_INLINE float idBitMsgDelta::ReadAngle8( void ) const {
return BYTE2ANGLE( ReadByte() );
}
ID_INLINE float idBitMsgDelta::ReadAngle16( void ) const {
return SHORT2ANGLE( ReadShort() );
}
ID_INLINE idVec3 idBitMsgDelta::ReadDir( int numBits ) const {
return idBitMsg::BitsToDir( ReadBits( numBits ), numBits );
}
ID_INLINE int idBitMsgDelta::ReadDeltaChar( int oldValue ) const {
return (signed char)ReadDelta( oldValue, -8 );
}
ID_INLINE int idBitMsgDelta::ReadDeltaByte( int oldValue ) const {
return (unsigned char)ReadDelta( oldValue, 8 );
}
ID_INLINE int idBitMsgDelta::ReadDeltaShort( int oldValue ) const {
return (short)ReadDelta( oldValue, -16 );
}
ID_INLINE int idBitMsgDelta::ReadDeltaLong( int oldValue ) const {
return ReadDelta( oldValue, 32 );
}
ID_INLINE int idBitMsgDelta::ReadDeltaInt( int oldValue ) const {
return ReadDelta( oldValue, 32 );
}
ID_INLINE float idBitMsgDelta::ReadDeltaFloat( float oldValue ) const {
float value;
*reinterpret_cast<int *>(&value) = ReadDelta( *reinterpret_cast<int *>(&oldValue), 32 );
return value;
}
ID_INLINE float idBitMsgDelta::ReadDeltaFloat( float oldValue, int exponentBits, int mantissaBits ) const {
int oldBits = idMath::FloatToBits( oldValue, exponentBits, mantissaBits );
int newBits = ReadDelta( oldBits, 1 + exponentBits + mantissaBits );
return idMath::BitsToFloat( newBits, exponentBits, mantissaBits );
}
#endif /* !__BITMSG_H__ */