WHeightMapEdit.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // WHeightMapEdit.h
  19. // Class to contain the editing functions subclass of WorldHeightMap.
  20. // Author: John Ahlquist, April 2001
  21. #pragma once
  22. #ifndef WHeightMapEdit_H
  23. #define WHeightMapEdit_H
  24. #include "W3DDevice/GameClient/WorldHeightMap.h"
  25. class DataChunkOutput;
  26. class TerrainType;
  27. // helper class
  28. class CProcessNode
  29. {
  30. public:
  31. const Int m_x, m_y;
  32. Real m_len; ///< Length of texture coord on this node.
  33. CProcessNode *m_next;
  34. public:
  35. CProcessNode(Int x, Int y):m_x(x),m_y(y),m_next(NULL),m_len(0) {};
  36. ~CProcessNode(void) { };
  37. };
  38. #define MAX_TILES_PER_CLASS 100
  39. /// Struct in memory.
  40. typedef struct
  41. {
  42. #ifdef _DEBUG
  43. Int forDebugOnly_fileTextureClass;
  44. #endif
  45. Int numTiles;
  46. Int width;
  47. Bool isBlendEdgeTile;
  48. AsciiString name;
  49. AsciiString filePath;
  50. AsciiString uiName;
  51. TileData *tiles[MAX_TILES_PER_CLASS];
  52. TerrainType *terrainType;
  53. } TGlobalTextureClass;
  54. class WorldHeightMapEdit : public WorldHeightMap
  55. {
  56. protected:
  57. Bool m_warnTooManyTex; ///< warning message flag.
  58. Bool m_warnTooManyBlend; ///< warning message flag.
  59. // Texture classes. There is one texture class for each bitmap read in.
  60. // A class may have more than one tile. For example, if the grass bitmap is
  61. // 128x128, it creates 4 64x64 tiles, so the grass texture class will have 4 tiles.
  62. static int m_numGlobalTextureClasses;
  63. static TGlobalTextureClass m_globalTextureClasses[NUM_TEXTURE_CLASSES];
  64. protected:
  65. static void loadBitmap(char *path, const char *uiName);
  66. static void loadDirectoryOfImages(char *path);
  67. static void loadImagesFromTerrainType( TerrainType *terrain );
  68. static void loadBaseImages(void);
  69. Int allocateTiles(Int textureClass);
  70. Int allocateEdgeTiles(Int textureClass);
  71. void blendToThisClass(Int xIndex, Int yIndex, Int textureClass, Int edgeClass);
  72. void blendSpecificTiles(Int xIndex, Int yIndex, Int srcXIndex, Int srcYIndex,
  73. Int curTileNdx, Int blendTileNdx, Bool longDiagonal, Int edgeClass);
  74. Int findOrCreateBlendTile(TBlendTileInfo *pBlendInfo);
  75. Int addCliffInfo(TCliffInfo *pCliffInfo);
  76. Int getTileIndexFromTerrainType( TerrainType *terrain );
  77. Int getTileNdxForClass(Int xIndex, Int yIndex, Int textureClass);
  78. Int getBlendTileNdxForClass(Int xIndex, Int yIndex, Int textureClass);
  79. Int getTextureClassFromNdx(Int tileNdx);
  80. void getTexClassNeighbors(Int xIndex, Int yIndex, Int textureClass, Int *pSideCount, Int *pTotalCount);
  81. void updateForAdjacentCliffs(Int xIndex, Int yIndex,
  82. UnsignedByte *pProcessed, TCliffInfo &cliffInfo);
  83. Bool adjustForTiling(TCliffInfo &cliffInfo, Real textureWidth);
  84. void updateFlatCellForAdjacentCliffs(Int xIndex, Int yIndex,
  85. Int curTileClass, UnsignedByte *pProcessed=NULL);
  86. public: // construction
  87. WorldHeightMapEdit(Int xExtent, Int yExtent, UnsignedByte initialHeight, Int border); ///< create.
  88. WorldHeightMapEdit(WorldHeightMapEdit *pThis); ///< duplicate.
  89. WorldHeightMapEdit(ChunkInputStream *pStrm); ///< read from file.
  90. ~WorldHeightMapEdit(void); ///< destroy.
  91. void saveToFile(DataChunkOutput &chunkWriter);
  92. WorldHeightMapEdit *duplicate(void);
  93. static void init(void);
  94. static void shutdown(void);
  95. public: /// Status methods.
  96. void clearStatus(void) {m_warnTooManyTex = false;m_warnTooManyBlend = false;};
  97. Bool tooManyTextures(void) {return m_warnTooManyTex;};
  98. Bool tooManyBlends(void) {return m_warnTooManyBlend;};
  99. Bool canFitTexture(Int textureClass); ///< Returns true if we can fit this texture.
  100. public: // Editing methods.
  101. static UnsignedByte *getPointerToClassTileData(Int texClass);
  102. void blendTile(Int xIndex, Int yIndex, Int srcXIndex, Int srcYIndex, Int srcClass, Int edgeClass);
  103. void autoBlendOut(Int xIndex, Int yIndex, Int edgeIndex = -1);
  104. Int getTextureClass(Int xIndex, Int yIndex, Bool baseClass=false);
  105. void setHeight(Int xIndex, Int yIndex, UnsignedByte height);
  106. void setCliff(Int xIndex, Int yIndex, Bool impassable) {setCliffState(xIndex, yIndex, impassable);}
  107. Bool setTileNdx(Int xIndex, Int yIndex, Int textureClass, Bool singleTile);
  108. Bool floodFill(Int xIndex, Int yIndex, Int textureClass, Bool doReplace);
  109. static Int getNumTexClasses(void) {return m_numGlobalTextureClasses;};
  110. static AsciiString getTexClassName(int ndx) {return m_globalTextureClasses[ndx].name;}
  111. static AsciiString getTexClassUiName(int ndx) ;
  112. static Int getTexClassNumTiles(int ndx) {return m_globalTextureClasses[ndx].numTiles;}
  113. static Int getTexClassIsBlendEdge(int ndx) {return m_globalTextureClasses[ndx].isBlendEdgeTile;}
  114. void addObject(MapObject *pMapObj); ///< Adds a map object to the front of the list.
  115. void removeFirstObject(void); ///< Removes the first map object from the list.
  116. Bool isTexClassUsed(Int textureClass);
  117. Int getFirstTile(Int textureClass);
  118. Bool optimizeTiles(void); ///< Optimizes tile allocations.
  119. void showTileStatusInfo(void); ///< pops up a dialog box with tile mem usage.
  120. Bool selectDuplicates(void); ///< Selects any dupicate map objects.
  121. Bool selectSimilar(void); ///< Selects any dupicate map objects.
  122. Bool selectInvalidTeam(void); ///< Selects any objects with invalid teams.
  123. Bool resize(Int newXSize, Int newYSize, Int newHeight, Int newBorder, Bool anchorTop, Bool anchorBottom,
  124. Bool anchorLeft, Bool anchorRight, Coord3D *pObjOffset);
  125. Bool remapTextures(void); ///< returns true if the operation had an effect.
  126. void reloadTextures(void); ///< Reloads textures from disk.
  127. void resetResources(void); ///< Releases textures in preparation for device reset.
  128. void dbgVerifyAfterUndo(void); ///< Verifies the structures are still consistent.
  129. Bool doCliffAdjustment(Int xIndex, Int yIndex);
  130. Bool removeCliffMapping(void);
  131. Int getNumBoundaries(void) const ;
  132. void getBoundary(Int ndx, ICoord2D* border) const;
  133. void addBoundary(ICoord2D* boundaryToAdd);
  134. void changeBoundary(Int ndx, ICoord2D *border);
  135. void removeLastBoundary(void);
  136. // outNdx must not be NULL, but outHandle can be.
  137. // outHandle: 0 means BL, 1 means TL, 2 means TR, 3 means BR
  138. void findBoundaryNear(Coord3D *pt, float okDistance, Int *outNdx, Int *outHandle);
  139. };
  140. #endif