GameLOD.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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: 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. Int m_textureReduction; ///<reduce texture resolution by dividing in half n times.
  106. Bool m_useFpsLimit; ///<don't lock fps to 30hz
  107. Bool m_enableDynamicLOD; ///<don't do dynamic lod based on current fps.
  108. Bool m_useTrees; ///<don't include trees on map.
  109. };
  110. struct DynamicGameLODInfo
  111. {
  112. DynamicGameLODInfo();
  113. //Dynamic LOD constants
  114. Int m_minFPS; ///< minimum fps in order to recommend his LOD.
  115. UnsignedInt m_dynamicParticleSkipMask;
  116. UnsignedInt m_dynamicDebrisSkipMask;
  117. Real m_slowDeathScale;
  118. ParticlePriorityType m_minDynamicParticlePriority;
  119. ParticlePriorityType m_minDynamicParticleSkipPriority;
  120. };
  121. struct LODPresetInfo
  122. {
  123. LODPresetInfo() : m_cpuType(XX),m_mhz(1),m_cpuPerfIndex(1.0f),m_videoType(DC_UNKNOWN),m_memory(1) {};
  124. CpuType m_cpuType;
  125. Int m_mhz;
  126. Real m_cpuPerfIndex; //used to select preset for unidentified cpu's
  127. ChipsetType m_videoType;
  128. Int m_memory;
  129. };
  130. struct BenchProfile
  131. {
  132. BenchProfile() : m_cpuType(XX),m_mhz(1),m_intBenchIndex(1.0f),m_floatBenchIndex(1.0f),m_memBenchIndex(1.0f) {};
  133. CpuType m_cpuType;
  134. Int m_mhz;
  135. Real m_intBenchIndex;
  136. Real m_floatBenchIndex;
  137. Real m_memBenchIndex;
  138. };
  139. class GameLODManager
  140. {
  141. public:
  142. GameLODManager(void);
  143. ~GameLODManager();
  144. const char *getStaticGameLODLevelName(StaticGameLODLevel level);
  145. const char *getDynamicGameLODLevelName(DynamicGameLODLevel level);
  146. StaticGameLODLevel findStaticLODLevel(void); ///< calculate the optimal static LOD level for this system.
  147. Bool setStaticLODLevel(StaticGameLODLevel level); ///< set the current static LOD level.
  148. StaticGameLODLevel getStaticLODLevel(void) { return m_currentStaticLOD;}
  149. DynamicGameLODLevel findDynamicLODLevel(Real averageFPS); ///<given an average fps, return the optimal dynamic LOD.
  150. Bool setDynamicLODLevel(DynamicGameLODLevel level); ///< set the current dynamic LOD level.
  151. DynamicGameLODLevel getDynamicLODLevel(void) { return m_currentDynamicLOD;}
  152. void init(void); ///<initialize tables of preset LOD's.
  153. void setCurrentTextureReduction(Int val) {m_currentTextureReduction = val;}
  154. Int getCurrentTextureReduction(void) {return m_currentTextureReduction;}
  155. Int getStaticGameLODIndex(AsciiString name);
  156. Int getDynamicGameLODIndex(AsciiString name);
  157. inline Bool isParticleSkipped(void);
  158. inline Bool isDebrisSkipped(void);
  159. inline Real getSlowDeathScale(void);
  160. inline ParticlePriorityType getMinDynamicParticlePriority(void); ///<priority at which particles will still render at current FPS.
  161. inline ParticlePriorityType getMinDynamicParticleSkipPriority(void); ///<priority at which particles will never be skipped at any FPS.
  162. Int getRecommendedTextureReduction(void); ///<return the optimal texture reduction for the system.
  163. Int getLevelTextureReduction(StaticGameLODLevel level); ///<return texture reduction specified in INI for this game detail.
  164. LODPresetInfo *newLODPreset(StaticGameLODLevel index);
  165. BenchProfile *newBenchProfile(void);
  166. Bool didMemPass( void );
  167. void setReallyLowMHz(Int mhz) { m_reallyLowMHz = mhz; }
  168. Bool isReallyLowMHz() const { return m_cpuFreq < m_reallyLowMHz; }
  169. StaticGameLODInfo m_staticGameLODInfo[STATIC_GAME_LOD_COUNT];
  170. DynamicGameLODInfo m_dynamicGameLODInfo[DYNAMIC_GAME_LOD_COUNT];
  171. LODPresetInfo m_lodPresets[STATIC_GAME_LOD_CUSTOM][MAX_LOD_PRESETS_PER_LEVEL];
  172. BenchProfile m_benchProfiles[MAX_BENCH_PROFILES];
  173. protected:
  174. void applyStaticLODLevel(StaticGameLODLevel level);
  175. void applyDynamicLODLevel(DynamicGameLODLevel level);
  176. void refreshCustomStaticLODLevel(void); ///<grabs current globaldata values and makes them the custom detail setting.
  177. static const FieldParse m_staticGameLODFieldParseTable[];
  178. StaticGameLODLevel m_currentStaticLOD; ///< current value of static LOD.
  179. DynamicGameLODLevel m_currentDynamicLOD; ///< current value of dynamic LOD.
  180. Int m_numParticleGenerations; ///<number of particles that have been generated since dynamic LOD reduction started.
  181. Int m_dynamicParticleSkipMask; ///<mask used to enable rendering of every Nth particle.
  182. Int m_numDebrisGenerations; ///<number of debris that have been generated since dynamic LOD reduction started.
  183. Int m_dynamicDebrisSkipMask; ///<mask used to enable rendering of every Nth debris.
  184. Real m_slowDeathScale; ///<values < 1.0f are used to accelerate deaths
  185. ParticlePriorityType m_minDynamicParticlePriority; ///<only priorities above/including this value are allowed to render.
  186. ParticlePriorityType m_minDynamicParticleSkipPriority; ///<priorities above/including this value never skip particles.
  187. Bool m_videoPassed;
  188. Bool m_cpuPassed;
  189. Bool m_memPassed;
  190. Int m_numLevelPresets[STATIC_GAME_LOD_CUSTOM];
  191. Int m_numBenchProfiles;
  192. StaticGameLODLevel m_idealDetailLevel;
  193. ChipsetType m_videoChipType;
  194. CpuType m_cpuType;
  195. Int m_numRAM;
  196. Int m_cpuFreq;
  197. Real m_intBenchIndex;
  198. Real m_floatBenchIndex;
  199. Real m_memBenchIndex;
  200. Real m_compositeBenchIndex;
  201. Real m_currentTextureReduction;
  202. Int m_reallyLowMHz;
  203. };
  204. Bool GameLODManager::isParticleSkipped(void)
  205. {
  206. return (++m_numParticleGenerations & m_dynamicParticleSkipMask) != m_dynamicParticleSkipMask;
  207. }
  208. Bool GameLODManager::isDebrisSkipped(void)
  209. {
  210. return (++m_numDebrisGenerations & m_dynamicDebrisSkipMask) != m_dynamicDebrisSkipMask;
  211. }
  212. Real GameLODManager::getSlowDeathScale(void)
  213. {
  214. return m_slowDeathScale;
  215. }
  216. ParticlePriorityType GameLODManager::getMinDynamicParticlePriority(void)
  217. {
  218. return m_minDynamicParticlePriority;
  219. }
  220. ParticlePriorityType GameLODManager::getMinDynamicParticleSkipPriority(void)
  221. {
  222. return m_minDynamicParticleSkipPriority;
  223. }
  224. extern GameLODManager *TheGameLODManager;
  225. #endif _GAME_LOD_H_