TileData.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // TileData.cpp
  24. // Class to handle tile data.
  25. // Author: John Ahlquist, April 2001
  26. #include "W3DDevice/GameClient/TileData.h"
  27. #include "W3DDevice/GameClient/WorldHeightMap.h"
  28. //
  29. // TileData - no destructor.
  30. //
  31. //
  32. // TileData - create a new texture tile .
  33. //
  34. TileData::TileData()
  35. {
  36. }
  37. #define TILE_PIXEL_EXTENT_MIP1 32
  38. #define TILE_PIXEL_EXTENT_MIP2 16
  39. #define TILE_PIXEL_EXTENT_MIP3 8
  40. #define TILE_PIXEL_EXTENT_MIP4 4
  41. #define TILE_PIXEL_EXTENT_MIP5 2
  42. #define TILE_PIXEL_EXTENT_MIP6 1
  43. Bool TileData::hasRGBDataForWidth(Int width)
  44. {
  45. if (width == TILE_PIXEL_EXTENT) return(true);
  46. if (width == TILE_PIXEL_EXTENT_MIP1) return(true);
  47. if (width == TILE_PIXEL_EXTENT_MIP2) return(true);
  48. if (width == TILE_PIXEL_EXTENT_MIP3) return(true);
  49. if (width == TILE_PIXEL_EXTENT_MIP4) return(true);
  50. if (width == TILE_PIXEL_EXTENT_MIP5) return(true);
  51. if (width == TILE_PIXEL_EXTENT_MIP6) return(true);
  52. return(false);
  53. }
  54. UnsignedByte * TileData::getRGBDataForWidth(Int width)
  55. {
  56. // default
  57. if (width == TILE_PIXEL_EXTENT_MIP1) return(m_tileDataMip32);
  58. if (width == TILE_PIXEL_EXTENT_MIP2) return(m_tileDataMip16);
  59. if (width == TILE_PIXEL_EXTENT_MIP3) return(m_tileDataMip8);
  60. if (width == TILE_PIXEL_EXTENT_MIP4) return(m_tileDataMip4);
  61. if (width == TILE_PIXEL_EXTENT_MIP5) return(m_tileDataMip2);
  62. if (width == TILE_PIXEL_EXTENT_MIP6) return(m_tileDataMip1);
  63. return(m_tileData);
  64. }
  65. void TileData::updateMips(void)
  66. {
  67. doMip(m_tileData, TILE_PIXEL_EXTENT, m_tileDataMip32);
  68. doMip(m_tileDataMip32, TILE_PIXEL_EXTENT_MIP1, m_tileDataMip16);
  69. doMip(m_tileDataMip16, TILE_PIXEL_EXTENT_MIP2, m_tileDataMip8);
  70. doMip(m_tileDataMip8, TILE_PIXEL_EXTENT_MIP3, m_tileDataMip4);
  71. doMip(m_tileDataMip4, TILE_PIXEL_EXTENT_MIP4, m_tileDataMip2);
  72. doMip(m_tileDataMip2, TILE_PIXEL_EXTENT_MIP5, m_tileDataMip1);
  73. }
  74. void TileData::doMip(UnsignedByte *pHiRes, Int hiRow, UnsignedByte *pLoRes)
  75. {
  76. Int i, j;
  77. for (i=0; i<hiRow; i+=2) {
  78. for (j=0; j<hiRow; j+=2) {
  79. Int pxl;
  80. Int ndx = (j*hiRow+i)*TILE_BYTES_PER_PIXEL;
  81. Int loNdx = (j/2)*(hiRow/2) + (i/2);
  82. loNdx *= TILE_BYTES_PER_PIXEL;
  83. Int p;
  84. for (p=0; p<TILE_BYTES_PER_PIXEL; p++,ndx++,loNdx++) {
  85. pxl = pHiRes[ndx] + pHiRes[ndx+TILE_BYTES_PER_PIXEL] + pHiRes[ndx+TILE_BYTES_PER_PIXEL*hiRow] + pHiRes[ndx+TILE_BYTES_PER_PIXEL*hiRow+TILE_BYTES_PER_PIXEL] +2;
  86. pxl /= 4;
  87. pLoRes[loNdx] = pxl;
  88. }
  89. }
  90. }
  91. }