WHeightMapEdit.h 6.7 KB

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