backgroundmgr.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. ** Command & Conquer Renegade(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/backgroundmgr.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/15/02 7:26p $*
  29. * *
  30. * $Revision:: 25 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef __BACKGROUNDMGR_H
  36. #define __BACKGROUNDMGR_H
  37. // Includes.
  38. #include "combat.h"
  39. #include "combatchunkid.h"
  40. #include "dx8indexbuffer.h"
  41. #include "networkobject.h"
  42. #include "rendobj.h"
  43. #include "saveloadsubsystem.h"
  44. #include "segline.h"
  45. #include "shader.h"
  46. #include "vector3.h"
  47. #include "vector3i.h"
  48. #include "vertmaterial.h"
  49. #include "wwdebug.h"
  50. // Forward declarations.
  51. class CameraClass;
  52. class DazzleRenderObjClass;
  53. class SimpleSceneClass;
  54. class TextureClass;
  55. class SoundEnvironmentClass;
  56. // Classes.
  57. class VisibilityClass {
  58. public:
  59. VisibilityClass() {Visible = true;}
  60. bool Is_Visible() {return (Visible);}
  61. void Set_Visibility (bool visible) {Visible = visible;}
  62. private :
  63. bool Visible;
  64. };
  65. class HazeClass : public VisibilityClass
  66. {
  67. public:
  68. HazeClass (float radius);
  69. ~HazeClass();
  70. void Configure (const Vector3 &blendcolor, const Vector3 &horizoncolor, float intensity);
  71. void Configure (const Vector3 &blendcolor, const Vector3 &horizoncolor);
  72. void Configure (const Vector3 &blendcolor, float intensity);
  73. void Configure (const Vector3 &blendcolor);
  74. Vector3 Get_Horizon_Color() {return (HorizonColor * Intensity);}
  75. void Render();
  76. protected:
  77. enum {
  78. ROW_COUNT = 3,
  79. VERTICES_PER_TRIANGLE = 3
  80. };
  81. void Configure();
  82. Vector3 BlendColor;
  83. Vector3 HorizonColor;
  84. float Intensity;
  85. unsigned RowCount;
  86. unsigned VertexCount;
  87. Vector3 *VertexArray;
  88. unsigned TriangleCount;
  89. DX8IndexBufferClass *IndexBuffer;
  90. unsigned *DiffuseArray;
  91. VertexMaterialClass *Material;
  92. ShaderClass Shader;
  93. };
  94. class StarfieldClass : public VisibilityClass
  95. {
  96. public:
  97. StarfieldClass (float radius, unsigned starcount);
  98. ~StarfieldClass();
  99. void Configure (const Vector3 &orientation, float length, float radius, const Vector3 &color0, const Vector3 &color1, float alpha);
  100. void Configure (const Vector3 &orientation, float length, float radius);
  101. void Configure (const Vector3 &color0, const Vector3 &color1, float alpha);
  102. void Render();
  103. protected:
  104. void Configure();
  105. enum {
  106. VERTICES_PER_TRIANGLE = 3
  107. };
  108. Vector3 Orientation;
  109. float Length;
  110. float Radius;
  111. Vector3 Color0, Color1;
  112. float Alpha;
  113. unsigned VertexCount;
  114. Vector3 *VertexArray;
  115. unsigned TriangleCount;
  116. DX8IndexBufferClass *IndexBuffer;
  117. VertexMaterialClass *Material;
  118. ShaderClass Shader;
  119. TextureClass *Texture;
  120. unsigned *DiffuseArray;
  121. unsigned ActiveVertexCount;
  122. unsigned ActiveTriangleCount;
  123. };
  124. class SkyObjectClass : public VisibilityClass
  125. {
  126. public:
  127. SkyObjectClass (ShaderClass shader);
  128. ~SkyObjectClass();
  129. void Configure (const Vector3 &direction, float length, float radius, const Vector3 &color);
  130. void Configure (const Vector3 &direction, float length, float width, float height);
  131. void Configure (const Vector3 &direction, float length, float radius);
  132. void Configure (const Vector3 &color);
  133. void Set_Texture (const char *texturename);
  134. Vector3 Get_Color() {return (Color);}
  135. void Render();
  136. protected:
  137. enum {
  138. VERTICES_PER_TRIANGLE = 3
  139. };
  140. void Configure();
  141. Vector3 Direction;
  142. float Length;
  143. float Width;
  144. float Height;
  145. Vector3 Color;
  146. unsigned VertexCount;
  147. Vector3 *VertexArray;
  148. unsigned TriangleCount;
  149. DX8IndexBufferClass *IndexBuffer;
  150. VertexMaterialClass *Material;
  151. ShaderClass Shader;
  152. TextureClass *Texture;
  153. Vector2 *TexCoordArray;
  154. unsigned *DiffuseArray;
  155. };
  156. class CloudLayerClass : public VisibilityClass
  157. {
  158. public:
  159. CloudLayerClass (float maxdistance, const char *texturename, const Vector2 &velocity, float tilefactor, bool rotate);
  160. ~CloudLayerClass();
  161. void Configure (const Vector3 &warmcolor, const Vector3 &coldcolor);
  162. void Configure (const Vector3 &warmdirection);
  163. void Configure (const Vector3 &warmcolor, const Vector3 &coldcolor, const Vector3 &warmdirection);
  164. void Configure (float alpha, float cloudintensity, float horizonintensity);
  165. void Render();
  166. protected:
  167. enum {
  168. VERTICES_PER_TRIANGLE = 3
  169. };
  170. void Configure();
  171. Vector3 WarmColor;
  172. Vector3 ColdColor;
  173. Vector3 WarmDirection;
  174. float Alpha;
  175. float CloudIntensity;
  176. float HorizonIntensity;
  177. unsigned RowCount;
  178. unsigned VertexCount;
  179. Vector3 *VertexArray;
  180. unsigned TriangleCount;
  181. DX8IndexBufferClass *IndexBuffer;
  182. VertexMaterialClass *Material;
  183. ShaderClass Shader;
  184. TextureClass *Texture;
  185. Vector2 *TexCoordArray;
  186. Vector2 Velocity;
  187. unsigned *DiffuseArray;
  188. };
  189. class SkyGlowClass : public VisibilityClass
  190. {
  191. public:
  192. SkyGlowClass (float radius);
  193. ~SkyGlowClass();
  194. void Configure (const Vector2 &hotdirection, const Vector3 &horizoncolor, float coldintensity);
  195. void Render();
  196. protected:
  197. enum {
  198. ROW_COUNT = 5,
  199. VERTICES_PER_TRIANGLE = 3
  200. };
  201. void Configure();
  202. Vector2 HotDirection;
  203. Vector3 HorizonColor;
  204. float ColdIntensity;
  205. unsigned RowCount;
  206. float Radius;
  207. float MinZ, MaxZ;
  208. unsigned VertexCount;
  209. Vector3 *VertexArray;
  210. unsigned TriangleCount;
  211. DX8IndexBufferClass *IndexBuffer;
  212. unsigned *DiffuseArray;
  213. VertexMaterialClass *Material;
  214. ShaderClass Shader;
  215. };
  216. class LightningBoltClass : public VisibilityClass, public SegmentedLineClass
  217. {
  218. public:
  219. LightningBoltClass::LightningBoltClass (int branchcount, Matrix3D &m, float length, float childlength, float width, float amplitude);
  220. ~LightningBoltClass ();
  221. void Configure (Vector3 &color);
  222. virtual void Set_Transform (Matrix3D &t);
  223. virtual void Render (RenderInfoClass &rinfo);
  224. void Set_Visibility (bool visible, bool recurse);
  225. private:
  226. struct BranchStruct {
  227. LightningBoltClass *LightningBolt;
  228. };
  229. BranchStruct *Branches;
  230. int BranchCount;
  231. };
  232. class LightningClass
  233. {
  234. public:
  235. LightningClass (float extent, float startdistance, float enddistance, float heading, float distribution);
  236. ~LightningClass();
  237. bool Update (Matrix3D &t, Vector3 &additivecolor, SoundEnvironmentClass *soundenvironment);
  238. void Render (RenderInfoClass &rinfo);
  239. private:
  240. SkyGlowClass *LightningGlow;
  241. LightningBoltClass *LightningBolt;
  242. SkyObjectClass *LightningSource;
  243. Vector2 Direction;
  244. float Distance;
  245. unsigned Time;
  246. unsigned ThunderDelayTime;
  247. Vector3 ThunderPosition;
  248. const char *ThunderSampleName;
  249. bool PlayedThunder;
  250. };
  251. class WarBlitzClass
  252. {
  253. public:
  254. WarBlitzClass (float extent, float startdistance, float enddistance, float heading, float distribution);
  255. ~WarBlitzClass();
  256. bool Update (Matrix3D &t, Vector3 &additivecolor);
  257. void Render (RenderInfoClass &rinfo);
  258. private:
  259. SkyGlowClass *WarBlitzGlow;
  260. Vector2 Direction;
  261. float Distance;
  262. unsigned Time;
  263. unsigned SampleDelayTime;
  264. Vector3 SamplePosition;
  265. bool PlayedSample;
  266. };
  267. class SkyClass : public RenderObjClass
  268. {
  269. public:
  270. enum MoonTypeEnum {
  271. MOON_TYPE_FULL,
  272. MOON_TYPE_PART,
  273. MOON_TYPE_COUNT
  274. };
  275. SkyClass (SoundEnvironmentClass *soundenvironment);
  276. ~SkyClass();
  277. RenderObjClass *Clone() const
  278. {
  279. WWASSERT (false);
  280. return (0);
  281. }
  282. void Set_Color();
  283. Vector3 Get_Color() {return (Color);}
  284. SkyObjectClass *Get_Sun() {return (Sun);}
  285. void Set_Light_Direction (const Vector3 &sundirection, const Vector3 &moondirection);
  286. void Set_Time_Of_Day (unsigned hours, unsigned minutes);
  287. void Set_Moon_Type (MoonTypeEnum moontype);
  288. void Set_Clouds (float cloudcover, float gloominess);
  289. void Set_Tint_Factor (float tintfactor);
  290. void Set_Lightning (float intensity, float startdistance, float enddistance, float heading, float distribution)
  291. {
  292. LightningIntensity = intensity;
  293. LightningStartDistance = startdistance;
  294. LightningEndDistance = enddistance;
  295. LightningHeading = DEG_TO_RADF (heading);
  296. LightningDistribution = distribution;
  297. }
  298. void Set_War_Blitz (float intensity, float startdistance, float enddistance, float heading, float distribution)
  299. {
  300. WarBlitzIntensity = intensity;
  301. WarBlitzStartDistance = startdistance;
  302. WarBlitzEndDistance = enddistance;
  303. WarBlitzHeading = DEG_TO_RADF (heading);
  304. WarBlitzDistribution = distribution;
  305. }
  306. void Update (SceneClass *mainscene, const Vector3 &cameraposition);
  307. void Render (RenderInfoClass &rinfo);
  308. void Get_Obj_Space_Bounding_Sphere (SphereClass &sphere) const;
  309. void Get_Obj_Space_Bounding_Box (AABoxClass &box) const;
  310. protected:
  311. enum {
  312. LIGHTNING_COUNT = 2
  313. };
  314. Vector3 Interpolate_Color (const unsigned char colortable [][3], unsigned colorcount, float interpolant);
  315. float Interpolate_Scalar (const unsigned char scalartable [], unsigned scalarcount, float interpolant);
  316. unsigned Lightning_Delay();
  317. unsigned War_Blitz_Delay();
  318. float Extent; // Radius of sphere (and half cube width) which contains all sky objects (for clipping purposes).
  319. Vector3 Color;
  320. unsigned Hours, Minutes;
  321. float Gloominess;
  322. float TintFactor;
  323. HazeClass *Haze;
  324. StarfieldClass *Starfield;
  325. SkyObjectClass *Sun;
  326. SkyObjectClass *SunHalo;
  327. SkyObjectClass *Moon;
  328. SkyObjectClass *MoonHalo;
  329. CloudLayerClass *CloudLayer0;
  330. CloudLayerClass *CloudLayer1;
  331. LightningClass *Lightning [LIGHTNING_COUNT];
  332. int LightningCountdown [LIGHTNING_COUNT];
  333. float LightningIntensity;
  334. float LightningStartDistance;
  335. float LightningEndDistance;
  336. float LightningHeading;
  337. float LightningDistribution;
  338. SoundEnvironmentClass *SoundEnvironment;
  339. WarBlitzClass *WarBlitz;
  340. int WarBlitzCountdown;
  341. float WarBlitzIntensity;
  342. float WarBlitzStartDistance;
  343. float WarBlitzEndDistance;
  344. float WarBlitzHeading;
  345. float WarBlitzDistribution;
  346. };
  347. class BackgroundParameterClass
  348. {
  349. public:
  350. void Initialize();
  351. void Set (float targetvalue, float ramptime, bool override);
  352. void Set (float overrideramptime) {OverrideDuration = overrideramptime;}
  353. float Value() {return (CurrentValue);}
  354. bool Update (float time, bool override);
  355. void Update (float &value, float &target, float &duration, float time);
  356. private:
  357. float CurrentValue;
  358. float NormalValue;
  359. float NormalTarget;
  360. float NormalDuration;
  361. float OverrideTarget;
  362. float OverrideDuration;
  363. friend class BackgroundMgrClass;
  364. };
  365. class BackgroundMgrClass : public SaveLoadSubSystemClass, public NetworkObjectClass
  366. {
  367. public:
  368. enum LightSourceTypeEnum {
  369. LIGHT_SOURCE_TYPE_SUN,
  370. LIGHT_SOURCE_TYPE_MOON
  371. };
  372. BackgroundMgrClass();
  373. ~BackgroundMgrClass() {}
  374. uint32 Chunk_ID() const {return (CHUNKID_BACKGROUND_MGR);}
  375. const char *Name() const {return ("BackgroundMgrClass");}
  376. void Delete (void) {}
  377. virtual void Set_Delete_Pending (void) {};
  378. bool Save (ChunkSaveClass &csave);
  379. bool Load (ChunkLoadClass &cload);
  380. bool Load_Micro_Chunks (ChunkLoadClass &cload);
  381. void Export_Rare (BitStreamClass &packet);
  382. void Import_Rare (BitStreamClass &packet);
  383. static void Init (SimpleSceneClass *renderscene, SoundEnvironmentClass *soundenvironment, bool render_available = true);
  384. static void Reset();
  385. static void Shutdown();
  386. static bool Save_Dynamic (ChunkSaveClass &csave);
  387. static bool Load_Dynamic (ChunkLoadClass &cload);
  388. static bool Load_Dynamic_Micro_Chunks (ChunkLoadClass &cload);
  389. static Vector3 Get_Clear_Color()
  390. {
  391. if (_Sky != NULL) {
  392. return (_Sky->Get_Color());
  393. } else {
  394. return (Vector3 (0.0f, 0.0f, 0.0f));
  395. }
  396. }
  397. static bool Set_Time_Of_Day (unsigned hours, unsigned minutes)
  398. {
  399. if ((hours >= 0) && (hours <= 23) && (minutes >= 0) && (minutes <= 59)) {
  400. _Hours = hours;
  401. _Minutes = minutes;
  402. Set_Dirty();
  403. return (true);
  404. } else {
  405. return (false);
  406. }
  407. }
  408. static void Get_Time_Of_Day (unsigned &hours, unsigned &minutes)
  409. {
  410. hours = _Hours;
  411. minutes = _Minutes;
  412. }
  413. static void Set_Light_Source_Type (LightSourceTypeEnum lightsourcetype)
  414. {
  415. _LightSourceType = lightsourcetype;
  416. Set_Dirty();
  417. }
  418. static LightSourceTypeEnum Get_Light_Source_Type() {return (_LightSourceType);}
  419. static void Set_Moon_Type (SkyClass::MoonTypeEnum moontype)
  420. {
  421. _MoonType = moontype;
  422. Set_Dirty();
  423. }
  424. static SkyClass::MoonTypeEnum Get_Moon_Type()
  425. {
  426. return (_MoonType);
  427. }
  428. static bool Set_Clouds (float cloudcover, float cloudgloominess, float ramptime = 0.0f);
  429. static bool Override_Clouds (float cloudcover, float cloudgloominess, float ramptime = 0.0f);
  430. static void Get_Clouds (float &cloudcover, float &gloominess);
  431. static void Restore_Clouds (float ramptime);
  432. static bool Set_Sky_Tint (float skytintfactor, float ramptime = 0.0f);
  433. static bool Override_Sky_Tint (float skytintfactor, float ramptime = 0.0f);
  434. static void Restore_Sky_Tint (float ramptime);
  435. static bool Set_Lightning_Intensity (float intensity, float ramptime = 0.0f);
  436. static bool Set_Lightning (float intensity, float startdistance, float enddistance, float heading, float distribution, float ramptime = 0.0f);
  437. static bool Override_Lightning (float intensity, float startdistance, float enddistance, float heading, float distribution, float ramptime = 0.0f);
  438. static void Get_Lightning (float &intensity, float &startdistance, float &enddistance, float &heading, float &distribution);
  439. static void Restore_Lightning (float ramptime);
  440. static bool Set_War_Blitz (float intensity, float ramptime = 0.0f);
  441. static bool Set_War_Blitz (float intensity, float startdistance, float enddistance, float heading, float distribution, float ramptime = 0.0f, bool override = false);
  442. static void Get_War_Blitz (float &intensity, float &startdistance, float &enddistance, float &heading, float &distribution);
  443. static void Update (PhysicsSceneClass *mainscene, CameraClass *camera);
  444. private:
  445. #define VARID_PARAMETER(varname) \
  446. VARID_ ## varname ## _CURRENT_VALUE, \
  447. VARID_ ## varname ## _NORMAL_VALUE, \
  448. VARID_ ## varname ## _NORMAL_TARGET, \
  449. VARID_ ## varname ## _NORMAL_DURATION, \
  450. VARID_ ## varname ## _OVERRIDE_TARGET, \
  451. VARID_ ## varname ## _OVERRIDE_DURATION
  452. // Constants.
  453. enum
  454. {
  455. CHUNKID_MICRO_CHUNKS = 0x11080732,
  456. CHUNKID_DYNAMIC_MICRO_CHUNKS = 0x11020216
  457. };
  458. enum {
  459. VARID_TIME_HOURS = 0x14,
  460. VARID_TIME_MINUTES,
  461. VARID_LIGHT_SOURCE_TYPE,
  462. VARID_MOON_TYPE,
  463. VARID_PARAMETER (CLOUD_COVER),
  464. VARID_PARAMETER (CLOUD_GLOOMINESS),
  465. VARID_PARAMETER (SKY_TINT_FACTOR),
  466. VARID_PARAMETER (LIGHTNING_INTENSITY),
  467. VARID_PARAMETER (LIGHTNING_START_DISTANCE),
  468. VARID_PARAMETER (LIGHTNING_END_DISTANCE),
  469. VARID_PARAMETER (LIGHTNING_HEADING),
  470. VARID_PARAMETER (LIGHTNING_DISTRIBUTION),
  471. VARID_CLOUD_OVERRIDE_COUNT,
  472. VARID_LIGHTNING_OVERRIDE_COUNT,
  473. VARID_PARAMETER (WAR_BLITZ_INTENSITY),
  474. VARID_PARAMETER (WAR_BLITZ_START_DISTANCE),
  475. VARID_PARAMETER (WAR_BLITZ_END_DISTANCE),
  476. VARID_PARAMETER (WAR_BLITZ_HEADING),
  477. VARID_PARAMETER (WAR_BLITZ_DISTRIBUTION),
  478. VARID_SKY_TINT_OVERRIDE_COUNT
  479. };
  480. #undef VARID_PARAMETER
  481. enum {
  482. PARAMETER_CLOUD_COVER,
  483. PARAMETER_CLOUD_GLOOMINESS,
  484. PARAMETER_SKY_TINT_FACTOR,
  485. PARAMETER_LIGHTNING_INTENSITY,
  486. PARAMETER_LIGHTNING_START_DISTANCE,
  487. PARAMETER_LIGHTNING_END_DISTANCE,
  488. PARAMETER_LIGHTNING_HEADING,
  489. PARAMETER_LIGHTNING_DISTRIBUTION,
  490. PARAMETER_WAR_BLITZ_INTENSITY,
  491. PARAMETER_WAR_BLITZ_START_DISTANCE,
  492. PARAMETER_WAR_BLITZ_END_DISTANCE,
  493. PARAMETER_WAR_BLITZ_HEADING,
  494. PARAMETER_WAR_BLITZ_DISTRIBUTION,
  495. PARAMETER_COUNT
  496. };
  497. static bool Set_Clouds (float cloudcover, float cloudgloominess, float ramptime, bool override);
  498. static bool Set_Sky_Tint (float skytintfactor, float ramptime, bool override);
  499. static bool Set_Lightning_Intensity (float intensity, float ramptime, bool override);
  500. static bool Set_Lightning (float intensity, float startdistance, float enddistance, float heading, float distribution, float ramptime, bool override);
  501. static bool Is_Dirty() {return (_Dirty);}
  502. static void Set_Dirty (bool dirty = true) {_Dirty = dirty;}
  503. static unsigned _Hours;
  504. static unsigned _Minutes;
  505. static LightSourceTypeEnum _LightSourceType;
  506. static SkyClass::MoonTypeEnum _MoonType;
  507. static BackgroundParameterClass _Parameters [PARAMETER_COUNT];
  508. static Vector3 _LightVector;
  509. static Vector3 _UnitLightVector;
  510. static unsigned _CloudOverrideCount;
  511. static unsigned _LightningOverrideCount;
  512. static unsigned _SkyTintOverrideCount;
  513. static bool _Dirty;
  514. static bool _FogEnabled;
  515. static SkyClass *_Sky;
  516. static DazzleRenderObjClass *_Dazzle;
  517. };
  518. // Externals.
  519. extern BackgroundMgrClass _TheBackgroundMgr;
  520. #endif // BACKGROUNDMGR_H