Snow.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. // Snow.cpp ////////////////////////////////////////////////////////////////////////////////
  24. // Snow Rendering implementation
  25. // Author: Mark Wilczynski, July 2003
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the Game
  28. #include "GameClient/Snow.h"
  29. #include "GameClient/view.h"
  30. #ifdef _INTERNAL
  31. // for occasional debugging...
  32. //#pragma optimize("", off)
  33. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  34. #endif
  35. SnowManager *TheSnowManager=NULL;
  36. SnowManager::SnowManager()
  37. {
  38. m_time = 0;
  39. m_velocity = 1;
  40. m_isVisible = TRUE; //default to showing if it's enabled via INI.
  41. }
  42. void SnowManager::init( void )
  43. {
  44. //starting heights of each particle
  45. //TODO: replace this lookup table with some kind of procedural method that takes x,y as input.
  46. m_startingHeights=NEW Real [ SNOW_NOISE_X * SNOW_NOISE_Y];
  47. m_time = 0;
  48. updateIniSettings();
  49. }
  50. void SnowManager::updateIniSettings(void)
  51. {
  52. Real *dst=m_startingHeights;
  53. //initialize a table of random starting positions for each particle.
  54. Int boxDimensions = (Int)TheWeatherSetting->m_snowBoxDimensions;
  55. for (Int y=0; y<SNOW_NOISE_Y; y++)
  56. {
  57. for (Int x=0; x<SNOW_NOISE_X; x++)
  58. {
  59. *dst=(Real)(rand()%(boxDimensions));
  60. dst++;
  61. }
  62. }
  63. m_velocity = TheWeatherSetting->m_snowVelocity;
  64. m_frequencyScaleX = TheWeatherSetting->m_snowFrequencyScaleX;
  65. m_frequencyScaleY = TheWeatherSetting->m_snowFrequencyScaleY;
  66. m_amplitude = TheWeatherSetting->m_snowAmplitude;
  67. m_pointSize = TheWeatherSetting->m_snowPointSize;
  68. m_quadSize = TheWeatherSetting->m_snowQuadSize;
  69. m_boxDimensions = TheWeatherSetting->m_snowBoxDimensions;
  70. m_emitterSpacing = 1.0f/TheWeatherSetting->m_snowBoxDensity;
  71. m_maxPointSize = TheWeatherSetting->m_snowMaxPointSize;
  72. m_minPointSize = TheWeatherSetting->m_snowMinPointSize;
  73. //Time for snow flake to make it from top to bottom of rendered cube around camera.
  74. m_fullTimePeriod = m_boxDimensions/m_velocity;
  75. }
  76. void SnowManager::setVisible(Bool showWeather)
  77. {
  78. m_isVisible = showWeather;
  79. }
  80. void SnowManager::reset(void)
  81. {
  82. m_isVisible = TRUE; //default to showing if it's enabled via INI.
  83. }
  84. SnowManager::~SnowManager()
  85. {
  86. delete [] m_startingHeights;
  87. m_startingHeights=NULL;
  88. }
  89. OVERRIDE<WeatherSetting> TheWeatherSetting = NULL;
  90. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  91. const FieldParse WeatherSetting::m_weatherSettingFieldParseTable[] =
  92. {
  93. { "SnowTexture", INI::parseAsciiString,NULL, offsetof( WeatherSetting, m_snowTexture ) },
  94. { "SnowFrequencyScaleX", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowFrequencyScaleX ) },
  95. { "SnowFrequencyScaleY", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowFrequencyScaleY ) },
  96. { "SnowAmplitude", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowAmplitude ) },
  97. { "SnowPointSize", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowPointSize ) },
  98. { "SnowMaxPointSize", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowMaxPointSize ) },
  99. { "SnowMinPointSize", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowMinPointSize ) },
  100. { "SnowQuadSize", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowQuadSize ) },
  101. { "SnowBoxDimensions", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowBoxDimensions ) },
  102. { "SnowBoxDensity", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowBoxDensity ) },
  103. { "SnowVelocity", INI::parseReal,NULL, offsetof( WeatherSetting, m_snowVelocity ) },
  104. { "SnowPointSprites", INI::parseBool,NULL, offsetof( WeatherSetting, m_usePointSprites ) },
  105. { "SnowEnabled", INI::parseBool,NULL, offsetof( WeatherSetting, m_snowEnabled ) },
  106. { 0, 0, 0, 0 },
  107. };
  108. //-------------------------------------------------------------------------------------------------
  109. void INI::parseWeatherDefinition( INI *ini )
  110. {
  111. if (TheWeatherSetting == NULL) {
  112. TheWeatherSetting = newInstance(WeatherSetting);
  113. } else if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES) {
  114. WeatherSetting* ws = (WeatherSetting*) (TheWeatherSetting.getNonOverloadedPointer());
  115. WeatherSetting* wsOverride = newInstance(WeatherSetting);
  116. *wsOverride = *ws;
  117. // Mark that it is an override.
  118. wsOverride->markAsOverride();
  119. ws->friend_getFinalOverride()->setNextOverride(wsOverride);
  120. } else {
  121. throw INI_INVALID_DATA;
  122. }
  123. WeatherSetting* weatherSet = (WeatherSetting*) (TheWeatherSetting.getNonOverloadedPointer());
  124. weatherSet = (WeatherSetting*) (weatherSet->friend_getFinalOverride());
  125. // parse the data
  126. ini->initFromINI( weatherSet, TheWeatherSetting->getFieldParse() );
  127. if (TheSnowManager)
  128. TheSnowManager->updateIniSettings();
  129. if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES) {
  130. // Check to see if we overrode any textures.
  131. // If we did, then we need to replace them in the model.
  132. }
  133. }