Skip to content

Commit

Permalink
Merge pull request #1577 from Xellzul/fixframerate
Browse files Browse the repository at this point in the history
FIX issue-1566 - framerate stuck to 1
  • Loading branch information
Flow86 committed Apr 16, 2023
2 parents e2b0a14 + 92ee6a7 commit dd481ba
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion libs/s25main/GameManager.cpp
Expand Up @@ -52,7 +52,7 @@ bool GameManager::Start()
settings_.video.fullscreen ? settings_.video.fullscreenSize : settings_.video.windowedSize; //-V807
if(!videoDriver_.CreateScreen(screenSize, settings_.video.fullscreen))
return false;
videoDriver_.setTargetFramerate(settings_.video.vsync);
videoDriver_.setTargetFramerate(settings_.video.framerate);
videoDriver_.SetMouseWarping(settings_.global.smartCursor);

/// Audiodriver laden
Expand Down
6 changes: 3 additions & 3 deletions libs/s25main/Settings.cpp
Expand Up @@ -90,7 +90,7 @@ void Settings::LoadDefaults()
video.windowedSize = video.fullscreenSize = VideoMode(800, 600);
video.fullscreen = false;
}
video.vsync = 0;
video.framerate = 0; // Special value for HW vsync
video.vbo = true;
video.shared_textures = true;
// }
Expand Down Expand Up @@ -224,7 +224,7 @@ void Settings::Load()
video.fullscreenSize.width = iniVideo->getIntValue("fullscreen_width");
video.fullscreenSize.height = iniVideo->getIntValue("fullscreen_height");
video.fullscreen = iniVideo->getBoolValue("fullscreen");
video.vsync = iniVideo->getBoolValue("vsync");
video.framerate = iniVideo->getValue("framerate", 0);
video.vbo = iniVideo->getBoolValue("vbo");
video.shared_textures = iniVideo->getBoolValue("shared_textures");
// };
Expand Down Expand Up @@ -402,7 +402,7 @@ void Settings::Save()
iniVideo->setValue("windowed_width", video.windowedSize.width);
iniVideo->setValue("windowed_height", video.windowedSize.height);
iniVideo->setValue("fullscreen", video.fullscreen);
iniVideo->setValue("vsync", video.vsync);
iniVideo->setValue("framerate", video.framerate);
iniVideo->setValue("vbo", video.vbo);
iniVideo->setValue("shared_textures", video.shared_textures);
// };
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/Settings.h
Expand Up @@ -59,7 +59,7 @@ class Settings : public Singleton<Settings, SingletonPolicies::WithLongevity>
struct
{
VideoMode fullscreenSize, windowedSize;
signed short vsync; // <0 for unlimited, 0 for HW Vsync
signed short framerate; // <0 for unlimited, 0 for HW Vsync
bool fullscreen;
bool vbo;
bool shared_textures;
Expand Down
6 changes: 3 additions & 3 deletions libs/s25main/desktops/Desktop.cpp
Expand Up @@ -26,11 +26,11 @@ Desktop::Desktop(glArchivItem_Bitmap* background)
{
SetScale(true);
SetFpsDisplay(true);
// By default limit the maximum frame rate to 60 FPS
if(SETTINGS.video.vsync < 0)
// By default limit the maximum frame rate to 60 FPS - used for main menu
if(SETTINGS.video.framerate < 0)
VIDEODRIVER.setTargetFramerate(60);
else
VIDEODRIVER.setTargetFramerate(SETTINGS.video.vsync);
VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate);
UpdateFps(VIDEODRIVER.GetFPS());
}

Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/desktops/dskGameInterface.cpp
Expand Up @@ -141,7 +141,7 @@ dskGameInterface::dskGameInterface(std::shared_ptr<Game> game, std::shared_ptr<c
if(initOGL)
worldViewer.InitTerrainRenderer();

VIDEODRIVER.setTargetFramerate(SETTINGS.video.vsync); // Use requested setting for ingame
VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate); // Use requested setting for ingame
}

