PostalAttrib.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // ATTRIBUTE.H
  19. //
  20. // Created on 10/03/96 JMI
  21. // Implemented 03/14/97 JRD
  22. //
  23. // 03/18/97 JRD Started this file to remove the Postal specific
  24. // interpretation of RAttribute out of the orange
  25. // layer to allow a second attribute grid with different
  26. // interpretations.
  27. //
  28. //////////////////////////////////////////////////////////////////////
  29. // After Postal, this class will be renamed to something more general
  30. // such as "RMultiGrid", since attribute data can be stored in many ways
  31. #ifndef ATTRIBUTE_H
  32. #define ATTRIBUTE_H
  33. #include "System.h"
  34. #ifdef PATHS_IN_INCLUDES
  35. #include "BLUE/Blue.h"
  36. #include "ORANGE/File/file.h"
  37. #else
  38. #include "Blue.h"
  39. #include "file.h"
  40. #endif // PATHS_IN_INCLUDES
  41. #define ATTRIBUTE_MAP_COOKIE 0x4d525441 //Looks like "ATRM" in the file
  42. #define ATTRIBUTE_CURRENT_VERSION 6
  43. //////////////////////////////////////////////////////////////////////
  44. // Here are the Postal attribute masks, grouped by word.
  45. //////////////////////////////////////////////////////////////////////
  46. //
  47. // NOTE: FOR SPEED REASONS, do NOT SHIFT values unless ABSOLUTELY
  48. // necessary. This is not needed for flags, or numeric fields when
  49. // only relative values are important. If a field TRULY needs to
  50. // have absolute values, it should be stored in the correct place in
  51. // the attribute mask.
  52. //
  53. // ALSO: AVOID using fields which need both OFFSETS and SCALING!
  54. // (To create a signed field, just subtract half)
  55. //
  56. // NOTE: MACROS for VALUES are for comparison ONLY - they cannot be
  57. // used for ANDing and ORing
  58. //
  59. //////////////////////////////////////////////////////////////////////
  60. // Postal Attribute Map ONE:
  61. //////////////////////////////////////////////////////////////////////
  62. // BITS 0-7, signed numeric field
  63. #define ATTRIBUTE_HEIGHT_MASK 0x00FF // Mask of height bits.
  64. // BITS 8-11, unsigned numeric field
  65. #define ATTRIBUTE_LAYER_MASK 0x0F00 // Mask of layer cue
  66. // BIT 12, flag
  67. #define ATTRIBUTE_CLIFF 0x1000 // cliff attribute
  68. // BIT 13, flag
  69. #define ATTRIBUTE_NOT_WALKABLE 0x2000 // Flag for no-walk areas.
  70. // BIT 14, flag
  71. #define ATTRIBUTE_LIGHT_EFFECT 0x4000 // Flag for light
  72. //////////////////////////////////////////////////////////////////////
  73. // Postal Attribute Map TWO:
  74. //////////////////////////////////////////////////////////////////////
  75. // BITS 0-10 OPENED FOR ALL POSTAL DUDES!
  76. // That's 2048 possibilities opened up for the postal crew!
  77. // BITS 11-12, unsigned numeric field
  78. #define ATTRIBUTE_RESERVED1_MASK 0x1800 // I reserve two for later
  79. // BITS 13-14, unsigned numberic field
  80. #define ATTRIBUTE_FLUID_MASK 0x6000 // Mask of fluids
  81. #define ATTRIBUTE_BLOOD_VALUE 0x2000 // Value of BLOOD
  82. #define ATTRIBUTE_OIL_VALUE 0x4000 // Value of GASOLINE
  83. #define ATTRIBUTE_WATER_VALUE 0x6000 // Value of WATER
  84. //////////////////////////////////////////////////////////////////////
  85. //////////////////////////////////////////////////////////////////////
  86. // The goal was to make getting the field of an attribute have ZERO
  87. // cost to the user. One change is that since BIT15 is removed
  88. // from the attribute on decompression, all values deal with
  89. // SIGNED shorts. The meaning is uneffected, but it provides greater
  90. // compatibility and options with comparing external values.
  91. //////////////////////////////////////////////////////////////////////
  92. //////////////////////////////////////////////////////////////////////
  93. // Here are Postal specific interpretations of fields:
  94. // Add as many as you like, but consolidate them here.
  95. // All will be considered DYNAMIC -> changeable like the wind!
  96. //////////////////////////////////////////////////////////////////////
  97. //////////////////////////////////////////////////////////////////////
  98. // Somewhat general macros
  99. //////////////////////////////////////////////////////////////////////
  100. // interpret a flag as 1 or zero
  101. inline short GetFlag(short sMaskedValue)
  102. {
  103. // faster than : ? assembly.
  104. if (sMaskedValue) return 1;
  105. return 0;
  106. }
  107. // interpret a field as a signed range:
  108. inline short GetField(short sMaskedValue,short sLowValue)
  109. {
  110. return sMaskedValue + sLowValue;
  111. }
  112. // interpret a field as a signed, scaled range:
  113. // FIRST scale it, THEN offset it!
  114. // DO NOT shift left more than 2 bits!
  115. //
  116. inline short GetFieldMul(short sMaskedValue,short sLowValue,short sMulBits)
  117. {
  118. return (sMaskedValue<<sMulBits) + sLowValue;
  119. }
  120. // interpret a field as a signed, scaled range:
  121. // FIRST scale it, THEN offset it!
  122. // DO NOT shift right more than 8 bits!
  123. //
  124. inline short GetFieldDiv(short sMaskedValue,short sLowValue,short sDivBits)
  125. {
  126. return (sMaskedValue>>sDivBits) + sLowValue;
  127. }
  128. //////////////////////////////////////////////////////////////////////
  129. // very specific macros (try to design attribute position to optimize!)
  130. //////////////////////////////////////////////////////////////////////
  131. // As always, these are PRE-MASKED fields!
  132. // range is -512 to +511 from 8 bits
  133. //
  134. inline short GetHeight(short sMaskedValue)
  135. {
  136. return GetFieldMul(sMaskedValue,-512,2);
  137. }
  138. // range is 0 to 15
  139. //
  140. inline short GetLayer(short sMaskedValue))
  141. {
  142. return (sMaskedValue >> 8);
  143. }
  144. //-------//-----//
  145. #endif // EOF //
  146. //-------//-----//