netplay readying cleanup

This commit is contained in:
Chris Forbes
2010-01-16 18:47:28 +13:00
parent e01f684878
commit e920ee8c92
5 changed files with 30 additions and 17 deletions

View File

@@ -16,7 +16,6 @@ namespace OpenRA.Server
public int Frame = 0; public int Frame = 0;
/* client data */ /* client data */
public bool IsReady;
public int PlayerIndex; public int PlayerIndex;
public byte[] PopBytes(int n) public byte[] PopBytes(int n)
@@ -25,6 +24,11 @@ namespace OpenRA.Server
data.RemoveRange(0, n); data.RemoveRange(0, n);
return result.ToArray(); return result.ToArray();
} }
/* file server state */
public int NextChunk = 0;
public int NumChunks = 0;
public Stream Stream = null;
} }
enum ReceiveState { Header, Data }; enum ReceiveState { Header, Data };

View File

@@ -16,6 +16,7 @@ namespace OpenRA.Server
static Dictionary<int, List<Connection>> inFlightFrames static Dictionary<int, List<Connection>> inFlightFrames
= new Dictionary<int, List<Connection>>(); = new Dictionary<int, List<Connection>>();
static Session lobbyInfo = new Session(); static Session lobbyInfo = new Session();
static bool GameStarted = false;
public static void Main(string[] args) public static void Main(string[] args)
{ {
@@ -223,7 +224,7 @@ namespace OpenRA.Server
{ "race", { "race",
s => s =>
{ {
if (conn.IsReady) if (GameStarted)
{ {
DispatchOrdersToClient(conn, 0, DispatchOrdersToClient(conn, 0,
new ServerOrder( conn.PlayerIndex, "Chat", new ServerOrder( conn.PlayerIndex, "Chat",
@@ -245,7 +246,7 @@ namespace OpenRA.Server
{ "pal", { "pal",
s => s =>
{ {
if (conn.IsReady) if (GameStarted)
{ {
DispatchOrdersToClient(conn, 0, DispatchOrdersToClient(conn, 0,
new ServerOrder( conn.PlayerIndex, "Chat", new ServerOrder( conn.PlayerIndex, "Chat",
@@ -275,7 +276,7 @@ namespace OpenRA.Server
return true; return true;
} }
if (conn.IsReady) if (GameStarted)
{ {
DispatchOrdersToClient(conn, 0, DispatchOrdersToClient(conn, 0,
new ServerOrder( conn.PlayerIndex, "Chat", new ServerOrder( conn.PlayerIndex, "Chat",
@@ -309,15 +310,22 @@ namespace OpenRA.Server
switch (so.Name) switch (so.Name)
{ {
case "ToggleReady": case "ToggleReady":
conn.IsReady ^= true; // if we're downloading, we can't ready up.
var client = lobbyInfo.Clients[conn.PlayerIndex];
if (client.State == Session.ClientState.NotReady)
client.State = Session.ClientState.Ready;
else if (client.State == Session.ClientState.Ready)
client.State = Session.ClientState.NotReady;
Console.WriteLine("Player @{0} is {1}", Console.WriteLine("Player @{0} is {1}",
conn.socket.RemoteEndPoint, conn.IsReady ? "ready" : "not ready"); conn.socket.RemoteEndPoint, client.State);
// start the game if everyone is ready. // start the game if everyone is ready.
if (conns.All(c => c.IsReady)) if (conns.All(c => lobbyInfo.Clients[c.PlayerIndex].State == Session.ClientState.Ready))
{ {
Console.WriteLine("All players are ready. Starting the game!"); Console.WriteLine("All players are ready. Starting the game!");
GameStarted = true;
DispatchOrders(null, 0, DispatchOrders(null, 0,
new ServerOrder(0, "StartGame", "").Serialize()); new ServerOrder(0, "StartGame", "").Serialize());
} }
@@ -336,6 +344,11 @@ namespace OpenRA.Server
foreach (var c in conns.Except(conn).ToArray()) foreach (var c in conns.Except(conn).ToArray())
DispatchOrdersToClient(c, 0, so.Serialize()); DispatchOrdersToClient(c, 0, so.Serialize());
break; break;
case "RequestFile":
Console.WriteLine("** Requesting file: `{0}`", so.Data);
// todo: start serving!
break;
} }
} }
@@ -374,6 +387,7 @@ namespace OpenRA.Server
Console.WriteLine("Server emptied out; doing a bit of housekeeping to prepare for next game.."); Console.WriteLine("Server emptied out; doing a bit of housekeeping to prepare for next game..");
inFlightFrames.Clear(); inFlightFrames.Clear();
lobbyInfo = new Session(); lobbyInfo = new Session();
GameStarted = false;
} }
static void SyncLobbyInfo() static void SyncLobbyInfo()

View File

@@ -160,13 +160,12 @@ namespace OpenRa.Game
buttons.Clear(); buttons.Clear();
renderer.Device.DisableScissor(); renderer.Device.DisableScissor();
renderer.DrawText("RenderFrame {0} ({2:F1} ms)\nTick {1} ({3:F1} ms)\nReady: {4} (F8 to toggle)".F( renderer.DrawText("RenderFrame {0} ({2:F1} ms)\nTick {1} ({3:F1} ms)\n".F(
Game.RenderFrame, Game.RenderFrame,
Game.orderManager.FrameNumber, Game.orderManager.FrameNumber,
PerfHistory.items["render"].LastValue, PerfHistory.items["render"].LastValue,
PerfHistory.items["tick_time"].LastValue, PerfHistory.items["tick_time"].LastValue),
Game.LocalPlayer.IsReady ? "Yes" : "No" new int2(140, 15), Color.White);
), new int2(140, 15), Color.White);
if (Game.Settings.PerfGraph) if (Game.Settings.PerfGraph)
PerfHistory.Render(renderer, Game.worldRenderer.lineRenderer); PerfHistory.Render(renderer, Game.worldRenderer.lineRenderer);

View File

@@ -146,10 +146,8 @@ namespace OpenRa.Game
/* hack hack hack */ /* hack hack hack */
if (e.KeyCode == Keys.F8 && !Game.orderManager.GameStarted) if (e.KeyCode == Keys.F8 && !Game.orderManager.GameStarted)
{ {
Game.LocalPlayer.IsReady ^= true;
Game.controller.AddOrder( Game.controller.AddOrder(
new Order( "ToggleReady", Game.LocalPlayer.PlayerActor, null, int2.Zero, new Order( "ToggleReady", Game.LocalPlayer.PlayerActor, null, int2.Zero, "") { IsImmediate = true });
Game.LocalPlayer.IsReady ? "ready" : "not ready") { IsImmediate = true });
} }
/* temporary hack: DO NOT LEAVE IN */ /* temporary hack: DO NOT LEAVE IN */

View File

@@ -26,8 +26,6 @@ namespace OpenRa.Game
public int PowerProvided = 0; public int PowerProvided = 0;
public int PowerDrained = 0; public int PowerDrained = 0;
public bool IsReady;
public Shroud Shroud = new Shroud(); public Shroud Shroud = new Shroud();
public Dictionary<string, SupportPower> SupportPowers; public Dictionary<string, SupportPower> SupportPowers;