uarraytest.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 : MathTest *
  23. * *
  24. * $Archive:: /Commando/Code/Tests/mathtest/uarraytest.cpp $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 3/17/00 9:08a $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "uarraytest.h"
  36. #include "output.h"
  37. #include "vector3.h"
  38. #include "uarray.h"
  39. Vector3 InputVectors[] =
  40. {
  41. Vector3(0,0,0),
  42. Vector3(1,0,0),
  43. Vector3(1,0,0),
  44. Vector3(1,0,0),
  45. Vector3(1,0,0),
  46. Vector3(1,0,0),
  47. Vector3(5.4f,2.3f,4.5f),
  48. Vector3(0,0,0),
  49. Vector3(5.4f,2.3f,4.5f),
  50. };
  51. class VectorHasherClass : public HashCalculatorClass<Vector3>
  52. {
  53. public:
  54. virtual bool Items_Match(const Vector3 & a, const Vector3 & b)
  55. {
  56. // looking for an exact match for normals...
  57. return ((a.X == b.X) && (a.Y == b.Y) && (a.Z == b.Z));
  58. }
  59. virtual void Compute_Hash(const Vector3 & item)
  60. {
  61. HashVal = (int)(item.X*12345.6f + item.Y*1714.38484f + item.Z*27561.3f)&1023;
  62. }
  63. virtual int Num_Hash_Bits(void)
  64. {
  65. return 12; // 12bit hash value.
  66. }
  67. virtual int Num_Hash_Values(void)
  68. {
  69. return 1; // only one hash value for normals, require *exact* match
  70. }
  71. virtual int Get_Hash_Value(int index)
  72. {
  73. return HashVal;
  74. }
  75. private:
  76. int HashVal;
  77. };
  78. void Test_Uarray(void)
  79. {
  80. VectorHasherClass vectorhasher;
  81. UniqueArrayClass<Vector3> UniqueVectors(4,4,&vectorhasher);
  82. int num_input_vectors = sizeof(InputVectors) / sizeof(Vector3);
  83. int add_index;
  84. for (int vi=0; vi<num_input_vectors; vi++) {
  85. add_index = UniqueVectors.Add(InputVectors[vi]);
  86. }
  87. }