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