From 23fb01f9dd1b89179b493d5bee2f97d923342030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 28 Jul 2024 14:36:53 +0200 Subject: [PATCH 1/2] Smoother menu checker background scrolling on loading screens Update global time also while rendering loading screens and shift the menu checker background based on the global time so it's smoother while loading. --- src/engine/client/client.cpp | 1 + src/game/client/components/menus.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 7950763c7..87df1a291 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3820,6 +3820,7 @@ void CClient::UpdateAndSwap() Input()->Update(); Graphics()->Swap(); Graphics()->Clear(0, 0, 0); + m_GlobalTime = (time_get() - m_GlobalStartTime) / (float)time_freq(); } void CClient::ServerBrowserUpdate() diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 031ebc9c7..a4d290335 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -2231,7 +2231,7 @@ void CMenus::RenderBackground() Graphics()->QuadsBegin(); Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.045f); const float Size = 15.0f; - const float OffsetTime = std::fmod(LocalTime() * 0.15f, 2.0f); + const float OffsetTime = std::fmod(Client()->GlobalTime() * 0.15f, 2.0f); IGraphics::CQuadItem aCheckerItems[64]; size_t NumCheckerItems = 0; for(int y = -2; y < (int)(ScreenWidth / Size); y++) From 5bd0b06c52451c71c0fb97955da719d94c3fb6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 28 Jul 2024 20:35:55 +0200 Subject: [PATCH 2/2] Fix menu checker background on wide resolutions and optimize it The maximum width and height were swapped as the loop bounds, so the menu checker background did not have the correct width on very wide resolutions. This was not noticed on common resolutions because twice as many quads as necessary were also being rendered for each row of the background. The bounds of the inner loop are adjusted and only every second x-value is iterated, which reduced the total number of quads for the checker background rendering by more than half. --- src/game/client/components/menus.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index a4d290335..456169a90 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -2234,11 +2234,13 @@ void CMenus::RenderBackground() const float OffsetTime = std::fmod(Client()->GlobalTime() * 0.15f, 2.0f); IGraphics::CQuadItem aCheckerItems[64]; size_t NumCheckerItems = 0; - for(int y = -2; y < (int)(ScreenWidth / Size); y++) + const int NumItemsWidth = std::ceil(ScreenWidth / Size); + const int NumItemsHeight = std::ceil(ScreenHeight / Size); + for(int y = -2; y < NumItemsHeight; y++) { - for(int x = -2; x < (int)(ScreenHeight / Size); x++) + for(int x = 0; x < NumItemsWidth + 4; x += 2) { - aCheckerItems[NumCheckerItems] = IGraphics::CQuadItem((x - OffsetTime) * Size * 2 + (y & 1) * Size, (y + OffsetTime) * Size, Size, Size); + aCheckerItems[NumCheckerItems] = IGraphics::CQuadItem((x - 2 * OffsetTime + (y & 1)) * Size, (y + OffsetTime) * Size, Size, Size); NumCheckerItems++; if(NumCheckerItems == std::size(aCheckerItems)) {