diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index c90d880f..7ea1ad07 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -4753,6 +4753,11 @@ void Game::loadstats() over30mode = atoi(pText); } + if (pKey == "vsync") + { + graphics.vsync = atoi(pText); + } + if (pKey == "notextoutline") { graphics.notextoutline = atoi(pText); @@ -5002,6 +5007,10 @@ void Game::savestats() msg->LinkEndChild(doc.NewText(help.String((int) over30mode).c_str())); dataNode->LinkEndChild(msg); + msg = doc.NewElement("vsync"); + msg->LinkEndChild(doc.NewText(help.String((int) graphics.vsync).c_str())); + dataNode->LinkEndChild(msg); + for (size_t i = 0; i < controllerButton_flip.size(); i += 1) { msg = doc.NewElement("flipButton"); @@ -7075,9 +7084,10 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) option("toggle analogue"); option("toggle mouse"); option("toggle fps"); + option("toggle vsync"); option("return"); - menuxoff = -50; - menuyoff = 8; + menuxoff = -85; + menuyoff = 0; break; case Menu::ed_settings: option("change description"); diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 42561587..67e21239 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -139,6 +139,8 @@ void Graphics::init() col_tb = 0; kludgeswnlinewidth = false; + + vsync = false; } int Graphics::font_idx(uint32_t ch) { @@ -3100,3 +3102,8 @@ Uint32 Graphics::crewcolourreal(int t) } return col_crewcyan; } + +void Graphics::processVsync() +{ + SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC, vsync ? "1" : "0", SDL_HINT_OVERRIDE); +} diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index 6a291e70..906bffb3 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -324,6 +324,9 @@ public: bool kludgeswnlinewidth; Uint32 crewcolourreal(int t); + + bool vsync; + void processVsync(); }; extern Graphics graphics; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index c82e583b..1b46fc19 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -364,6 +364,13 @@ void menuactionpress() game.over30mode = !game.over30mode; game.savestats(); break; + case 6: + //toggle vsync + music.playef(11); + graphics.vsync = !graphics.vsync; + graphics.processVsync(); + game.savestats(); + break; default: //back music.playef(11); diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 99203359..b6f0369e 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -176,6 +176,18 @@ void menurender() graphics.Print(-1, 95, "Current mode: Over 30 FPS", tr, tg, tb, true); } break; + case 6: + graphics.bigprint(-1, 30, "Toggle VSync", tr, tg, tb, true); + graphics.Print(-1, 65, "Turn VSync on or off.", tr, tg, tb, true); + + if (!graphics.vsync) + { + graphics.Print(-1, 95, "Current mode: VSYNC OFF", tr/2, tg/2, tb/2, true); + } + else + { + graphics.Print(-1, 95, "Current mode: VSYNC ON", tr, tg, tb, true); + } } break; case Menu::credits: diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 5e6ead1b..639de72c 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -105,8 +105,6 @@ int main(int argc, char *argv[]) } } - SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC, "1", SDL_HINT_OVERRIDE); - if(!FILESYSTEM_init(argv[0], baseDir, assetsPath)) { return 1; @@ -208,6 +206,8 @@ int main(int argc, char *argv[]) //Moved screensetting init here from main menu V2.1 game.loadstats(); + graphics.processVsync(); + if (game.skipfakeload) game.gamestate = TITLEMODE; if(game.usingmmmmmm==0) music.usingmmmmmm=false;