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.
| 365 | int GetSystemRamMB() const override { return SDL_GetSystemRAM(); } |
| 366 | }; |
| 367 | |
| 368 | std::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. |
| 376 | void 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; |
no test coverage detected