فهرست منبع

Added a 'refreshrate' field to the table returned by love.window.getMode. The value may be 0 if the refresh rate of the monitor can't be determined. It might also be 59 instead of 60 on 59.94hz monitors on some operating systems.

Alex Szpakowski 11 سال پیش
والد
کامیت
e1f7e4abd3
4فایلهای تغییر یافته به همراه16 افزوده شده و 4 حذف شده
  1. 2 0
      src/modules/window/Window.cpp
  2. 2 0
      src/modules/window/Window.h
  3. 6 0
      src/modules/window/sdl/Window.cpp
  4. 6 4
      src/modules/window/wrap_Window.cpp

+ 2 - 0
src/modules/window/Window.cpp

@@ -51,6 +51,7 @@ WindowSettings::WindowSettings()
 	, display(0)
 	, highdpi(false)
 	, sRGB(false)
+	, refreshrate(0.0)
 {
 }
 
@@ -99,6 +100,7 @@ StringMap<Window::Setting, Window::SETTING_MAX_ENUM>::Entry Window::settingEntri
 	{"display", SETTING_DISPLAY},
 	{"highdpi", SETTING_HIGHDPI},
 	{"srgb", SETTING_SRGB},
+	{"refreshrate", SETTING_REFRESHRATE},
 };
 
 StringMap<Window::Setting, Window::SETTING_MAX_ENUM> Window::settings(Window::settingEntries, sizeof(Window::settingEntries));

+ 2 - 0
src/modules/window/Window.h

@@ -59,6 +59,7 @@ public:
 		SETTING_DISPLAY,
 		SETTING_HIGHDPI,
 		SETTING_SRGB,
+		SETTING_REFRESHRATE,
 		SETTING_MAX_ENUM
 	};
 
@@ -198,6 +199,7 @@ struct WindowSettings
 	int display; // = 0
 	bool highdpi; // false
 	bool sRGB; // false
+	double refreshrate; // 0.0
 
 }; // WindowSettings
 

+ 6 - 0
src/modules/window/sdl/Window.cpp

@@ -390,6 +390,12 @@ void Window::updateSettings(const WindowSettings &newsettings)
 		SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
 
 	curMode.settings.sRGB = newsettings.sRGB;
+
+	SDL_DisplayMode dmode = {};
+	SDL_GetCurrentDisplayMode(curMode.settings.display, &dmode);
+
+	// May be 0 if the refresh rate can't be determined.
+	curMode.settings.refreshrate = (double) dmode.refresh_rate;
 }
 
 void Window::getWindow(int &width, int &height, WindowSettings &settings)

+ 6 - 4
src/modules/window/wrap_Window.cpp

@@ -105,17 +105,16 @@ int w_setMode(lua_State *L)
 	settings.minheight = luax_intflag(L, 3, settingName(Window::SETTING_MIN_HEIGHT), 1);
 	settings.borderless = luax_boolflag(L, 3, settingName(Window::SETTING_BORDERLESS), false);
 	settings.centered = luax_boolflag(L, 3, settingName(Window::SETTING_CENTERED), true);
-	settings.display = luax_intflag(L, 3, settingName(Window::SETTING_DISPLAY), 1);
+	settings.display = luax_intflag(L, 3, settingName(Window::SETTING_DISPLAY), 1) - 1;
 	settings.highdpi = luax_boolflag(L, 3, settingName(Window::SETTING_HIGHDPI), false);
 	settings.sRGB = luax_boolflag(L, 3, settingName(Window::SETTING_SRGB), false);
 
+	// We don't explicitly set the refresh rate, it's "read-only".
+
 	// For backward-compatibility. TODO: remove!
 	int fsaa = luax_intflag(L, 3, settingName(Window::SETTING_FSAA), 0);
 	if (fsaa > settings.msaa) settings.msaa = fsaa;
 
-	// Display index is 1-based in Lua and 0-based internally.
-	settings.display--;
-
 	luax_catchexcept(L,
 		[&](){ luax_pushboolean(L, instance()->setWindow(w, h, &settings)); }
 	);
@@ -176,6 +175,9 @@ int w_getMode(lua_State *L)
 	luax_pushboolean(L, settings.sRGB);
 	lua_setfield(L, -2, settingName(Window::SETTING_SRGB));
 
+	lua_pushnumber(L, settings.refreshrate);
+	lua_setfield(L, -2, settingName(Window::SETTING_REFRESHRATE));
+
 	return 3;
 }