void UGameEngine::ConditionallyOverrideSettings(int32& ResolutionX, int32& ResolutionY, EWindowMode::Type& WindowMode) { if (FParse::Param(FCommandLine::Get(),TEXT("Windowed")) || FParse::Param(FCommandLine::Get(), TEXT("SimMobile"))) { // -Windowed or -SimMobile WindowMode = EWindowMode::Windowed; } else if (FParse::Param(FCommandLine::Get(),TEXT("FullScreen"))) { // -FullScreen auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.FullScreenMode")); check(CVar); WindowMode = CVar->GetValueOnGameThread() == 0 ? EWindowMode::Fullscreen : EWindowMode::WindowedFullscreen; } //fullscreen is always supported, but don't allow windowed mode on platforms that dont' support it. WindowMode = (!FPlatformProperties::SupportsWindowedMode() && (WindowMode == EWindowMode::Windowed || WindowMode == EWindowMode::WindowedMirror || WindowMode == EWindowMode::WindowedFullscreen)) ? EWindowMode::Fullscreen : WindowMode; FParse::Value(FCommandLine::Get(), TEXT("ResX="), ResolutionX); FParse::Value(FCommandLine::Get(), TEXT("ResY="), ResolutionY); if (!IsRunningDedicatedServer() && ((ResolutionX <= 0) || (ResolutionY <= 0))) { // consume available desktop area FDisplayMetrics DisplayMetrics; FDisplayMetrics::GetDisplayMetrics( DisplayMetrics ); ResolutionX = DisplayMetrics.PrimaryDisplayWidth; ResolutionY = DisplayMetrics.PrimaryDisplayHeight; // If we're in windowed mode, attempt to choose a suitable starting resolution that is smaller than the desktop, with a matching aspect ratio if (WindowMode == EWindowMode::Windowed) { TArray<FIntPoint> WindowedResolutions; GenerateConvenientWindowedResolutions(DisplayMetrics, WindowedResolutions); if (WindowedResolutions.Num() > 0) { // We'll default to the largest one we have ResolutionX = WindowedResolutions[WindowedResolutions.Num() - 1].X; ResolutionY = WindowedResolutions[WindowedResolutions.Num() - 1].Y; // Attempt to find the largest one with the same aspect ratio float DisplayAspect = (float)DisplayMetrics.PrimaryDisplayWidth / (float)DisplayMetrics.PrimaryDisplayHeight; for (int32 i = WindowedResolutions.Num() - 1; i >= 0; --i) { float Aspect = (float)WindowedResolutions[i].X / (float)WindowedResolutions[i].Y; if (FMath::Abs(Aspect - DisplayAspect) < KINDA_SMALL_NUMBER) { ResolutionX = WindowedResolutions[i].X; ResolutionY = WindowedResolutions[i].Y; break; } } } } } // Check the platform to see if we should override the user settings. if (FPlatformProperties::HasFixedResolution()) { // Always use the device's actual resolution that has been setup earlier FDisplayMetrics DisplayMetrics; FDisplayMetrics::GetDisplayMetrics( DisplayMetrics ); // We need to pass the resolution back out to GameUserSettings, or it will just override it again ResolutionX = DisplayMetrics.PrimaryDisplayWorkAreaRect.Right - DisplayMetrics.PrimaryDisplayWorkAreaRect.Left; ResolutionY = DisplayMetrics.PrimaryDisplayWorkAreaRect.Bottom - DisplayMetrics.PrimaryDisplayWorkAreaRect.Top; FSystemResolution::RequestResolutionChange(ResolutionX, ResolutionY, EWindowMode::Fullscreen); } if (FParse::Param(FCommandLine::Get(),TEXT("Portrait"))) { Swap(ResolutionX, ResolutionY); } }
void UGameEngine::ConditionallyOverrideSettings( int32& ResolutionX, int32& ResolutionY, bool& bIsFullscreen ) { if (FParse::Param(FCommandLine::Get(),TEXT("Windowed")) || FParse::Param(FCommandLine::Get(), TEXT("SimMobile"))) { // -Windowed or -SimMobile bIsFullscreen = false; } else if (FParse::Param(FCommandLine::Get(),TEXT("FullScreen"))) { // -FullScreen bIsFullscreen = true; } //fullscreen is always supported, but don't allow windowed mode on platforms that dont' support it. bIsFullscreen = bIsFullscreen ? bIsFullscreen : !FPlatformProperties::SupportsWindowedMode(); FParse::Value(FCommandLine::Get(), TEXT("ResX="), ResolutionX); FParse::Value(FCommandLine::Get(), TEXT("ResY="), ResolutionY); if (!IsRunningDedicatedServer() && ((ResolutionX <= 0) || (ResolutionY <= 0))) { // consume available desktop area FDisplayMetrics DisplayMetrics; FSlateApplication::Get().GetDisplayMetrics( DisplayMetrics ); ResolutionX = DisplayMetrics.PrimaryDisplayWidth; ResolutionY = DisplayMetrics.PrimaryDisplayHeight; // If we're in windowed mode, attempt to choose a suitable starting resolution that is smaller than the desktop, with a matching aspect ratio if (!bIsFullscreen) { TArray<FIntPoint> WindowedResolutions; GenerateConvenientWindowedResolutions(DisplayMetrics, WindowedResolutions); if (WindowedResolutions.Num() > 0) { // We'll default to the largest one we have ResolutionX = WindowedResolutions[WindowedResolutions.Num() - 1].X; ResolutionY = WindowedResolutions[WindowedResolutions.Num() - 1].Y; // Attempt to find the largest one with the same aspect ratio float DisplayAspect = (float)DisplayMetrics.PrimaryDisplayWidth / (float)DisplayMetrics.PrimaryDisplayHeight; for (int32 i = WindowedResolutions.Num() - 1; i >= 0; --i) { float Aspect = (float)WindowedResolutions[i].X / (float)WindowedResolutions[i].Y; if (FMath::Abs(Aspect - DisplayAspect) < KINDA_SMALL_NUMBER) { ResolutionX = WindowedResolutions[i].X; ResolutionY = WindowedResolutions[i].Y; break; } } } } } #if PLATFORM_ANDROID || PLATFORM_IOS { // Always use the device's actual resolution that has been setup earlier FDisplayMetrics DisplayMetrics; FSlateApplication::Get().GetDisplayMetrics( DisplayMetrics ); // We need to pass the resolution back out to GameUserSettings, or it will just override it again ResolutionX = DisplayMetrics.PrimaryDisplayWorkAreaRect.Right - DisplayMetrics.PrimaryDisplayWorkAreaRect.Left; ResolutionY = DisplayMetrics.PrimaryDisplayWorkAreaRect.Bottom - DisplayMetrics.PrimaryDisplayWorkAreaRect.Top; FSystemResolution::RequestResolutionChange(ResolutionX, ResolutionY, true); } #endif if (FParse::Param(FCommandLine::Get(),TEXT("Portrait"))) { Swap(ResolutionX, ResolutionY); } }