vistable.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/vistable.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 8/13/00 11:43a $*
  29. * *
  30. * $Revision:: 16 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef VISTABLE_H
  39. #define VISTABLE_H
  40. #include "vector.h"
  41. #include "bittype.h"
  42. #include "refcount.h"
  43. #include "multilist.h"
  44. #include "wwdebug.h"
  45. class ChunkLoadClass;
  46. class ChunkSaveClass;
  47. class CompressedVisTableClass;
  48. /*
  49. ** VisTableClass
  50. ** This is a bit vector which contains a bit for each static node in the world indicating
  51. ** whether that node can be seen from the current "vis-sector"
  52. */
  53. class VisTableClass : public RefCountClass, public MultiListObjectClass
  54. {
  55. public:
  56. VisTableClass(unsigned bitcount,int id);
  57. VisTableClass(CompressedVisTableClass * ctable,int bitcount,int id);
  58. VisTableClass(const VisTableClass & that);
  59. ~VisTableClass(void);
  60. VisTableClass & operator = (const VisTableClass & that);
  61. int Get_Bit_Count(void) const { return BitCount; }
  62. void Reset_All(void);
  63. void Set_All(void);
  64. int Get_Bit(int i) const;
  65. void Set_Bit(int i,bool onoff);
  66. void Delete_Bit(int i);
  67. void Merge(const VisTableClass & that);
  68. void Invert(void);
  69. bool Is_Equal_To(const VisTableClass & that);
  70. int Count_Differences(const VisTableClass & that);
  71. int Count_True_Bits(void);
  72. float Match_Fraction(const VisTableClass & that);
  73. void Set_Vis_Sector_ID(int id) { VisSectorID = id; }
  74. int Get_Vis_Sector_ID(void) { return VisSectorID; }
  75. void Set_Time_Stamp(int timestamp) { Timestamp = timestamp; }
  76. int Get_Time_Stamp(void) const { return Timestamp; }
  77. protected:
  78. void Alloc_Buffer(int bitcount);
  79. int Get_Byte_Count(void) const;
  80. int Get_Long_Count(void) const;
  81. uint8 * Get_Bytes(void) const;
  82. uint32 * Get_Longs(void) const;
  83. int BitCount;
  84. uint32 * Buffer;
  85. int VisSectorID;
  86. int Timestamp;
  87. // Not implemented:
  88. bool operator == (const VisTableClass & that);
  89. friend class CompressedVisTableClass;
  90. };
  91. /*
  92. ** CompressedVisTableClass
  93. ** This is the form that pvs data is stored in memory when it is not being used. It
  94. ** is basically a wrapper around an allocated array with functions to compress and
  95. ** decompress to/from a VisTableClass and functions for saving and loading.
  96. */
  97. class CompressedVisTableClass
  98. {
  99. public:
  100. CompressedVisTableClass(void);
  101. CompressedVisTableClass(VisTableClass * bits);
  102. CompressedVisTableClass(const CompressedVisTableClass &that);
  103. ~CompressedVisTableClass(void);
  104. const CompressedVisTableClass &operator= (const CompressedVisTableClass &that);
  105. void Load(void* hfile);
  106. void Save(void* hfile);
  107. void Load(ChunkLoadClass & cload);
  108. void Save(ChunkSaveClass & csave);
  109. protected:
  110. int Get_Byte_Count(void) const;
  111. uint8 * Get_Bytes(void);
  112. void Compress(uint8 * src_buffer,int src_size);
  113. void Decompress(uint8 * decomp_buffer,int decomp_size);
  114. int BufferSize;
  115. uint8 * Buffer;
  116. // Not implemented:
  117. bool operator == (const CompressedVisTableClass & that);
  118. friend class VisTableClass;
  119. };
  120. inline int VisTableClass::Get_Bit(int i) const
  121. {
  122. WWASSERT(Buffer != NULL);
  123. WWASSERT(i < BitCount);
  124. return (Buffer[i>>5] & (0x80000000u >> (i & 0x1F)));
  125. }
  126. inline void VisTableClass::Set_Bit(int i,bool onoff)
  127. {
  128. WWASSERT(Buffer != NULL);
  129. WWASSERT(i < BitCount);
  130. if (onoff) {
  131. Buffer[i>>5] |= (0x80000000u >> (i & 0x01F));
  132. } else {
  133. Buffer[i>>5] &= ~(0x80000000u >> (i & 0x01F));
  134. }
  135. }
  136. #endif