summaryrefslogtreecommitdiff
path: root/hotfix-02_perf-disable-vsync-by-default-4414.patch
blob: 4220a06f7b9cdfea7b5672aab2ba597359fe8e24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
From 404ca35f036358419353107cfbbfcf7c95f89ba8 Mon Sep 17 00:00:00 2001
From: scarf <greenscarf005@gmail.com>
Date: Mon, 1 Apr 2024 00:50:26 +0900
Subject: [PATCH] perf: disable vsync by default (#4414)

* perf: disable vsync by default

* fix: warn vsync performance
---
 src/options.cpp  | 7 +++++++
 src/sdltiles.cpp | 8 ++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/options.cpp b/src/options.cpp
index 85832403dc0..684e8cbd48e 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -2090,6 +2090,13 @@ void options_manager::add_options_graphics()
          false, COPT_CURSES_HIDE
        );
 
+#if defined(SDL_HINT_RENDER_VSYNC)
+    add( "VSYNC", graphics, translate_marker( "Use VSync" ),
+         translate_marker( "Enable vertical synchronization to prevent screen tearing.  VSync can slow the game down a lot.  Requires restart." ),
+         false, COPT_CURSES_HIDE
+       );
+#endif
+
 #if defined(__ANDROID__)
     get_option( "FRAMEBUFFER_ACCEL" ).setPrerequisite( "SOFTWARE_RENDERING" );
 #else
diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp
index 226513ad2ff..561d2e767da 100644
--- a/src/sdltiles.cpp
+++ b/src/sdltiles.cpp
@@ -350,8 +350,12 @@ static void WinCreate()
     if( !software_renderer ) {
         dbg( DL::Info ) << "Attempting to initialize accelerated SDL renderer.";
 
-        renderer.reset( SDL_CreateRenderer( ::window.get(), renderer_id, SDL_RENDERER_ACCELERATED |
-                                            SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE ) );
+        int init_flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
+        if( get_option<bool>( "VSYNC" ) ) {
+            init_flags |= SDL_RENDERER_PRESENTVSYNC;
+        }
+
+        renderer.reset( SDL_CreateRenderer( ::window.get(), renderer_id, init_flags ) );
         if( printErrorIf( !renderer,
                           "Failed to initialize accelerated renderer, falling back to software rendering" ) ) {
             software_renderer = true;
-- 
2.43.0