VisLog.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/VisLog.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 5/22/01 9:15a $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "StdAfx.H"
  36. #include "VisLog.H"
  37. #include "Utils.H"
  38. #include "ChunkIO.H"
  39. enum
  40. {
  41. LOG_CHUNK_VIS = 0x00000000,
  42. LOG_CHUNK_VIS_HEADER = 0x00000100,
  43. LEV_CHUNK_VIS_POINT_INFO = 0x00000102,
  44. };
  45. typedef struct
  46. {
  47. uint32 version;
  48. uint32 count;
  49. uint32 reserved[4];
  50. } VIS_ERROR_HEADER;
  51. /*typedef struct
  52. {
  53. Matrix3D transform;
  54. float backface_fraction;
  55. int status[6];
  56. int direction_bits;
  57. int current_direction;
  58. uint32 Reserved[4];
  59. } VIS_ERROR_INFO;*/
  60. static const uint32 CURRENT_VERSION = 0x00010000;
  61. //////////////////////////////////////////////////////////////////////////////////
  62. //
  63. // VisLogClass
  64. //
  65. //////////////////////////////////////////////////////////////////////////////////
  66. VisLogClass::VisLogClass (void)
  67. {
  68. m_ErrorList.Set_Growth_Step (5000);
  69. return ;
  70. }
  71. //////////////////////////////////////////////////////////////////////////////////
  72. //
  73. // ~VisLogClass
  74. //
  75. //////////////////////////////////////////////////////////////////////////////////
  76. VisLogClass::~VisLogClass (void)
  77. {
  78. Reset_Log ();
  79. return ;
  80. }
  81. //////////////////////////////////////////////////////////////////////////////////
  82. //
  83. // Reset_Log
  84. //
  85. //////////////////////////////////////////////////////////////////////////////////
  86. void
  87. VisLogClass::Reset_Log (void)
  88. {
  89. //
  90. // Delete all the vis samples
  91. //
  92. for (int index = 0; index < m_ErrorList.Count (); index ++) {
  93. VisSampleClass *vis_sample = m_ErrorList[index];
  94. SAFE_DELETE (vis_sample);
  95. }
  96. m_ErrorList.Delete_All ();
  97. return ;
  98. }
  99. //////////////////////////////////////////////////////////////////////////////////
  100. //
  101. // Log_Sample
  102. //
  103. //////////////////////////////////////////////////////////////////////////////////
  104. void
  105. VisLogClass::Log_Sample (const VisSampleClass &vis_sample)
  106. {
  107. //
  108. // If this sample is either a leak or an overflow, then log it
  109. // for reference later.
  110. //
  111. /*if ( vis_sample.Status == VIS_STATUS_BACKFACE_LEAK ||
  112. vis_sample.Status == VIS_STATUS_BACKFACE_OVERFLOW ||
  113. vis_sample.Status == VIS_STATUS_OK) {*/
  114. //
  115. // Add this sample to our list
  116. //
  117. if (m_ErrorList.Count () < 5000) {
  118. VisSampleClass *new_sample = new VisSampleClass (vis_sample);
  119. m_ErrorList.Add (new_sample);
  120. }
  121. //}
  122. return ;
  123. }
  124. //////////////////////////////////////////////////////////////////////////////////
  125. //
  126. // Load
  127. //
  128. //////////////////////////////////////////////////////////////////////////////////
  129. bool
  130. VisLogClass::Load (ChunkLoadClass &chunk_load)
  131. {
  132. bool retval = chunk_load.Open_Chunk ();
  133. if (retval) {
  134. bool close_both = false;
  135. //
  136. // Which chunk is this?
  137. //
  138. switch (chunk_load.Cur_Chunk_ID ())
  139. {
  140. case LOG_CHUNK_VIS:
  141. close_both = chunk_load.Open_Chunk ();
  142. case LOG_CHUNK_VIS_HEADER:
  143. {
  144. VIS_ERROR_HEADER header = { 0 };
  145. retval &= (chunk_load.Read (&header, sizeof (header)) == sizeof (header));
  146. //
  147. // Read the list of points from the chunk
  148. //
  149. for (uint32 index = 0; (index < header.count) && retval; index ++) {
  150. VisSampleClass sample;
  151. retval &= sample.Load (chunk_load);
  152. //
  153. // Add this sample to the log
  154. //
  155. if (retval) {
  156. Log_Sample (sample);
  157. }
  158. }
  159. }
  160. break;
  161. default:
  162. ASSERT (0);
  163. break;
  164. }
  165. //
  166. // Close the chunks
  167. //
  168. chunk_load.Close_Chunk ();
  169. if (close_both) {
  170. chunk_load.Close_Chunk ();
  171. }
  172. }
  173. return retval;
  174. }
  175. //////////////////////////////////////////////////////////////////////////////////
  176. //
  177. // Save
  178. //
  179. //////////////////////////////////////////////////////////////////////////////////
  180. bool
  181. VisLogClass::Save (ChunkSaveClass &chunk_save)
  182. {
  183. bool retval = false;
  184. chunk_save.Begin_Chunk (LOG_CHUNK_VIS);
  185. chunk_save.Begin_Chunk (LOG_CHUNK_VIS_HEADER);
  186. //
  187. // Write the header out to the chunk
  188. //
  189. VIS_ERROR_HEADER header = { 0 };
  190. header.version = CURRENT_VERSION;
  191. header.count = m_ErrorList.Count ();
  192. retval = (chunk_save.Write (&header, sizeof (header)) == sizeof (header));
  193. //
  194. // Now write each of the points to the chunk
  195. //
  196. for (int index = 0; (index < m_ErrorList.Count ()) && retval; index ++) {
  197. VisSampleClass *sample = m_ErrorList[index];
  198. retval &= sample->Save (chunk_save);
  199. }
  200. chunk_save.End_Chunk ();
  201. chunk_save.End_Chunk ();
  202. return retval;
  203. }