TileData.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // TileData.h
  24. // Class to hold 1 tile's data.
  25. // Author: John Ahlquist, April 2001
  26. #pragma once
  27. #ifndef TileData_H
  28. #define TileData_H
  29. #include <stdio.h>
  30. #include "Lib/BaseType.h"
  31. #include "WWLib/RefCount.h"
  32. #include "Common/AsciiString.h"
  33. typedef struct {
  34. Int blendNdx;
  35. UnsignedByte horiz;
  36. UnsignedByte vert;
  37. UnsignedByte rightDiagonal;
  38. UnsignedByte leftDiagonal;
  39. UnsignedByte inverted;
  40. UnsignedByte longDiagonal;
  41. Int customBlendEdgeClass; // Class of texture for a blend edge. -1 means use alpha.
  42. } TBlendTileInfo;
  43. #define INVERTED_MASK 0x1 //AND this with TBlendTileInfo.inverted to get actual inverted state
  44. #define FLIPPED_MASK 0x2 //AND this with TBlendTileInfo.inverted to get forced flip state (for horizontal/vertical flips).
  45. #define TILE_PIXEL_EXTENT 64
  46. #define TILE_BYTES_PER_PIXEL 4
  47. #define DATA_LEN_BYTES TILE_PIXEL_EXTENT*TILE_PIXEL_EXTENT*TILE_BYTES_PER_PIXEL
  48. #define DATA_LEN_PIXELS TILE_PIXEL_EXTENT*TILE_PIXEL_EXTENT
  49. #define TILE_PIXEL_EXTENT_MIP1 32
  50. #define TILE_PIXEL_EXTENT_MIP2 16
  51. #define TILE_PIXEL_EXTENT_MIP3 8
  52. #define TILE_PIXEL_EXTENT_MIP4 4
  53. #define TILE_PIXEL_EXTENT_MIP5 2
  54. #define TILE_PIXEL_EXTENT_MIP6 1
  55. #define TEXTURE_WIDTH 2048 // was 1024 jba
  56. /** This class holds the bitmap data from the .tga texture files. It is used to
  57. create the D3D texture in the game and 3d windows, and to create DIB data for the
  58. 2d window. */
  59. class TileData : public RefCountClass
  60. {
  61. protected:
  62. // data is bgrabgrabgra to be compatible with windows blt. jba.
  63. // Also, first byte is lower left pixel, not upper left pixel.
  64. // so 0,0 is lower left, not upper left.
  65. UnsignedByte m_tileData[DATA_LEN_BYTES];
  66. /// Mipped down copies of the tile data.
  67. UnsignedByte m_tileDataMip32[TILE_PIXEL_EXTENT_MIP1*TILE_PIXEL_EXTENT_MIP1*TILE_BYTES_PER_PIXEL];
  68. UnsignedByte m_tileDataMip16[TILE_PIXEL_EXTENT_MIP2*TILE_PIXEL_EXTENT_MIP2*TILE_BYTES_PER_PIXEL];
  69. UnsignedByte m_tileDataMip8[TILE_PIXEL_EXTENT_MIP3*TILE_PIXEL_EXTENT_MIP3*TILE_BYTES_PER_PIXEL];
  70. UnsignedByte m_tileDataMip4[TILE_PIXEL_EXTENT_MIP4*TILE_PIXEL_EXTENT_MIP4*TILE_BYTES_PER_PIXEL];
  71. UnsignedByte m_tileDataMip2[TILE_PIXEL_EXTENT_MIP5*TILE_PIXEL_EXTENT_MIP5*TILE_BYTES_PER_PIXEL];
  72. UnsignedByte m_tileDataMip1[TILE_PIXEL_EXTENT_MIP6*TILE_PIXEL_EXTENT_MIP6*TILE_BYTES_PER_PIXEL];
  73. public:
  74. ICoord2D m_tileLocationInTexture;
  75. protected:
  76. /** doMip - generates the next mip level mipping pHiRes down to pLoRes.
  77. pLoRes is 1/2 the width of pHiRes, and both are square. */
  78. static void doMip(UnsignedByte *pHiRes, Int hiRow, UnsignedByte *pLoRes);
  79. public:
  80. TileData(void);
  81. public:
  82. UnsignedByte *getDataPtr(void) {return(m_tileData);};
  83. static Int dataLen(void) {return(DATA_LEN_BYTES);};
  84. void updateMips(void);
  85. Bool hasRGBDataForWidth(Int width);
  86. UnsignedByte *getRGBDataForWidth(Int width);
  87. };
  88. #endif