INIWater.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. // FILE: INIWater.cpp /////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, December 2001
  25. // Desc: Water settings
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #define DEFINE_TIME_OF_DAY_NAMES
  30. #include "Common/INI.h"
  31. #include "Common/GameType.h"
  32. #include "GameClient/TerrainVisual.h"
  33. #include "GameClient/Water.h"
  34. ///////////////////////////////////////////////////////////////////////////////////////////////////
  35. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////
  37. //-------------------------------------------------------------------------------------------------
  38. /** Water setting, note that this does not support override situations. As the water
  39. * system becomes more complex we may want to change this */
  40. //-------------------------------------------------------------------------------------------------
  41. void INI::parseWaterSettingDefinition( INI* ini )
  42. {
  43. AsciiString name;
  44. WaterSetting *waterSetting = NULL;
  45. // read the name
  46. const char* token = ini->getNextToken();
  47. name.set( token );
  48. // get the water setting we want to load based on name
  49. char **timeOfDayName = TimeOfDayNames;
  50. Int timeOfDayIndex = 0; // TIME_OF_DAY_INVALID
  51. while( timeOfDayName && *timeOfDayName )
  52. {
  53. if( stricmp( *timeOfDayName, name.str() ) == 0 )
  54. {
  55. waterSetting = &WaterSettings[ timeOfDayIndex ];
  56. break;
  57. } // end if
  58. // next name
  59. timeOfDayName++;
  60. timeOfDayIndex++;
  61. } // end while
  62. // check for no time of day match
  63. if( waterSetting == NULL )
  64. throw INI_INVALID_DATA;
  65. // parse the data
  66. ini->initFromINI( waterSetting, waterSetting->getFieldParse() );
  67. } // end parseWaterSetting
  68. //-------------------------------------------------------------------------------------------------
  69. void INI::parseWaterTransparencyDefinition( INI *ini )
  70. {
  71. if (TheWaterTransparency == NULL) {
  72. TheWaterTransparency = newInstance(WaterTransparencySetting);
  73. } else if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES) {
  74. WaterTransparencySetting* wt = (WaterTransparencySetting*) (TheWaterTransparency.getNonOverloadedPointer());
  75. WaterTransparencySetting* wtOverride = newInstance(WaterTransparencySetting);
  76. *wtOverride = *wt;
  77. // Mark that it is an override.
  78. wtOverride->markAsOverride();
  79. wt->friend_getFinalOverride()->setNextOverride(wtOverride);
  80. } else {
  81. throw INI_INVALID_DATA;
  82. }
  83. WaterTransparencySetting* waterTrans = (WaterTransparencySetting*) (TheWaterTransparency.getNonOverloadedPointer());
  84. waterTrans = (WaterTransparencySetting*) (waterTrans->friend_getFinalOverride());
  85. // parse the data
  86. ini->initFromINI( waterTrans, TheWaterTransparency->getFieldParse() );
  87. // If we overrode any skybox textures, then call the W3D Water stuff.
  88. if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES) {
  89. // Check to see if we overrode any skybox textures.
  90. // If we did, then we need to replace them in the model.
  91. // Copy/Paste monkeys PLEASE TAKE NOTE. This technique only works for the skybox because we
  92. // know that there will never be more than one sky box. If you were to use this technique for
  93. // technicals, for instance, it would make all technicals in the level have the same new
  94. // texture.
  95. const WaterTransparencySetting* wtOriginal = TheWaterTransparency.getNonOverloadedPointer();
  96. OVERRIDE<WaterTransparencySetting> wtOverride = TheWaterTransparency;
  97. if (wtOriginal == wtOverride)
  98. return;
  99. const AsciiString *oldTextures[5],*newTextures[5];
  100. //Copy current texture names into arrays
  101. oldTextures[0]=&wtOriginal->m_skyboxTextureN;
  102. newTextures[0]=&wtOverride->m_skyboxTextureN;
  103. oldTextures[1]=&wtOriginal->m_skyboxTextureE;
  104. newTextures[1]=&wtOverride->m_skyboxTextureE;
  105. oldTextures[2]=&wtOriginal->m_skyboxTextureS;
  106. newTextures[2]=&wtOverride->m_skyboxTextureS;
  107. oldTextures[3]=&wtOriginal->m_skyboxTextureW;
  108. newTextures[3]=&wtOverride->m_skyboxTextureW;
  109. oldTextures[4]=&wtOriginal->m_skyboxTextureT;
  110. newTextures[4]=&wtOverride->m_skyboxTextureT;
  111. TheTerrainVisual->replaceSkyboxTextures(oldTextures, newTextures);
  112. }
  113. }