From 076dd9a56abcb7180e39c7bb23631b31db7a7fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Hamil?= Date: Sun, 22 Jun 2025 00:39:02 +0300 Subject: [PATCH] Overlays: fix delta calculation --- src/Ryujinx.Graphics.Gpu/Window.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Ryujinx.Graphics.Gpu/Window.cs b/src/Ryujinx.Graphics.Gpu/Window.cs index c5186c77b..7c023d5a8 100644 --- a/src/Ryujinx.Graphics.Gpu/Window.cs +++ b/src/Ryujinx.Graphics.Gpu/Window.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Gpu { private readonly GpuContext _context; private readonly OverlayManager _overlayManager; - private DateTime _lastUpdateTime = DateTime.UtcNow; + private DateTime? _lastUpdateTime = null; /// /// Texture presented on the window. @@ -271,13 +271,16 @@ namespace Ryujinx.Graphics.Gpu { try { - // Calculate delta time for lifespan updates DateTime currentTime = DateTime.UtcNow; - float deltaTime = (float)(currentTime - _lastUpdateTime).TotalSeconds; - _lastUpdateTime = currentTime; + if (_lastUpdateTime != null) + { + // Calculate delta time for lifespan updates + float deltaTime = (float)(currentTime - _lastUpdateTime.Value).TotalSeconds; + _overlayManager.Update(deltaTime, new SKSize(texture.Info.Width, texture.Info.Height)); + } // Update overlay animations - _overlayManager.Update(deltaTime, new SKSize(texture.Info.Width, texture.Info.Height)); + _lastUpdateTime = currentTime; // Get texture data from host texture using var pinnedData = texture.HostTexture.GetData(); @@ -301,7 +304,7 @@ namespace Ryujinx.Graphics.Gpu // Create SKBitmap from texture data var imageInfo = new SKImageInfo(width, height, colorType, SKAlphaType.Premul); using var bitmap = new SKBitmap(imageInfo); - + // Copy texture data to bitmap unsafe { @@ -313,7 +316,7 @@ namespace Ryujinx.Graphics.Gpu // Create canvas for drawing overlays using var canvas = new SKCanvas(bitmap); - + // On Linux with OpenGL, we need to flip the Y-axis because OpenGL uses bottom-left origin // while SkiaSharp uses top-left origin if (OperatingSystem.IsLinux()) @@ -321,7 +324,7 @@ namespace Ryujinx.Graphics.Gpu canvas.Scale(1, -1); canvas.Translate(0, -height); } - + // Render all overlays _overlayManager.Render(canvas);