GameLOD.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. // FILE: GameLOD.h ///////////////////////////////////////////////////////////
  24. //
  25. // Used to set detail levels of various game systems.
  26. //
  27. // Author: Mark Wilczynski, Sept 2002
  28. //
  29. //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. #pragma once
  32. #ifndef _GAME_LOD_H_
  33. #define _GAME_LOD_H_
  34. enum ParticlePriorityType;
  35. #define MAX_LOD_PRESETS_PER_LEVEL 32 //number of hardware configs preset for each low,medium,high
  36. #define MAX_BENCH_PROFILES 16
  37. //Make sure this enum stays in sync with GameLODNames[]
  38. enum StaticGameLODLevel
  39. {
  40. STATIC_GAME_LOD_UNKNOWN=-1,
  41. STATIC_GAME_LOD_LOW,
  42. STATIC_GAME_LOD_MEDIUM,
  43. STATIC_GAME_LOD_HIGH,
  44. STATIC_GAME_LOD_CUSTOM, //make sure this remains last!
  45. STATIC_GAME_LOD_COUNT
  46. };
  47. enum DynamicGameLODLevel
  48. {
  49. DYNAMIC_GAME_LOD_UNKNOWN=-1,
  50. DYNAMIC_GAME_LOD_LOW,
  51. DYNAMIC_GAME_LOD_MEDIUM,
  52. DYNAMIC_GAME_LOD_HIGH,
  53. DYNAMIC_GAME_LOD_VERY_HIGH,
  54. DYNAMIC_GAME_LOD_COUNT
  55. };
  56. //Make sure this stays in sync with CPUNames[] in gamelod.cpp
  57. enum CpuType
  58. {
  59. XX, //unknown type
  60. P3,
  61. P4,
  62. K7,
  63. };
  64. //Keep this in sync with VideoNames in Gamelod.cpp
  65. enum ChipsetType
  66. { DC_UNKNOWN,
  67. DC_VOODOO2,
  68. DC_VOODOO3,
  69. DC_VOODOO4,
  70. DC_VOODOO5,
  71. DC_TNT,
  72. DC_TNT2,
  73. DC_GEFORCE2,
  74. DC_RADEON,
  75. DC_GENERIC_PIXEL_SHADER_1_1,
  76. DC_GEFORCE3,
  77. DC_GEFORCE4,
  78. DC_GENERIC_PIXEL_SHADER_1_4,
  79. DC_RADEON_8500,
  80. DC_GENERIC_PIXEL_SHADER_2_0,
  81. DC_RADEON_9700,
  82. DC_MAX
  83. };
  84. struct StaticGameLODInfo
  85. {
  86. StaticGameLODInfo();
  87. //Static LOD constants
  88. Int m_minFPS; ///< minimum fps in order to recommend this LOD.
  89. Int m_minProcessorFPS; ///< minimum CPU time (in ms) to recommend this LOD.
  90. Int m_sampleCount2D; ///<How many 2-D (UI) samples should we allow simultaneously (Note: Hardware may support less than the desired number)
  91. Int m_sampleCount3D; ///<How many 3-D (World) samples should we allow simultaneously (Note: Hardware may support less than the desired number)
  92. Int m_streamCount; ///<How many streaming audio things should we allow simultaneously (Note: Hardware may support less than the desired number)
  93. Int m_maxParticleCount; ///<maximum number of particles that can exist
  94. Bool m_useShadowVolumes; ///<use volumetric shadows if available.
  95. Bool m_useShadowDecals; ///<use 2D Decal shadows.
  96. Bool m_useCloudMap; ///<use cloud shadows scrolling over terrain.
  97. Bool m_useLightMap; ///<use noise pattern over terrain to break up tiling.
  98. Bool m_showSoftWaterEdge; ///<feather water edge if supported by hardware.
  99. Int m_maxTankTrackEdges; ///<maximum length of tank track
  100. Int m_maxTankTrackOpaqueEdges; ///<maximum length of tank track before it starts fading.
  101. Int m_maxTankTrackFadeDelay; ///<maximum amount of time a tank track segment remains visible.
  102. Bool m_useBuildupScaffolds; ///<draw scaffold during structure building.
  103. Bool m_useTreeSway; ///<sway trees to simulate wind.
  104. Bool m_useEmissiveNightMaterials; ///<perform second lighting pass on night buildings.
  105. Bool m_useHeatEffects; ///<draw heat distortion effects (i.e Microwave Tank).
  106. Int m_textureReduction; ///<reduce texture resolution by dividing in half n times.
  107. Bool m_useFpsLimit; ///<don't lock fps to 30hz
  108. Bool m_enableDynamicLOD; ///<don't do dynamic lod based on current fps.
  109. Bool m_useTrees; ///<don't include trees on map.
  110. };
  111. struct DynamicGameLODInfo
  112. {
  113. DynamicGameLODInfo();
  114. //Dynamic LOD constants
  115. Int m_minFPS; ///< minimum fps in order to recommend his LOD.
  116. UnsignedInt m_dynamicParticleSkipMask;
  117. UnsignedInt m_dynamicDebrisSkipMask;
  118. Real m_slowDeathScale;
  119. ParticlePriorityType m_minDynamicParticlePriority;
  120. ParticlePriorityType m_minDynamicParticleSkipPriority;
  121. };
  122. struct LODPresetInfo
  123. {
  124. LODPresetInfo() : m_cpuType(XX),m_mhz(1),m_cpuPerfIndex(1.0f),m_videoType(DC_UNKNOWN),m_memory(1) {};
  125. CpuType m_cpuType;
  126. Int m_mhz;
  127. Real m_cpuPerfIndex; //used to select preset for unidentified cpu's
  128. ChipsetType m_videoType;
  129. Int m_memory;
  130. };
  131. struct BenchProfile
  132. {
  133. BenchProfile() : m_cpuType(XX),m_mhz(1),m_intBenchIndex(1.0f),m_floatBenchIndex(1.0f),m_memBenchIndex(1.0f) {};
  134. CpuType m_cpuType;
  135. Int m_mhz;
  136. Real m_intBenchIndex;
  137. Real m_floatBenchIndex;
  138. Real m_memBenchIndex;
  139. };
  140. class GameLODManager
  141. {
  142. public:
  143. GameLODManager(void);
  144. ~GameLODManager();
  145. const char *getStaticGameLODLevelName(StaticGameLODLevel level);
  146. const char *getDynamicGameLODLevelName(DynamicGameLODLevel level);
  147. StaticGameLODLevel findStaticLODLevel(void); ///< calculate the optimal static LOD level for this system.
  148. Bool setStaticLODLevel(StaticGameLODLevel level); ///< set the current static LOD level.
  149. StaticGameLODLevel getStaticLODLevel(void) { return m_currentStaticLOD;}
  150. DynamicGameLODLevel findDynamicLODLevel(Real averageFPS); ///<given an average fps, return the optimal dynamic LOD.
  151. Bool setDynamicLODLevel(DynamicGameLODLevel level); ///< set the current dynamic LOD level.
  152. DynamicGameLODLevel getDynamicLODLevel(void) { return m_currentDynamicLOD;}
  153. void init(void); ///<initialize tables of preset LOD's.
  154. void setCurrentTextureReduction(Int val) {m_currentTextureReduction = val;}
  155. Int getCurrentTextureReduction(void) {return m_currentTextureReduction;}
  156. Int getStaticGameLODIndex(AsciiString name);
  157. Int getDynamicGameLODIndex(AsciiString name);
  158. inline Bool isParticleSkipped(void);
  159. inline Bool isDebrisSkipped(void);
  160. inline Real getSlowDeathScale(void);
  161. inline ParticlePriorityType getMinDynamicParticlePriority(void); ///<priority at which particles will still render at current FPS.
  162. inline ParticlePriorityType getMinDynamicParticleSkipPriority(void); ///<priority at which particles will never be skipped at any FPS.
  163. Int getRecommendedTextureReduction(void); ///<return the optimal texture reduction for the system.
  164. Int getLevelTextureReduction(StaticGameLODLevel level); ///<return texture reduction specified in INI for this game detail.
  165. LODPresetInfo *newLODPreset(StaticGameLODLevel index);
  166. BenchProfile *newBenchProfile(void);
  167. Bool didMemPass( void );
  168. void setReallyLowMHz(Int mhz) { m_reallyLowMHz = mhz; }
  169. Bool isReallyLowMHz() const { return m_cpuFreq < m_reallyLowMHz; }
  170. StaticGameLODInfo m_staticGameLODInfo[STATIC_GAME_LOD_COUNT];
  171. DynamicGameLODInfo m_dynamicGameLODInfo[DYNAMIC_GAME_LOD_COUNT];
  172. LODPresetInfo m_lodPresets[STATIC_GAME_LOD_CUSTOM][MAX_LOD_PRESETS_PER_LEVEL];
  173. BenchProfile m_benchProfiles[MAX_BENCH_PROFILES];
  174. protected:
  175. void applyStaticLODLevel(StaticGameLODLevel level);
  176. void applyDynamicLODLevel(DynamicGameLODLevel level);
  177. void refreshCustomStaticLODLevel(void); ///<grabs current globaldata values and makes them the custom detail setting.
  178. static const FieldParse m_staticGameLODFieldParseTable[];
  179. StaticGameLODLevel m_currentStaticLOD; ///< current value of static LOD.
  180. DynamicGameLODLevel m_currentDynamicLOD; ///< current value of dynamic LOD.
  181. Int m_numParticleGenerations; ///<number of particles that have been generated since dynamic LOD reduction started.
  182. Int m_dynamicParticleSkipMask; ///<mask used to enable rendering of every Nth particle.
  183. Int m_numDebrisGenerations; ///<number of debris that have been generated since dynamic LOD reduction started.
  184. Int m_dynamicDebrisSkipMask; ///<mask used to enable rendering of every Nth debris.
  185. Real m_slowDeathScale; ///<values < 1.0f are used to accelerate deaths
  186. ParticlePriorityType m_minDynamicParticlePriority; ///<only priorities above/including this value are allowed to render.
  187. ParticlePriorityType m_minDynamicParticleSkipPriority; ///<priorities above/including this value never skip particles.
  188. Bool m_videoPassed;
  189. Bool m_cpuPassed;
  190. Bool m_memPassed;
  191. Int m_numLevelPresets[STATIC_GAME_LOD_CUSTOM];
  192. Int m_numBenchProfiles;
  193. StaticGameLODLevel m_idealDetailLevel;
  194. ChipsetType m_videoChipType;
  195. CpuType m_cpuType;
  196. Int m_numRAM;
  197. Int m_cpuFreq;
  198. Real m_intBenchIndex;
  199. Real m_floatBenchIndex;
  200. Real m_memBenchIndex;
  201. Real m_compositeBenchIndex;
  202. Int m_currentTextureReduction;
  203. Int m_reallyLowMHz;
  204. };
  205. Bool GameLODManager::isParticleSkipped(void)
  206. {
  207. return (++m_numParticleGenerations & m_dynamicParticleSkipMask) != m_dynamicParticleSkipMask;
  208. }
  209. Bool GameLODManager::isDebrisSkipped(void)
  210. {
  211. return (++m_numDebrisGenerations & m_dynamicDebrisSkipMask) != m_dynamicDebrisSkipMask;
  212. }
  213. Real GameLODManager::getSlowDeathScale(void)
  214. {
  215. return m_slowDeathScale;
  216. }
  217. ParticlePriorityType GameLODManager::getMinDynamicParticlePriority(void)
  218. {
  219. return m_minDynamicParticlePriority;
  220. }
  221. ParticlePriorityType GameLODManager::getMinDynamicParticleSkipPriority(void)
  222. {
  223. return m_minDynamicParticleSkipPriority;
  224. }
  225. extern GameLODManager *TheGameLODManager;
  226. #endif _GAME_LOD_H_