MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / LoadAndApplyGraphicsConfig

Function LoadAndApplyGraphicsConfig

apps/cwr/Game/GameApplication.cpp:367–397  ·  view source on GitHub ↗

Eager-write defaults (autodetected) if the file is missing, then apply the cfg values to the live engine. Normalize-but-don't- persist mirrors AudioConfig + DisplayConfig.

Source from the content-addressed store, hash-verified

365 int GetSystemRamMB() const override { return SDL_GetSystemRAM(); }
366};
367
368std::string GraphicsConfigPath()
369{
370 return GamePaths::Instance().UserDir() + "graphics.cfg";
371}
372
373// Eager-write defaults (autodetected) if the file is missing, then
374// apply the cfg values to the live engine. Normalize-but-don't-
375// persist mirrors AudioConfig + DisplayConfig.
376void LoadAndApplyGraphicsConfig()
377{
378 const std::string path = GraphicsConfigPath();
379 const int refreshHz = GEngine ? GEngine->RefreshRate() : 0;
380 GraphicsConfig cfg;
381 if (!cfg.Load(path))
382 {
383 // First boot autodetects from hardware. vsync / brightness / gamma
384 // keep their class-default values.
385 cfg.LoadDefaults();
386 const int ramMB = SDL_GetSystemRAM();
387 cfg.qualityPreset = GraphicsConfig::PickPresetFromRam(ramMB);
388 cfg.ApplyPresetToTiers(cfg.qualityPreset);
389 cfg.fpsCap = GraphicsConfig::FpsCapForRefreshRate(refreshHz);
390 cfg.Save(path);
391 LOG_INFO(Graphics,
392 "LoadGraphicsConfig: autodetected preset={} (RAM={} MB) fpsCap={} (display {} Hz), wrote '{}'",
393 (int)cfg.qualityPreset, ramMB, cfg.fpsCap, refreshHz, path);
394 }
395
396 if (cfg.Migrate(refreshHz) && cfg.Save(path))
397 LOG_INFO(Graphics, "LoadGraphicsConfig: migrated '{}' to version {} (fpsCap={}, display {} Hz)", path,
398 GraphicsConfig::kVersion, cfg.fpsCap, refreshHz);
399
400 LiveGraphicsEnv env;

Callers 1

Calls 7

GraphicsConfigPathFunction · 0.85
ApplyPresetToTiersMethod · 0.80
LoadMethod · 0.45
LoadDefaultsMethod · 0.45
SaveMethod · 0.45
NormalizeMethod · 0.45

Tested by

no test coverage detected