Made the menu and launch screen scale up at the same speed regardless of the display refresh rate

This commit is contained in:
Leon Styhre 2025-02-09 22:19:01 +01:00
parent c1480e847a
commit 762aace575
4 changed files with 41 additions and 16 deletions

View file

@ -45,6 +45,7 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
}
mScaleUp = 0.5f;
mScaleAccumulator = 0;
const float titleFontSize {0.060f};
const float gameNameFontSize {0.073f};
@ -223,16 +224,17 @@ void GuiLaunchScreen::onSizeChanged()
void GuiLaunchScreen::update(int deltaTime)
{
if (Settings::getInstance()->getString("MenuOpeningEffect") == "none")
mScaleUp = 1.0f;
else if (mScaleUp < 1.0f)
mScaleUp = glm::clamp(mScaleUp + 0.07f, 0.0f, 1.0f);
if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up")
mScaleAccumulator += deltaTime;
}
void GuiLaunchScreen::render(const glm::mat4& /*parentTrans*/)
void GuiLaunchScreen::render(const glm::mat4&)
{
// Scale up animation.
setScale(mScaleUp);
if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up" && mScaleUp < 1.0f) {
mScaleUp = glm::clamp(glm::mix(0.5f, 1.0f, static_cast<float>(mScaleAccumulator) / 110.0f),
0.5f, 1.0f);
setScale(mScaleUp);
}
glm::mat4 trans {Renderer::getIdentity() * getTransform()};
mRenderer->setMatrix(trans);

View file

@ -45,6 +45,7 @@ private:
std::string mImagePath;
float mScaleUp;
int mScaleAccumulator;
};
#endif // ES_APP_GUIS_GUI_LAUNCH_SCREEN_H

View file

@ -59,6 +59,7 @@ Window::Window() noexcept
, mInvalidateCacheTimer {0}
, mVideoPlayerCount {0}
, mTopScale {0.5f}
, mScaleAccumulator {0}
, mRenderedHelpPrompts {false}
, mChangedTheme {false}
{
@ -180,9 +181,21 @@ bool Window::init(bool resized)
mProgressBarRectangles.emplace_back(progressBarRect);
mBackgroundOverlay->setResize(mRenderer->getScreenWidth(), mRenderer->getScreenHeight());
mPostprocessedBackground = TextureResource::get("", false, false, false, false, false);
// This doesn't really do anything useful per se, but initializing the texture takes a bit
// longer the first time so doing it here even with null data avoids some potential stutter
// the first time the menu is opened.
const std::vector<unsigned char> processedTexture(
static_cast<size_t>(mRenderer->getScreenWidth()) *
static_cast<size_t>(mRenderer->getScreenHeight()) * 4,
0);
mPostprocessedBackground->initFromPixels(&processedTexture[0],
static_cast<size_t>(mRenderer->getScreenWidth()),
static_cast<size_t>(mRenderer->getScreenHeight()));
mScaleAccumulator = 0;
mListScrollText = std::make_unique<TextComponent>("", Font::get(FONT_SIZE_LARGE));
mGPUStatisticsText = std::make_unique<TextComponent>(
"", Font::get(FONT_SIZE_SMALL), 0xFF00FFFF, ALIGN_LEFT, ALIGN_CENTER, glm::vec2 {1, 1},
@ -294,6 +307,7 @@ void Window::input(InputConfig* config, Input input)
// up. So scale it to full size so it won't be stuck at a smaller size when returning
// from the submenu.
mTopScale = 1.0f;
mScaleAccumulator = 0;
GuiComponent* menu {mGuiStack.back()};
glm::vec2 menuCenter {menu->getCenter()};
menu->setOrigin(0.5f, 0.5f);
@ -363,6 +377,10 @@ void Window::update(int deltaTime)
deltaTime = mAverageDeltaTime;
}
if (mGuiStack.size() > 1 && mTopScale < 1.0f &&
Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up")
mScaleAccumulator += deltaTime;
mFrameTimeElapsed += deltaTime;
++mFrameCountElapsed;
if (mFrameTimeElapsed > 500) {
@ -600,14 +618,17 @@ void Window::render()
mBackgroundOverlay->render(trans);
// Scale-up menu opening effect.
if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up") {
if (mTopScale < 1.0f) {
mTopScale = glm::clamp(mTopScale + 0.07f, 0.0f, 1.0f);
glm::vec2 topCenter {top->getCenter()};
top->setOrigin(0.5f, 0.5f);
top->setPosition(topCenter.x, topCenter.y, 0.0f);
top->setScale(mTopScale);
}
if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up" &&
mTopScale < 1.0f) {
mTopScale =
glm::clamp(glm::mix(0.5f, 1.0f, static_cast<float>(mScaleAccumulator) / 110.0f),
0.5f, 1.0f);
glm::vec2 topCenter {top->getCenter()};
top->setOrigin(0.5f, 0.5f);
top->setPosition(topCenter.x, topCenter.y, 0.0f);
top->setScale(mTopScale);
if (mTopScale == 1.0f)
mScaleAccumulator = 0;
}
if (!mRenderedHelpPrompts) {

View file

@ -250,6 +250,7 @@ private:
std::atomic<int> mVideoPlayerCount;
float mTopScale;
int mScaleAccumulator;
bool mRenderedHelpPrompts;
bool mChangedTheme;
};