stripped out dead netplay code
This commit is contained in:
@@ -23,7 +23,6 @@ namespace OpenRa.Game
|
||||
public static TerrainRenderer terrain;
|
||||
public static Viewport viewport;
|
||||
public static PathFinder PathFinder;
|
||||
public static Network network;
|
||||
public static WorldRenderer worldRenderer;
|
||||
public static Controller controller;
|
||||
|
||||
@@ -39,6 +38,8 @@ namespace OpenRa.Game
|
||||
|
||||
static ISoundEngine soundEngine;
|
||||
|
||||
public static string Replay;
|
||||
|
||||
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer)
|
||||
{
|
||||
Rules.LoadRules(mapName);
|
||||
@@ -69,15 +70,15 @@ namespace OpenRa.Game
|
||||
|
||||
PathFinder = new PathFinder(map, terrain.tileSet);
|
||||
|
||||
network = new Network();
|
||||
|
||||
controller = new Controller();
|
||||
worldRenderer = new WorldRenderer(renderer);
|
||||
|
||||
soundEngine = new ISoundEngine();
|
||||
sounds = new Cache<string, ISoundSource>(LoadSound);
|
||||
|
||||
orderManager = new OrderManager( new OrderSource[] { new LocalOrderSource() }, "replay.rep" );
|
||||
orderManager = (Replay == "")
|
||||
? new OrderManager(new[] { new LocalOrderSource() }, "replay.rep")
|
||||
: new OrderManager(new[] { new ReplayOrderSource(Replay) });
|
||||
|
||||
PlaySound("intro.aud", false);
|
||||
}
|
||||
@@ -128,7 +129,6 @@ namespace OpenRa.Game
|
||||
|
||||
public static void Tick()
|
||||
{
|
||||
var stuffFromOtherPlayers = network.Tick(); // todo: actually use the orders!
|
||||
world.Update();
|
||||
UnitInfluence.Tick();
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace OpenRa.Game
|
||||
|
||||
UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false);
|
||||
WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false);
|
||||
Game.Replay = settings.GetValue("replay", "");
|
||||
|
||||
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
|
||||
settings.GetValue("player", 1));
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
class Network
|
||||
{
|
||||
public const int Port = 6543;
|
||||
const int netSyncInterval = 40 * 5;
|
||||
|
||||
UdpClient client = new UdpClient(Port);
|
||||
int nextSyncTime = 0;
|
||||
int currentFrame = 0;
|
||||
|
||||
public int CurrentFrame { get { return currentFrame; } }
|
||||
public int RemainingNetSyncTime { get { return Math.Max(0, nextSyncTime - Environment.TickCount); } }
|
||||
|
||||
Queue<Packet> incomingPackets = new Queue<Packet>();
|
||||
|
||||
public Network()
|
||||
{
|
||||
client.EnableBroadcast = true;
|
||||
|
||||
Thread receiveThread = new Thread( () =>
|
||||
{
|
||||
for (; ; )
|
||||
{
|
||||
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
|
||||
byte[] data = client.Receive(ref sender);
|
||||
|
||||
Packet packet = Packet.FromReceivedData(sender, data);
|
||||
|
||||
lock (this)
|
||||
if (currentFrame <= packet.Frame)
|
||||
incomingPackets.Enqueue(packet);
|
||||
}
|
||||
});
|
||||
|
||||
receiveThread.IsBackground = true;
|
||||
receiveThread.Start();
|
||||
}
|
||||
|
||||
public void Send(byte[] data)
|
||||
{
|
||||
IPEndPoint destination = new IPEndPoint(IPAddress.Broadcast, Port);
|
||||
using(MemoryStream ms = new MemoryStream())
|
||||
using (BinaryWriter writer = new BinaryWriter(ms))
|
||||
{
|
||||
writer.Write(currentFrame);
|
||||
writer.Write(data);
|
||||
writer.Flush();
|
||||
|
||||
byte[] toSend = ms.ToArray();
|
||||
|
||||
client.Send(toSend, toSend.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public Queue<Packet> Tick()
|
||||
{
|
||||
Queue<Packet> toProcess = new Queue<Packet>();
|
||||
|
||||
if (Environment.TickCount > nextSyncTime)
|
||||
lock (this)
|
||||
{
|
||||
while (incomingPackets.Count > 0 && incomingPackets.Peek().Frame <= currentFrame)
|
||||
{
|
||||
Packet p = incomingPackets.Dequeue();
|
||||
if (p.Frame == currentFrame)
|
||||
toProcess.Enqueue(p);
|
||||
}
|
||||
|
||||
++currentFrame;
|
||||
nextSyncTime = Environment.TickCount + netSyncInterval;
|
||||
}
|
||||
|
||||
return toProcess;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
class Packet : IComparable<Packet>
|
||||
{
|
||||
IPEndPoint address;
|
||||
int frame;
|
||||
byte[] data;
|
||||
|
||||
public int Frame { get { return frame; } }
|
||||
|
||||
Packet(IPEndPoint address, byte[] data)
|
||||
{
|
||||
this.address = address;
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(data))
|
||||
using (BinaryReader reader = new BinaryReader(ms))
|
||||
{
|
||||
frame = reader.ReadInt32();
|
||||
this.data = reader.ReadBytes(data.Length - 4);
|
||||
}
|
||||
}
|
||||
|
||||
public static Packet FromReceivedData(IPEndPoint sender, byte[] data) { return new Packet(sender, data); }
|
||||
|
||||
public int CompareTo(Packet other) { return frame.CompareTo(other.frame); }
|
||||
}
|
||||
}
|
||||
@@ -100,13 +100,11 @@
|
||||
<Compile Include="IOrderGenerator.cs" />
|
||||
<Compile Include="PlaceBuilding.cs" />
|
||||
<Compile Include="TechTree\Item.cs" />
|
||||
<Compile Include="Network\Packet.cs" />
|
||||
<Compile Include="Player.cs" />
|
||||
<Compile Include="Race.cs" />
|
||||
<Compile Include="Support\SharedResources.cs" />
|
||||
<Compile Include="Graphics\Sheet.cs" />
|
||||
<Compile Include="Support\Log.cs" />
|
||||
<Compile Include="Network\Network.cs" />
|
||||
<Compile Include="PathFinder.cs" />
|
||||
<Compile Include="Graphics\Sequence.cs" />
|
||||
<Compile Include="Order.cs" />
|
||||
|
||||
Reference in New Issue
Block a user