void dskGameInterface::InitPlayer()
Expand Down
24 changes: 12 additions & 12 deletions libs/s25main/desktops/dskOptions.cpp
Expand Up @@ -72,8 +72,8 @@ enum
ID_cbResolution,
ID_txtFullscreen,
ID_grpFullscreen,
ID_txtVSync,
ID_cbVSync,
ID_txtFramerate,
ID_cbFramerate,
ID_txtVBO,
ID_grpVBO,
ID_txtVideoDriver,
Expand Down Expand Up @@ -275,9 +275,9 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
optiongroup->AddTextButton(ID_btOff, DrawPoint(280, 125), Extent(190, 22), TextureColor::Grey, _("Windowed"),
NormalFont);

// "VSync"
groupGrafik->AddText(ID_txtVSync, DrawPoint(80, 180), _("Limit Framerate:"), COLOR_YELLOW, FontStyle{}, NormalFont);
groupGrafik->AddComboBox(ID_cbVSync, DrawPoint(280, 175), Extent(390, 22), TextureColor::Grey, NormalFont, 150);
groupGrafik->AddText(ID_txtFramerate, DrawPoint(80, 180), _("Limit Framerate:"), COLOR_YELLOW, FontStyle{},
NormalFont);
groupGrafik->AddComboBox(ID_cbFramerate, DrawPoint(280, 175), Extent(390, 22), TextureColor::Grey, NormalFont, 150);

// "VBO"
groupGrafik->AddText(ID_txtVBO, DrawPoint(80, 230), _("Vertex Buffer Objects:"), COLOR_YELLOW, FontStyle{},
Expand Down Expand Up @@ -382,7 +382,7 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
groupGrafik->GetCtrl<ctrlOptionGroup>(ID_grpFullscreen)->SetSelection(SETTINGS.video.fullscreen); //-V807

// "Limit Framerate" füllen
auto* cbFrameRate = groupGrafik->GetCtrl<ctrlComboBox>(ID_cbVSync);
auto* cbFrameRate = groupGrafik->GetCtrl<ctrlComboBox>(ID_cbFramerate);
if(VIDEODRIVER.HasVSync())
cbFrameRate->AddString(_("Dynamic (Limits to display refresh rate, works with most drivers)"));
for(int framerate : Settings::SCREEN_REFRESH_RATES)
Expand All @@ -391,7 +391,7 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
cbFrameRate->AddString(_("Disabled"));
else
cbFrameRate->AddString(helpers::toString(framerate) + " FPS");
if(SETTINGS.video.vsync == framerate)
if(SETTINGS.video.framerate == framerate)
cbFrameRate->SetSelection(cbFrameRate->GetNumItems() - 1);
}
if(!cbFrameRate->GetSelection())
Expand Down Expand Up @@ -478,17 +478,17 @@ void dskOptions::Msg_Group_ComboSelectItem(const unsigned group_id, const unsign
->SetEnabled(true);
break;
case ID_cbResolution: SETTINGS.video.fullscreenSize = video_modes[selection]; break;
case ID_cbVSync:
case ID_cbFramerate:
if(VIDEODRIVER.HasVSync())
{
if(selection == 0)
SETTINGS.video.vsync = 0;
SETTINGS.video.framerate = 0;
else
SETTINGS.video.vsync = Settings::SCREEN_REFRESH_RATES[selection - 1];
SETTINGS.video.framerate = Settings::SCREEN_REFRESH_RATES[selection - 1];
} else
SETTINGS.video.vsync = Settings::SCREEN_REFRESH_RATES[selection];
SETTINGS.video.framerate = Settings::SCREEN_REFRESH_RATES[selection];

VIDEODRIVER.setTargetFramerate(SETTINGS.video.vsync);
VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate);
break;
case ID_cbVideoDriver: SETTINGS.driver.video = combo->GetText(selection); break;
case ID_cbAudioDriver: SETTINGS.driver.audio = combo->GetText(selection); break;
Expand Down

0 comments on commit dd481ba

Please sign in to comment.