Made further accuracy improvements to the timing of the dedicated server
TODO: make the dedicated server load all of the settings from serversettings.xml
This commit is contained in:
@@ -3,6 +3,7 @@ using FarseerPhysics.Dynamics;
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@@ -133,24 +134,32 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Timing.Accumulator = 0.0;
|
Timing.Accumulator = 0.0;
|
||||||
|
|
||||||
DateTime prevTime = DateTime.Now;
|
double frequency = (double)Stopwatch.Frequency;
|
||||||
|
if (frequency <= 1500)
|
||||||
|
{
|
||||||
|
DebugConsole.NewMessage("WARNING: Stopwatch frequency under 1500 ticks per second. Expect significant syncing accuracy issues.", Color.Yellow);
|
||||||
|
}
|
||||||
|
|
||||||
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||||
|
long prevTicks = stopwatch.ElapsedTicks;
|
||||||
while (ShouldRun)
|
while (ShouldRun)
|
||||||
{
|
{
|
||||||
Timing.Accumulator += ((float)(DateTime.Now.Subtract(prevTime).Milliseconds) / 1000.0)/Timing.Step;
|
long currTicks = stopwatch.ElapsedTicks;
|
||||||
prevTime = DateTime.Now;
|
Timing.Accumulator += (double)(currTicks - prevTicks) / frequency;
|
||||||
while (Timing.Accumulator>0.0)
|
prevTicks = currTicks;
|
||||||
|
while (Timing.Accumulator>=Timing.Step)
|
||||||
{
|
{
|
||||||
DebugConsole.Update();
|
DebugConsole.Update();
|
||||||
if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
|
if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
|
||||||
Server.Update((float)Timing.Step);
|
Server.Update((float)Timing.Step);
|
||||||
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
||||||
|
|
||||||
Timing.Accumulator -= 1.0;
|
Timing.Accumulator -= Timing.Step;
|
||||||
}
|
}
|
||||||
int frameTime = DateTime.Now.Subtract(prevTime).Milliseconds;
|
int frameTime = (int)(((double)(stopwatch.ElapsedTicks - prevTicks) / frequency)*1000.0);
|
||||||
Thread.Sleep(Math.Max((int)(Timing.Step * 1000.0) - frameTime/2,0));
|
Thread.Sleep(Math.Max(((int)(Timing.Step * 1000.0) - frameTime)/2,0));
|
||||||
}
|
}
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
CloseServer();
|
CloseServer();
|
||||||
|
|
||||||
@@ -168,7 +177,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoroutineHandle ShowLoading(IEnumerable<object> loader, bool waitKeyHit = true)
|
public CoroutineHandle ShowLoadings(IEnumerable<object> loader, bool waitKeyHit = true)
|
||||||
{
|
{
|
||||||
return CoroutineManager.StartCoroutine(loader);
|
return CoroutineManager.StartCoroutine(loader);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
No = 0, Maybe = 1, Yes = 2
|
No = 0, Maybe = 1, Yes = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
partial class GameServer : NetworkMember, ISerializableEntity
|
partial class GameServer : NetworkMember, ISerializableEntity
|
||||||
{
|
{
|
||||||
private class SavedClientPermission
|
private class SavedClientPermission
|
||||||
@@ -48,7 +48,7 @@ namespace Barotrauma.Networking
|
|||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, int> extraCargo;
|
public Dictionary<string, int> extraCargo;
|
||||||
|
|
||||||
public bool ShowNetStats;
|
public bool ShowNetStats;
|
||||||
@@ -57,24 +57,24 @@ namespace Barotrauma.Networking
|
|||||||
private TimeSpan sparseUpdateInterval = new TimeSpan(0, 0, 0, 3);
|
private TimeSpan sparseUpdateInterval = new TimeSpan(0, 0, 0, 3);
|
||||||
|
|
||||||
private SelectionMode subSelectionMode, modeSelectionMode;
|
private SelectionMode subSelectionMode, modeSelectionMode;
|
||||||
|
|
||||||
private bool registeredToMaster;
|
private bool registeredToMaster;
|
||||||
|
|
||||||
private WhiteList whitelist;
|
private WhiteList whitelist;
|
||||||
private BanList banList;
|
private BanList banList;
|
||||||
|
|
||||||
private string password;
|
private string password;
|
||||||
|
|
||||||
public float AutoRestartTimer;
|
public float AutoRestartTimer;
|
||||||
|
|
||||||
private bool autoRestart;
|
private bool autoRestart;
|
||||||
|
|
||||||
private bool isPublic;
|
private bool isPublic;
|
||||||
|
|
||||||
private int maxPlayers;
|
private int maxPlayers;
|
||||||
|
|
||||||
private List<SavedClientPermission> clientPermissions = new List<SavedClientPermission>();
|
private List<SavedClientPermission> clientPermissions = new List<SavedClientPermission>();
|
||||||
|
|
||||||
[Serialize(true, true)]
|
[Serialize(true, true)]
|
||||||
public bool RandomizeSeed
|
public bool RandomizeSeed
|
||||||
{
|
{
|
||||||
@@ -170,7 +170,7 @@ namespace Barotrauma.Networking
|
|||||||
AutoRestartTimer = autoRestart ? AutoRestartInterval : 0.0f;
|
AutoRestartTimer = autoRestart ? AutoRestartInterval : 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serialize(true, true)]
|
[Serialize(true, true)]
|
||||||
public bool AllowRespawn
|
public bool AllowRespawn
|
||||||
{
|
{
|
||||||
@@ -193,7 +193,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
get { return modeSelectionMode; }
|
get { return modeSelectionMode; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public BanList BanList
|
public BanList BanList
|
||||||
{
|
{
|
||||||
get { return banList; }
|
get { return banList; }
|
||||||
@@ -234,7 +234,7 @@ namespace Barotrauma.Networking
|
|||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serialize(false,true)]
|
[Serialize(false, true)]
|
||||||
public bool KarmaEnabled
|
public bool KarmaEnabled
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -246,7 +246,7 @@ namespace Barotrauma.Networking
|
|||||||
XDocument doc = new XDocument(new XElement("serversettings"));
|
XDocument doc = new XDocument(new XElement("serversettings"));
|
||||||
|
|
||||||
SerializableProperty.SerializeProperties(this, doc.Root, true);
|
SerializableProperty.SerializeProperties(this, doc.Root, true);
|
||||||
|
|
||||||
doc.Root.SetAttributeValue("name", name);
|
doc.Root.SetAttributeValue("name", name);
|
||||||
doc.Root.SetAttributeValue("public", isPublic);
|
doc.Root.SetAttributeValue("public", isPublic);
|
||||||
doc.Root.SetAttributeValue("port", config.Port);
|
doc.Root.SetAttributeValue("port", config.Port);
|
||||||
@@ -257,7 +257,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
doc.Root.SetAttributeValue("SubSelection", subSelectionMode.ToString());
|
doc.Root.SetAttributeValue("SubSelection", subSelectionMode.ToString());
|
||||||
doc.Root.SetAttributeValue("ModeSelection", modeSelectionMode.ToString());
|
doc.Root.SetAttributeValue("ModeSelection", modeSelectionMode.ToString());
|
||||||
|
|
||||||
doc.Root.SetAttributeValue("TraitorsEnabled", TraitorsEnabled.ToString());
|
doc.Root.SetAttributeValue("TraitorsEnabled", TraitorsEnabled.ToString());
|
||||||
|
|
||||||
#if SERVER
|
#if SERVER
|
||||||
@@ -272,7 +272,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
doc.Root.SetAttributeValue("ServerMessage", GameMain.NetLobbyScreen.ServerMessageText);
|
doc.Root.SetAttributeValue("ServerMessage", GameMain.NetLobbyScreen.ServerMessageText);
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlWriterSettings settings = new XmlWriterSettings();
|
XmlWriterSettings settings = new XmlWriterSettings();
|
||||||
settings.Indent = true;
|
settings.Indent = true;
|
||||||
settings.NewLineOnAttributes = true;
|
settings.NewLineOnAttributes = true;
|
||||||
@@ -289,7 +289,7 @@ namespace Barotrauma.Networking
|
|||||||
if (File.Exists(SettingsFile))
|
if (File.Exists(SettingsFile))
|
||||||
{
|
{
|
||||||
doc = XMLExtensions.TryLoadXml(SettingsFile);
|
doc = XMLExtensions.TryLoadXml(SettingsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc == null || doc.Root == null)
|
if (doc == null || doc.Root == null)
|
||||||
{
|
{
|
||||||
@@ -318,13 +318,16 @@ namespace Barotrauma.Networking
|
|||||||
Enum.TryParse<YesNoMaybe>(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled);
|
Enum.TryParse<YesNoMaybe>(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled);
|
||||||
TraitorsEnabled = traitorsEnabled;
|
TraitorsEnabled = traitorsEnabled;
|
||||||
GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);
|
GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);
|
||||||
|
|
||||||
if (GameMain.NetLobbyScreen != null
|
if (GameMain.NetLobbyScreen != null
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
&& GameMain.NetLobbyScreen.ServerMessage != null
|
&& GameMain.NetLobbyScreen.ServerMessage != null
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
#if SERVER
|
||||||
|
GameMain.NetLobbyScreen.ServerName = doc.Root.GetAttributeString("name", "");
|
||||||
|
#endif
|
||||||
GameMain.NetLobbyScreen.ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");
|
GameMain.NetLobbyScreen.ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user