mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-17 21:51:20 +02:00
Provide a default refresh rate when it cannot be queried
This commit is contained in:
@@ -146,14 +146,14 @@ void blit(pixel *vid)
|
|||||||
|
|
||||||
void UpdateRefreshRate()
|
void UpdateRefreshRate()
|
||||||
{
|
{
|
||||||
std::optional<int> refreshRate;
|
RefreshRate refreshRate;
|
||||||
int displayIndex = SDL_GetWindowDisplayIndex(sdl_window);
|
int displayIndex = SDL_GetWindowDisplayIndex(sdl_window);
|
||||||
if (displayIndex >= 0)
|
if (displayIndex >= 0)
|
||||||
{
|
{
|
||||||
SDL_DisplayMode displayMode;
|
SDL_DisplayMode displayMode;
|
||||||
if (!SDL_GetCurrentDisplayMode(displayIndex, &displayMode) && displayMode.refresh_rate)
|
if (!SDL_GetCurrentDisplayMode(displayIndex, &displayMode) && displayMode.refresh_rate)
|
||||||
{
|
{
|
||||||
refreshRate = displayMode.refresh_rate;
|
refreshRate = RefreshRateQueried{ displayMode.refresh_rate };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui::Engine::Ref().SetRefreshRate(refreshRate);
|
ui::Engine::Ref().SetRefreshRate(refreshRate);
|
||||||
|
@@ -2618,13 +2618,13 @@ void GameView::OnDraw()
|
|||||||
fpsInfo << "hindered";
|
fpsInfo << "hindered";
|
||||||
}
|
}
|
||||||
fpsInfo << "\n Refresh rate: ";
|
fpsInfo << "\n Refresh rate: ";
|
||||||
if (auto refreshRate = ui::Engine::Ref().GetRefreshRate())
|
auto refreshRate = ui::Engine::Ref().GetRefreshRate();
|
||||||
|
fpsInfo << std::visit([](auto &refreshRate) {
|
||||||
|
return refreshRate.value;
|
||||||
|
}, refreshRate);
|
||||||
|
if (std::holds_alternative<RefreshRateDefault>(refreshRate))
|
||||||
{
|
{
|
||||||
fpsInfo << *refreshRate;
|
fpsInfo << " (default)";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fpsInfo << "unknown";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -370,7 +370,9 @@ std::optional<int> Engine::GetEffectiveDrawCap() const
|
|||||||
}
|
}
|
||||||
if (std::get_if<DrawLimitDisplay>(&drawLimit))
|
if (std::get_if<DrawLimitDisplay>(&drawLimit))
|
||||||
{
|
{
|
||||||
effectiveDrawCap = GetRefreshRate();
|
effectiveDrawCap = std::visit([](auto &&refreshRate) {
|
||||||
|
return refreshRate.value;
|
||||||
|
}, GetRefreshRate());
|
||||||
}
|
}
|
||||||
return effectiveDrawCap;
|
return effectiveDrawCap;
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
#include <variant>
|
||||||
#include "common/String.h"
|
#include "common/String.h"
|
||||||
#include "common/ExplicitSingleton.h"
|
#include "common/ExplicitSingleton.h"
|
||||||
#include "graphics/Pixel.h"
|
#include "graphics/Pixel.h"
|
||||||
@@ -10,6 +11,16 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include "FpsLimit.h"
|
#include "FpsLimit.h"
|
||||||
|
|
||||||
|
struct RefreshRateDefault
|
||||||
|
{
|
||||||
|
int value = 60;
|
||||||
|
};
|
||||||
|
struct RefreshRateQueried
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
using RefreshRate = std::variant<RefreshRateDefault, RefreshRateQueried>;
|
||||||
|
|
||||||
class Graphics;
|
class Graphics;
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
@@ -96,7 +107,7 @@ namespace ui
|
|||||||
Window* state_;
|
Window* state_;
|
||||||
Point windowTargetPosition;
|
Point windowTargetPosition;
|
||||||
bool ignoreEvents = false;
|
bool ignoreEvents = false;
|
||||||
std::optional<int> refreshRate;
|
RefreshRate refreshRate;
|
||||||
|
|
||||||
// saved appearances of windows that are in the backround and
|
// saved appearances of windows that are in the backround and
|
||||||
// thus are not currently being redrawn
|
// thus are not currently being redrawn
|
||||||
@@ -140,12 +151,12 @@ namespace ui
|
|||||||
bool GetResizable () const { return windowFrameOps.resizable; }
|
bool GetResizable () const { return windowFrameOps.resizable; }
|
||||||
bool GetBlurryScaling () const { return windowFrameOps.blurryScaling; }
|
bool GetBlurryScaling () const { return windowFrameOps.blurryScaling; }
|
||||||
|
|
||||||
std::optional<int> GetRefreshRate() const
|
RefreshRate GetRefreshRate() const
|
||||||
{
|
{
|
||||||
return refreshRate;
|
return refreshRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetRefreshRate(std::optional<int> newRefreshRate)
|
void SetRefreshRate(RefreshRate newRefreshRate)
|
||||||
{
|
{
|
||||||
refreshRate = newRefreshRate;
|
refreshRate = newRefreshRate;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user