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