SphereUtils.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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/W3DView/SphereUtils.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 3/08/00 7:21p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "sphereutils.h"
  37. /////////////////////////////////////////////////////////////
  38. //
  39. // Resize
  40. //
  41. /////////////////////////////////////////////////////////////
  42. void
  43. SphereKeysClass::Resize (int max_keys)
  44. {
  45. //
  46. // Determine the new array size
  47. //
  48. int blocks = (max_keys / 10) + 1;
  49. int array_size = blocks * 10;
  50. if (array_size != m_MaxKeys) {
  51. //
  52. // Allocate the new array
  53. //
  54. W3dSphereKeyFrameStruct *key_array = new W3dSphereKeyFrameStruct[array_size];
  55. //
  56. // Copy the contents of the old array
  57. //
  58. ::memcpy (key_array, m_Keys, m_KeyCount * sizeof (W3dSphereKeyFrameStruct));
  59. //
  60. // Use the new array
  61. //
  62. SAFE_DELETE_ARRAY (m_Keys);
  63. m_Keys = key_array;
  64. m_MaxKeys = array_size;
  65. }
  66. return ;
  67. }
  68. /////////////////////////////////////////////////////////////
  69. //
  70. // Add_Keys
  71. //
  72. /////////////////////////////////////////////////////////////
  73. void
  74. SphereKeysClass::Add_Keys (W3dSphereKeyFrameStruct *keys, int key_count)
  75. {
  76. //
  77. // Make sure we have a large enough array
  78. //
  79. Resize (m_KeyCount + key_count);
  80. //
  81. // Copy the new keys into our array
  82. //
  83. ::memcpy (&m_Keys[m_KeyCount + 1], keys, key_count * sizeof (W3dSphereKeyFrameStruct));
  84. m_KeyCount += keys;
  85. return ;
  86. }
  87. /////////////////////////////////////////////////////////////
  88. //
  89. // Add_Key
  90. //
  91. /////////////////////////////////////////////////////////////
  92. void
  93. SphereKeysClass::Add_Key (W3dSphereKeyFrameStruct &keys)
  94. {
  95. Add_Keys (&keys, 1);
  96. return ;
  97. }
  98. /////////////////////////////////////////////////////////////
  99. //
  100. // Free_Keys
  101. //
  102. /////////////////////////////////////////////////////////////
  103. void
  104. SphereKeysClass::Free_Keys (void)
  105. {
  106. SAFE_DELETE_ARRAY (m_Keys);
  107. m_KeyCount = 0;
  108. m_MaxKeys = 0;
  109. return ;
  110. }
  111. /////////////////////////////////////////////////////////////
  112. //
  113. // Detach
  114. //
  115. /////////////////////////////////////////////////////////////
  116. void
  117. SphereKeysClass::Detach (void)
  118. {
  119. m_Keys = NULL;
  120. m_KeyCount = 0;
  121. m_MaxKeys = 0;
  122. return ;
  123. }
  124. /////////////////////////////////////////////////////////////
  125. //
  126. // Key_Compare
  127. //
  128. // Compares two keys based on their time value
  129. //
  130. /////////////////////////////////////////////////////////////
  131. static int
  132. Key_Compare (const void *arg1, const void *arg2)
  133. {
  134. ASSERT (arg1 != NULL);
  135. ASSERT (arg2 != NULL);
  136. W3dSphereKeyFrameStruct *key1 = (W3dSphereKeyFrameStruct *)arg1;
  137. W3dSphereKeyFrameStruct *key2 = (W3dSphereKeyFrameStruct *)arg2;
  138. int retval = 0
  139. float delta = key1->time_code - key2->time_code;
  140. if (delta < 0) {
  141. retval = -1;
  142. } else if (delta > 0) {
  143. retval = 1;
  144. }
  145. return retval;
  146. }
  147. /////////////////////////////////////////////////////////////
  148. //
  149. // Sort
  150. //
  151. // Linerally sorts the keys based on their time value
  152. //
  153. /////////////////////////////////////////////////////////////
  154. void
  155. SphereKeysClass::Sort (void)
  156. {
  157. if (m_Keys != NULL && m_KeyCount > 0) {
  158. ::qsort (m_Keys, m_KeyCount, sizeof (W3dSphereKeyFrameStruct), Key_Compare);
  159. }
  160. return ;
  161. }