BitPacker.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //
  19. // Filename: bitpacker.h
  20. // Project: wwbitpack.lib
  21. // Author: Tom Spencer-Smith
  22. // Date: June 1998
  23. // Description: Minimal bit encoding
  24. //
  25. #ifndef BITPACKER_H
  26. #define BITPACKER_H
  27. #include "always.h"
  28. #include "bittype.h"
  29. #pragma warning(disable:4514)
  30. static const int MAX_BITS = 32;
  31. // 1400 is too big. Minimum MTU allowable on the internet is 576. IP Header is 20 bytes. UDP header is 8 bytes
  32. // So our max packet size is 576 - 28 = 548
  33. //static const int MAX_BUFFER_SIZE = 1400;
  34. static const int MAX_BUFFER_SIZE = 548;
  35. class cBitPacker
  36. {
  37. public:
  38. //cBitPacker(UINT buffer_size);
  39. cBitPacker();
  40. virtual ~cBitPacker();
  41. char * Get_Data() const {return (char *) Buffer;}
  42. //UINT Get_Buffer_Size() const {return BufferSize;}
  43. UINT Get_Buffer_Size() const {return MAX_BUFFER_SIZE;}
  44. void Flush() {BitReadPosition = BitWritePosition;}
  45. bool Is_Flushed() const {return (BitReadPosition == BitWritePosition);}
  46. void Add_Bits(ULONG value, UINT num_bits);
  47. void Get_Bits(ULONG & value, UINT num_bits);
  48. void Set_Bit_Write_Position(UINT position);
  49. UINT Get_Bit_Write_Position() const {return BitWritePosition;}
  50. protected:
  51. cBitPacker& operator=(const cBitPacker& rhs);
  52. private:
  53. cBitPacker(const cBitPacker& source); // Disallow copy constructor
  54. //BYTE * Buffer;
  55. //const UINT BufferSize;
  56. BYTE Buffer[MAX_BUFFER_SIZE];
  57. UINT BitWritePosition;
  58. UINT BitReadPosition;
  59. };
  60. #endif // BITPACKER_H
  61. /*
  62. void Reset() {BitWritePosition = 0;}
  63. UINT Get_Compressed_Size_Bytes() const;
  64. void Flush() {NumBits = 0;}
  65. bool Is_Flushed() const {return (NumBits < 8);}
  66. void Set_Num_Bits(int num) {WWASSERT(num >= 0); NumBits = num;}
  67. int Get_Num_Bits(void) {return NumBits;}
  68. void Increment_Bit_Position(int num_bits);
  69. //inline void Advance_Bit_Position();
  70. //int NumBits;
  71. */