Added option to toggle vsync

For the ultimate PC master race experience.

Also calling water scroll on every frame with deltatime instead of being called at fixed intervals, making it look smoother as framerate increases.
This commit is contained in:
juanjp600
2016-09-18 18:17:15 -03:00
parent 5da2bc9523
commit c97f729fb3
8 changed files with 35 additions and 16 deletions

View File

@@ -101,6 +101,7 @@ namespace Barotrauma
if (Hull.renderer != null)
{
Hull.renderer.ScrollWater(deltaTime);
Hull.renderer.RenderBack(spriteBatch, renderTarget, 0.0f);
}
@@ -134,13 +135,13 @@ namespace Barotrauma
}
public void Update()
/*public void Update()
{
if (Hull.renderer != null)
{
Hull.renderer.ScrollWater();
}
}
}*/
bool drawn;
public IEnumerable<object> DoLoading(IEnumerable<object> loader)

View File

@@ -126,6 +126,7 @@ namespace Barotrauma
graphicsWidth = Config.GraphicsWidth;
graphicsHeight = Config.GraphicsHeight;
Graphics.SynchronizeWithVerticalRetrace = Config.VSyncEnabled;
Graphics.HardwareModeSwitch = Config.WindowMode != WindowMode.BorderlessWindowed;
@@ -310,7 +311,7 @@ namespace Barotrauma
if (titleScreenOpen)
{
TitleScreen.Update();
//TitleScreen.Update();
}
else if (hasLoaded)
{

View File

@@ -46,6 +46,8 @@ namespace Barotrauma
public int GraphicsWidth { get; set; }
public int GraphicsHeight { get; set; }
public bool VSyncEnabled { get; set; }
//public bool FullScreenEnabled { get; set; }
public WindowMode WindowMode
@@ -128,6 +130,7 @@ namespace Barotrauma
XElement graphicsMode = doc.Root.Element("graphicsmode");
GraphicsWidth = ToolBox.GetAttributeInt(graphicsMode, "width", 0);
GraphicsHeight = ToolBox.GetAttributeInt(graphicsMode, "height", 0);
VSyncEnabled = ToolBox.GetAttributeBool(graphicsMode, "vsync", true);
if (GraphicsWidth==0 || GraphicsHeight==0)
{
@@ -255,6 +258,7 @@ namespace Barotrauma
gMode.ReplaceAttributes(
new XAttribute("width", GraphicsWidth),
new XAttribute("height", GraphicsHeight),
new XAttribute("vsync", VSyncEnabled),
new XAttribute("displaymode", windowMode));
}
@@ -362,6 +366,20 @@ namespace Barotrauma
y += 70;
GUITickBox vsyncTickBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Enable vertical sync",Alignment.CenterY | Alignment.Left,settingsFrame);
vsyncTickBox.OnSelected = (GUITickBox box) =>
{
VSyncEnabled = !VSyncEnabled;
GameMain.Graphics.SynchronizeWithVerticalRetrace = VSyncEnabled;
GameMain.Graphics.ApplyChanges();
UnsavedSettings = true;
return true;
};
vsyncTickBox.Selected = VSyncEnabled;
y += 70;
new GUITextBlock(new Rectangle(0, y, 100, 20), "Sound volume:", GUI.Style, settingsFrame);
GUIScrollBar soundScrollBar = new GUIScrollBar(new Rectangle(0, y+20, 150, 20), GUI.Style,0.1f, settingsFrame);
soundScrollBar.BarScroll = SoundVolume;

View File

@@ -74,10 +74,10 @@ namespace Barotrauma
spriteBatch.End();
}
public void ScrollWater()
public void ScrollWater(float deltaTime)
{
wavePos.X += 0.0001f;
wavePos.Y += 0.0001f;
wavePos.X += 0.006f*deltaTime;
wavePos.Y += 0.006f*deltaTime;
}
public void Render(GraphicsDevice graphicsDevice, Camera cam, RenderTarget2D texture, Matrix transform)

View File

@@ -83,11 +83,6 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
if (Hull.renderer != null)
{
Hull.renderer.ScrollWater();
}
//the accumulator code is based on this article:
//http://gafferongames.com/game-physics/fix-your-timestep/
Physics.accumulator += deltaTime;
@@ -173,8 +168,12 @@ namespace Barotrauma
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
cam.UpdateTransform(true);
cam.UpdateTransform(true);
if (Hull.renderer != null)
{
Hull.renderer.ScrollWater((float)deltaTime);
}
DrawMap(graphics, spriteBatch);
spriteBatch.Begin();

View File

@@ -490,7 +490,7 @@ namespace Barotrauma
public override void Update(double deltaTime)
{
GameMain.TitleScreen.Update();
//GameMain.TitleScreen.Update();
foreach (GUIButton button in menuButtons)
{

View File

@@ -336,7 +336,7 @@ namespace Barotrauma
public override void Update(double deltaTime)
{
GameMain.TitleScreen.Update();
//GameMain.TitleScreen.Update();
menu.Update((float)deltaTime);

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<config masterserverurl="http://www.undertowgames.com/baromaster" autocheckupdates="true" musicvolume="0.0" soundvolume="0.0" verboselogging="true">
<graphicsmode width="1280" height="720" fullscreen="false" />
<graphicsmode width="1280" height="720" fullscreen="false" vsync="false" />
<contentpackage path="Data/ContentPackages/Vanilla 0.3.xml" />
<keymapping Select="E" Use="0" Aim="1" Up="W" Down="S" Left="A" Right="D" Attack="R" Run="LeftShift" Crouch="LeftControl" Chat="Tab" CrewOrders="C" />
</config>