afxZodiacDefs.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #ifndef _AFX_ZODIAC_DEFS_H_
  25. #define _AFX_ZODIAC_DEFS_H_
  26. class afxZodiacDefs
  27. {
  28. public:
  29. enum
  30. {
  31. MAX_ZODIACS = 256,
  32. N_ZODIAC_FIELD_INTS = (MAX_ZODIACS - 1) / 32 + 1,
  33. };
  34. enum
  35. {
  36. BLEND_NORMAL = 0x0,
  37. BLEND_ADDITIVE = 0x1,
  38. BLEND_SUBTRACTIVE = 0x2,
  39. BLEND_RESERVED = 0x3,
  40. BLEND_MASK = 0x3
  41. };
  42. enum
  43. {
  44. SHOW_ON_TERRAIN = BIT(2),
  45. SHOW_ON_INTERIORS = BIT(3),
  46. SHOW_ON_WATER = BIT(4),
  47. SHOW_ON_MODELS = BIT(5),
  48. //
  49. SHOW_IN_NON_REFLECTIONS = BIT(6),
  50. SHOW_IN_REFLECTIONS = BIT(7),
  51. //
  52. RESPECT_ORIENTATION = BIT(8),
  53. SCALE_VERT_RANGE = BIT(9),
  54. INVERT_GRADE_RANGE = BIT(10),
  55. USE_GRADE_RANGE = BIT(11),
  56. PREFER_DEST_GRADE = BIT(12),
  57. //
  58. INTERIOR_VERT_IGNORE = BIT(13),
  59. INTERIOR_HORIZ_ONLY = BIT(14),
  60. INTERIOR_BACK_IGNORE = BIT(15),
  61. INTERIOR_OPAQUE_IGNORE = BIT(16),
  62. INTERIOR_TRANSP_IGNORE = BIT(17),
  63. //
  64. INTERIOR_FILTERS = INTERIOR_VERT_IGNORE | INTERIOR_HORIZ_ONLY | INTERIOR_BACK_IGNORE
  65. };
  66. };
  67. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  68. class afxZodiacBitmask : public afxZodiacDefs
  69. {
  70. U32 mBits[N_ZODIAC_FIELD_INTS];
  71. public:
  72. afxZodiacBitmask() { clear(); }
  73. afxZodiacBitmask(const afxZodiacBitmask& field) { *this = field; }
  74. bool test(U32 index)
  75. {
  76. U32 word = index / 32;
  77. U32 bit = index % 32;
  78. return mBits[word] & (1 << bit);
  79. }
  80. void set(U32 index)
  81. {
  82. U32 word = index / 32;
  83. U32 bit = index % 32;
  84. mBits[word] |= 1 << bit;
  85. }
  86. void unset(U32 index)
  87. {
  88. U32 word = index / 32;
  89. U32 bit = index % 32;
  90. mBits[word] &= ~(1 << bit);
  91. }
  92. S32 findLastSetBit(U32 startbit=(MAX_ZODIACS-1))
  93. {
  94. U32 word = startbit / 32;
  95. U32 bit = startbit % 32;
  96. if (mBits[word] != 0)
  97. {
  98. U32 mask = mBits[word] << (31-bit);
  99. for (U32 j = bit; j >= 0; j--)
  100. {
  101. if (mask & 0x80000000)
  102. return word*32 + j;
  103. mask <<= 1;
  104. }
  105. }
  106. for (U32 k = word-1; k >= 0; k--)
  107. {
  108. if (mBits[k] != 0)
  109. {
  110. U32 mask = mBits[k];
  111. for (U32 j = 31; j >= 0; j--)
  112. {
  113. if (mask & 0x80000000)
  114. return k*32 + j;
  115. mask <<= 1;
  116. }
  117. }
  118. }
  119. return -1;
  120. }
  121. void clear()
  122. {
  123. for (U32 k = 0; k < N_ZODIAC_FIELD_INTS; k++)
  124. mBits[k] = 0x00000000;
  125. }
  126. bool isEmpty()
  127. {
  128. for (U32 k = 0; k < N_ZODIAC_FIELD_INTS; k++)
  129. if (mBits[k] != 0)
  130. return false;
  131. return true;
  132. }
  133. afxZodiacBitmask& operator=(const afxZodiacBitmask& field)
  134. {
  135. for (U32 k = 0; k < N_ZODIAC_FIELD_INTS; k++)
  136. mBits[k] = field.mBits[k];
  137. return *this;
  138. }
  139. operator bool() { return !isEmpty(); }
  140. };
  141. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  142. #endif // _AFX_ZODIAC_DEFS_H_