Added timestep accumulator to dedicated server, improved autorestart commands, added client permission commands

This commit is contained in:
juanjp600
2017-12-01 14:25:10 -03:00
parent d021fe593e
commit 84ba36aa78
9 changed files with 425 additions and 376 deletions
+14 -8
View File
@@ -63,12 +63,12 @@ namespace Barotrauma
FarseerPhysics.Settings.VelocityIterations = 1;
FarseerPhysics.Settings.PositionIterations = 1;
Config = new GameSettings("serverconfig.xml");
Config = new GameSettings("config.xml");
if (Config.WasGameUpdated)
{
UpdaterUtil.CleanOldFiles();
Config.WasGameUpdated = false;
Config.Save("serverconfig.xml");
Config.Save("config.xml");
}
GameScreen = new GameScreen();
@@ -131,19 +131,25 @@ namespace Barotrauma
Init();
StartServer();
Timing.Accumulator = 0.0;
DateTime prevTime = DateTime.Now;
while (ShouldRun)
{
Timing.Accumulator += ((float)(DateTime.Now.Subtract(prevTime).Milliseconds) / 1000.0)/Timing.Step;
prevTime = DateTime.Now;
while (Timing.Accumulator>0.0)
{
DebugConsole.Update();
if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
Server.Update((float)Timing.Step);
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
DebugConsole.Update();
if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
Server.Update((float)Timing.Step);
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
Timing.Accumulator -= 1.0;
}
int frameTime = DateTime.Now.Subtract(prevTime).Milliseconds;
Thread.Sleep(Math.Max((int)(Timing.Step * 1000.0) - frameTime,0));
Thread.Sleep(Math.Max((int)(Timing.Step * 1000.0) - frameTime/2,0));
}
CloseServer();
@@ -1,40 +0,0 @@
using System.Xml.Linq;
namespace Barotrauma
{
public enum WindowMode
{
Windowed, Fullscreen, BorderlessWindowed
}
public partial class GameSettings
{
public void Save(string filePath)
{
XDocument doc = new XDocument();
if (doc.Root == null)
{
doc.Add(new XElement("config"));
}
doc.Root.Add(
new XAttribute("masterserverurl", MasterServerUrl),
new XAttribute("autocheckupdates", AutoCheckUpdates),
new XAttribute("verboselogging", VerboseLogging));
if (WasGameUpdated)
{
doc.Root.Add(new XAttribute("wasgameupdated", true));
}
if (SelectedContentPackage != null)
{
doc.Root.Add(new XElement("contentpackage",
new XAttribute("path", SelectedContentPackage.Path)));
}
doc.Save(filePath);
}
}
}