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

Function LoadAndApplyDisplayConfig

apps/cwr/Game/GameApplication.cpp:307–351  ·  view source on GitHub ↗

Eager-write defaults if the file is missing, then apply the cfg values to the live graphics engine. Normalize-but-don't-persist so a temporarily disconnected monitor keeps its remembered name.

Source from the content-addressed store, hash-verified

305 request.windowMode = GetCliWindowModeOverride(cli);
306 if (cli.IsWidthExplicit())
307 request.resolutionWidth = cli.GetWindowWidth();
308 if (cli.IsHeightExplicit())
309 request.resolutionHeight = cli.GetWindowHeight();
310 return BuildDisplayStartupOverrides(request);
311}
312
313// Eager-write defaults if the file is missing, then apply the cfg
314// values to the live graphics engine. Normalize-but-don't-persist
315// so a temporarily disconnected monitor keeps its remembered name.
316void LoadAndApplyDisplayConfig()
317{
318 if (!GEngine)
319 return;
320
321 const std::string path = DisplayConfigPath();
322 DisplayConfig cfg;
323 if (!cfg.Load(path))
324 {
325 cfg.LoadDefaults();
326 cfg.Save(path);
327 LOG_INFO(Graphics, "LoadDisplayConfig: created defaults at '{}'", path);
328 }
329
330 LiveDisplayEnv env(GEngine);
331 if (cfg.Normalize(env))
332 LOG_INFO(Graphics, "LoadDisplayConfig: normalized invalid fields (not persisted)");
333
334 DisplayStartupOverrides overrides = GetCliDisplayOverrides(AppConfig::Instance());
335 if (ApplyDisplayStartupOverrides(cfg, overrides))
336 LOG_INFO(Graphics, "LoadDisplayConfig: applied explicit CLI display overrides");
337
338 // Apply order matters: monitor first (window may move),
339 // window mode next, resolution + refresh rate last.
340 if (cfg.monitor != GEngine->GetCurrentMonitor())
341 GEngine->SwitchMonitor(cfg.monitor);
342
343 // Honour the --window CLI override — when the user/test runner
344 // explicitly asked for Windowed, applying the cfg's Borderless or
345 // Fullscreen via SetWindowMode would route through
346 // SDL_SetWindowFullscreen(true), which fires WINDOW_ENTER_FULLSCREEN
347 // and flips the engine's _windowed back to false. Tests that boot
348 // with --window then assert IsWindowed() would race-fail.
349 const auto effectiveWindowMode =
350 ENGINE_CONFIG.useWindow ? DisplayConfig::Windowed : static_cast<DisplayConfig::WindowMode>(cfg.windowMode);
351 GEngine->SetWindowMode(static_cast<WindowMode>(effectiveWindowMode));
352 if (cfg.resolutionWidth > 0 && cfg.resolutionHeight > 0)
353 GEngine->SwitchRes(cfg.resolutionWidth, cfg.resolutionHeight, /*bpp*/ 32);
354 if (cfg.refreshRate > 0 && effectiveWindowMode == DisplayConfig::Fullscreen)

Callers 1

Calls 13

DisplayConfigPathFunction · 0.85
GetCliDisplayOverridesFunction · 0.85
ApplyAspectPolicyFunction · 0.85
LoadMethod · 0.45
LoadDefaultsMethod · 0.45
SaveMethod · 0.45
NormalizeMethod · 0.45
GetCurrentMonitorMethod · 0.45
SwitchMonitorMethod · 0.45
SetWindowModeMethod · 0.45
SwitchResMethod · 0.45

Tested by

no test coverage detected