Add OrderBuffer and time synchronisation.

This commit is contained in:
teinarss
2021-10-10 16:14:26 +02:00
committed by Gustas
parent 4435bdec3c
commit 999af0c05b
2 changed files with 162 additions and 5 deletions

View File

@@ -69,6 +69,8 @@ namespace OpenRA.Server
readonly TypeDictionary serverTraits = new TypeDictionary();
readonly PlayerDatabase playerDatabase;
OrderBuffer orderBuffer;
volatile ServerState internalState = ServerState.WaitingPlayers;
readonly BlockingCollection<IServerEvent> events = new BlockingCollection<IServerEvent>();
@@ -361,6 +363,18 @@ namespace OpenRA.Server
foreach (var t in serverTraits.WithInterface<ITick>())
t.Tick(this);
if (State == ServerState.GameStarted)
{
foreach (var (playerIndex, scale) in orderBuffer.GetTickScales())
{
var frame = CreateTickScaleFrame(scale);
var con = Conns.SingleOrDefault(c => c.PlayerIndex == playerIndex);
if (con != null && con.Validated)
DispatchFrameToClient(con, playerIndex, frame);
}
}
}
if (State == ServerState.ShuttingDown)
@@ -890,6 +904,8 @@ namespace OpenRA.Server
frame += OrderLatency;
DispatchFrameToClient(conn, conn.PlayerIndex, CreateAckFrame(frame, 1));
orderBuffer.AddOrderTimestamp(conn.PlayerIndex);
// Track the last frame for each client so the disconnect handling can write
// an EndOfOrders marker with the correct frame number.
// TODO: This should be handled by the order buffering system too
@@ -1155,6 +1171,7 @@ namespace OpenRA.Server
{
lock (LobbyInfo)
{
orderBuffer?.RemovePlayer(toDrop.PlayerIndex);
Conns.Remove(toDrop);
var dropClient = LobbyInfo.Clients.FirstOrDefault(c => c.Index == toDrop.PlayerIndex);
@@ -1330,12 +1347,16 @@ namespace OpenRA.Server
SyncLobbyInfo();
State = ServerState.GameStarted;
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
var gameSpeedName = LobbyInfo.GlobalSettings.OptionOrDefault("gamespeed", gameSpeeds.DefaultSpeed);
var gameSpeed = gameSpeeds.Speeds[gameSpeedName];
orderBuffer = new OrderBuffer();
orderBuffer.Start(gameSpeed, Conns.Where(c => c.Validated).Select(c => c.PlayerIndex));
if (Type != ServerType.Local)
{
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
var gameSpeedName = LobbyInfo.GlobalSettings.OptionOrDefault("gamespeed", gameSpeeds.DefaultSpeed);
OrderLatency = gameSpeeds.Speeds[gameSpeedName].OrderLatency;
}
OrderLatency = gameSpeed.OrderLatency;
if (GameSave == null && LobbyInfo.GlobalSettings.GameSavesEnabled)
GameSave = new GameSave();