mapdata.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //---------------------------------------------------------------------------
  2. //
  3. // MapData.h -- File contains class definitions for the Terrain Mesh
  4. //
  5. // MechCommander 2
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef MAPDATA_H
  11. #define MAPDATA_H
  12. //---------------------------------------------------------------------------
  13. // Include Files
  14. #ifndef DMAPDATA_H
  15. #include "dmapdata.h"
  16. #endif
  17. #ifndef HEAP_H
  18. #include "heap.h"
  19. #endif
  20. #ifndef PACKET_H
  21. #include "packet.h"
  22. #endif
  23. #ifndef VERTEX_H
  24. #include "vertex.h"
  25. #endif
  26. #ifndef QUAD_H
  27. #include "quad.h"
  28. #endif
  29. #include <stuff\stuff.hpp>
  30. //---------------------------------------------------------------------------
  31. enum Overlays
  32. {
  33. INVALID_OVERLAY = -1,
  34. DIRT_ROAD = 0,
  35. PAVED_ROAD = 1,
  36. ROUGH = 2,
  37. DIRT_ROAD_TO_PAVED_ROAD = 3,
  38. PAVED_ROAD_CROSSING_DIRT_ROAD = 4,
  39. TWO_LANE_DIRT_ROAD = 5,
  40. DAMAGED_ROAD = 6,
  41. RUNWAY = 7,
  42. X_DIRT_PAVED = 8,
  43. X_DIRT_2LANEDIRT = 9,
  44. X_DIRT_DAMAGED = 10,
  45. X_2LANEDIRT_PAVED = 11,
  46. X_DAMAGED_PAVED = 12,
  47. X_2LANEDIRT_DAMAGED = 13,
  48. OBRIDGE = 14,
  49. X_PAVED_ROAD_BRIDGE = 15,
  50. DAMAGED_BRIDGE = 16,
  51. NUM_OVERLAY_TYPES = 17
  52. };
  53. //---------------------------------------------------------------------------
  54. // Classes
  55. class MapData : public HeapManager
  56. {
  57. //Data Members
  58. //-------------
  59. protected:
  60. PostcompVertexPtr blocks;
  61. PostcompVertexPtr blankVertex;
  62. int hasSelection;
  63. public:
  64. Stuff::Vector2DOf<float> topLeftVertex;
  65. static float shallowDepth;
  66. static float waterDepth;
  67. static float alphaDepth;
  68. static DWORD WaterTXMData;
  69. //Member Functions
  70. //-----------------
  71. public:
  72. void *operator new (size_t mySize);
  73. void operator delete (void *us);
  74. void init (void)
  75. {
  76. HeapManager::init();
  77. topLeftVertex.Zero();
  78. blocks = NULL;
  79. blankVertex = NULL;
  80. hasSelection = false;
  81. shallowDepth = 0.0f;
  82. waterDepth = 0.0f;
  83. alphaDepth = 0.0f;
  84. WaterTXMData = 0xffffffff;
  85. }
  86. MapData (void) : HeapManager()
  87. {
  88. init();
  89. }
  90. void destroy (void);
  91. ~MapData (void)
  92. {
  93. destroy();
  94. }
  95. long init (char *fileName, long numBlocks, long blockSize);
  96. void newInit (PacketFile* file, long numVertices);
  97. void newInit (long numVertices);
  98. long update (void);
  99. void makeLists (VertexPtr vertexList, long &numVerts, TerrainQuadPtr quadList, long &numTiles);
  100. Stuff::Vector2DOf<float> getTopLeftVertex (void)
  101. {
  102. return topLeftVertex;
  103. }
  104. void calcLight (void);
  105. void clearShadows();
  106. float terrainElevation (Stuff::Vector3D &position);
  107. float terrainElevation ( long tileR, long tileC );
  108. float terrainAngle (Stuff::Vector3D &position, Stuff::Vector3D* normal = NULL);
  109. Stuff::Vector3D terrainNormal (Stuff::Vector3D& position);
  110. float terrainLight (Stuff::Vector3D& position);
  111. float getTopLeftElevation (void);
  112. // old overlay stuff
  113. void setOverlayTile (long block, long vertex, long offset);
  114. long getOverlayTile (long block, long vertex);
  115. // new overlay stuff
  116. void setOverlay( long tileR, long tileC, Overlays type, unsigned long Offset );
  117. void getOverlay( long tileR, long tileC, Overlays& type, unsigned long& Offset );
  118. void setTerrain( long tileR, long tileC, int terrainType );
  119. long getTerrain( long tileR, long tileC );
  120. void setVertexHeight( int vertexIndex, float value );
  121. float getVertexHeight( int vertexIndex );
  122. PostcompVertexPtr getData (void)
  123. {
  124. return blocks;
  125. }
  126. unsigned long getTexture( long tileR, long tileC );
  127. long save( PacketFile* file, int whichPacket);
  128. void calcWater (float waterDepth, float waterShallowDepth, float waterAlphaDepth);
  129. void recalcWater (void); //Uses above values already passed in to just recalc the water
  130. float waterElevation () { return waterDepth; }
  131. void markSeen (Stuff::Vector2DOf<float> &topLeftPosition, VertexPtr vertexList, Stuff::Vector3D &looker, Stuff::Vector3D &lookVector, float cone, float dist, byte who);
  132. void unselectAll();
  133. void unhighlightAll();
  134. void highlightAllTransitionsOver2 (void);
  135. void selectVertex( unsigned long tileRow, unsigned long tileCol, bool bSelect, bool bToggle );
  136. bool selection(){ return hasSelection ? true : false; }
  137. bool isVertexSelected( unsigned long tileRow, unsigned long tileCol );
  138. void calcTransitions();
  139. };
  140. //-----------------------------------------------------------------------------------------------
  141. #endif