Add VSync setting.
This commit is contained in:
@@ -73,6 +73,7 @@ namespace OpenRA
|
||||
void DisableDepthBuffer();
|
||||
void ClearDepthBuffer();
|
||||
void SetBlendMode(BlendMode mode);
|
||||
void SetVSyncEnabled(bool enabled);
|
||||
string GLVersion { get; }
|
||||
}
|
||||
|
||||
|
||||
@@ -427,6 +427,11 @@ namespace OpenRA
|
||||
Window.Dispose();
|
||||
}
|
||||
|
||||
public void SetVSyncEnabled(bool enabled)
|
||||
{
|
||||
Window.Context.SetVSyncEnabled(enabled);
|
||||
}
|
||||
|
||||
public string GetClipboardText()
|
||||
{
|
||||
return Window.GetClipboardText();
|
||||
|
||||
@@ -138,6 +138,9 @@ namespace OpenRA
|
||||
[Desc("This can be set to Windowed, Fullscreen or PseudoFullscreen.")]
|
||||
public WindowMode Mode = WindowMode.PseudoFullscreen;
|
||||
|
||||
[Desc("Enable VSync.")]
|
||||
public bool VSync = true;
|
||||
|
||||
[Desc("Screen resolution in fullscreen mode.")]
|
||||
public int2 FullscreenSize = new int2(0, 0);
|
||||
|
||||
|
||||
@@ -205,6 +205,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
BindCheckboxPref(panel, "HARDWARECURSORS_CHECKBOX", ds, "HardwareCursors");
|
||||
BindCheckboxPref(panel, "CURSORDOUBLE_CHECKBOX", ds, "CursorDouble");
|
||||
BindCheckboxPref(panel, "VSYNC_CHECKBOX", ds, "VSync");
|
||||
BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate");
|
||||
BindCheckboxPref(panel, "PLAYER_STANCE_COLORS_CHECKBOX", gs, "UsePlayerStanceColors");
|
||||
|
||||
@@ -232,6 +233,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
battlefieldCameraDropDown.OnMouseDown = _ => ShowBattlefieldCameraDropdown(battlefieldCameraDropDown, ds);
|
||||
battlefieldCameraDropDown.GetText = () => battlefieldCameraLabel.Update(ds.ViewportDistance);
|
||||
|
||||
// Update vsync immediately
|
||||
var vsyncCheckbox = panel.Get<CheckboxWidget>("VSYNC_CHECKBOX");
|
||||
var vsyncOnClick = vsyncCheckbox.OnClick;
|
||||
vsyncCheckbox.OnClick = () =>
|
||||
{
|
||||
vsyncOnClick();
|
||||
Game.Renderer.SetVSyncEnabled(ds.VSync);
|
||||
};
|
||||
|
||||
panel.Get("WINDOW_RESOLUTION").IsVisible = () => ds.Mode == WindowMode.Windowed;
|
||||
var windowWidth = panel.Get<TextFieldWidget>("WINDOW_WIDTH");
|
||||
windowWidth.Text = ds.WindowedSize.X.ToString();
|
||||
|
||||
@@ -231,6 +231,12 @@ namespace OpenRA.Platforms.Default
|
||||
OpenGL.CheckGLError();
|
||||
}
|
||||
|
||||
public void SetVSyncEnabled(bool enabled)
|
||||
{
|
||||
VerifyThreadAffinity();
|
||||
SDL.SDL_GL_SetSwapInterval(enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed)
|
||||
|
||||
@@ -241,6 +241,8 @@ namespace OpenRA.Platforms.Default
|
||||
else
|
||||
context = new ThreadedGraphicsContext(new Sdl2GraphicsContext(this), batchSize);
|
||||
|
||||
context.SetVSyncEnabled(Game.Settings.Graphics.VSync);
|
||||
|
||||
SDL.SDL_SetModState(SDL.SDL_Keymod.KMOD_NONE);
|
||||
input = new Sdl2Input();
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace OpenRA.Platforms.Default
|
||||
Action<object> doDrawPrimitives;
|
||||
Action<object> doEnableScissor;
|
||||
Action<object> doSetBlendMode;
|
||||
Action<object> doSetVSync;
|
||||
|
||||
public ThreadedGraphicsContext(Sdl2GraphicsContext context, int batchSize)
|
||||
{
|
||||
@@ -107,6 +108,7 @@ namespace OpenRA.Platforms.Default
|
||||
context.EnableScissor(t.Item1, t.Item2, t.Item3, t.Item4);
|
||||
};
|
||||
doSetBlendMode = mode => { context.SetBlendMode((BlendMode)mode); };
|
||||
doSetVSync = enabled => { context.SetVSyncEnabled((bool)enabled); };
|
||||
|
||||
Monitor.Pulse(syncObject);
|
||||
}
|
||||
@@ -445,6 +447,11 @@ namespace OpenRA.Platforms.Default
|
||||
{
|
||||
Post(doSetBlendMode, mode);
|
||||
}
|
||||
|
||||
public void SetVSyncEnabled(bool enabled)
|
||||
{
|
||||
Post(doSetVSync, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
class ThreadedFrameBuffer : IFrameBuffer
|
||||
|
||||
@@ -145,29 +145,36 @@ Container@SETTINGS_PANEL:
|
||||
Font: Tiny
|
||||
Align: Center
|
||||
Text: Mode, resolution, and cursor changes will be applied after the game is restarted
|
||||
Checkbox@VSYNC_CHECKBOX:
|
||||
X: 80
|
||||
Y: 125
|
||||
Width: 200
|
||||
Height: 20
|
||||
Font: Regular
|
||||
Text: Enable VSync
|
||||
Checkbox@FRAME_LIMIT_CHECKBOX:
|
||||
X: 15
|
||||
X: 310
|
||||
Y: 125
|
||||
Width: 200
|
||||
Height: 20
|
||||
Font: Regular
|
||||
Text: Enable Frame Limiter
|
||||
Label@FRAME_LIMIT_DESC_A:
|
||||
X: 45
|
||||
X: 340
|
||||
Y: 153
|
||||
Width: 50
|
||||
Height: 25
|
||||
Text: Limit to
|
||||
Align: Right
|
||||
TextField@FRAME_LIMIT_TEXTFIELD:
|
||||
X: 100
|
||||
X: 395
|
||||
Y: 153
|
||||
Width: 45
|
||||
Height: 25
|
||||
MaxLength: 3
|
||||
Type: Integer
|
||||
Label@FRAME_LIMIT_DESC_B:
|
||||
X: 150
|
||||
X: 445
|
||||
Y: 153
|
||||
Height: 25
|
||||
Text: FPS
|
||||
|
||||
@@ -159,29 +159,36 @@ Background@SETTINGS_PANEL:
|
||||
Font: Tiny
|
||||
Align: Center
|
||||
Text: Mode, resolution, and cursor changes will be applied after the game is restarted
|
||||
Checkbox@VSYNC_CHECKBOX:
|
||||
X: 80
|
||||
Y: 125
|
||||
Width: 200
|
||||
Height: 20
|
||||
Font: Regular
|
||||
Text: Enable VSync
|
||||
Checkbox@FRAME_LIMIT_CHECKBOX:
|
||||
X: 15
|
||||
X: 310
|
||||
Y: 125
|
||||
Width: 200
|
||||
Height: 20
|
||||
Font: Regular
|
||||
Text: Enable Frame Limiter
|
||||
Label@FRAME_LIMIT_DESC_A:
|
||||
X: 45
|
||||
X: 340
|
||||
Y: 159
|
||||
Width: 50
|
||||
Height: 25
|
||||
Text: Limit to
|
||||
Align: Right
|
||||
TextField@FRAME_LIMIT_TEXTFIELD:
|
||||
X: 100
|
||||
X: 395
|
||||
Y: 158
|
||||
Width: 45
|
||||
Height: 25
|
||||
MaxLength: 3
|
||||
Type: Integer
|
||||
Label@FRAME_LIMIT_DESC_B:
|
||||
X: 150
|
||||
X: 445
|
||||
Y: 159
|
||||
Height: 25
|
||||
Text: FPS
|
||||
|
||||
Reference in New Issue
Block a user