stripped out dead netplay code
This commit is contained in:
@@ -18,16 +18,16 @@ namespace OpenRa.Game
|
||||
void ApplyOrders(float2 xy, bool left)
|
||||
{
|
||||
var doVoice = null as Actor;
|
||||
if( orderGenerator != null )
|
||||
foreach( var order in orderGenerator.Order( xy.ToInt2(), left ) )
|
||||
if (orderGenerator != null)
|
||||
foreach (var order in orderGenerator.Order(xy.ToInt2(), left))
|
||||
{
|
||||
recentOrders.Add( order );
|
||||
recentOrders.Add(order);
|
||||
//UnitOrders.ProcessOrder( order );
|
||||
if( order.Subject != null && order.Player == Game.LocalPlayer )
|
||||
if (order.Subject != null && order.Player == Game.LocalPlayer)
|
||||
doVoice = order.Subject;
|
||||
}
|
||||
if( doVoice != null )
|
||||
Game.PlaySound( Game.SovietVoices.First.GetNext() + GetVoiceSuffix( doVoice ), false );
|
||||
if (doVoice != null)
|
||||
Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(doVoice), false);
|
||||
}
|
||||
|
||||
public List<Order> GetRecentOrders()
|
||||
@@ -37,61 +37,61 @@ namespace OpenRa.Game
|
||||
return ret;
|
||||
}
|
||||
|
||||
static string GetVoiceSuffix( Actor unit )
|
||||
static string GetVoiceSuffix(Actor unit)
|
||||
{
|
||||
var suffixes = new[] { ".r01", ".r03" };
|
||||
return suffixes[ unit.traits.Get<Traits.Mobile>().Voice ];
|
||||
return suffixes[unit.traits.Get<Traits.Mobile>().Voice];
|
||||
}
|
||||
|
||||
float2 dragStart, dragEnd;
|
||||
float2 dragStart, dragEnd;
|
||||
public void HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
var xy = Game.viewport.ViewToWorld(mi);
|
||||
var xy = Game.viewport.ViewToWorld(mi);
|
||||
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
if (!(orderGenerator is PlaceBuilding))
|
||||
dragStart = dragEnd = xy;
|
||||
ApplyOrders(xy, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move)
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move)
|
||||
dragEnd = xy;
|
||||
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
if (!(orderGenerator is PlaceBuilding))
|
||||
{
|
||||
if (dragStart != xy)
|
||||
orderGenerator = new UnitOrderGenerator(
|
||||
Game.SelectUnitsInBox( Game.CellSize * dragStart, Game.CellSize * xy ) );
|
||||
Game.SelectUnitsInBox(Game.CellSize * dragStart, Game.CellSize * xy));
|
||||
else
|
||||
orderGenerator = new UnitOrderGenerator(
|
||||
Game.SelectUnitOrBuilding( Game.CellSize * xy ) );
|
||||
Game.SelectUnitOrBuilding(Game.CellSize * xy));
|
||||
}
|
||||
|
||||
dragStart = dragEnd = xy;
|
||||
}
|
||||
}
|
||||
|
||||
if (mi.Button == MouseButtons.None && mi.Event == MouseInputEvent.Move)
|
||||
{
|
||||
/* update the cursor to reflect the thing under us - note this
|
||||
* needs to also happen when the *thing* changes, so per-frame hook */
|
||||
if (mi.Button == MouseButtons.None && mi.Event == MouseInputEvent.Move)
|
||||
{
|
||||
/* update the cursor to reflect the thing under us - note this
|
||||
* needs to also happen when the *thing* changes, so per-frame hook */
|
||||
dragStart = dragEnd = xy;
|
||||
}
|
||||
}
|
||||
|
||||
if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down)
|
||||
ApplyOrders(xy, false);
|
||||
}
|
||||
|
||||
public Pair<float2, float2>? SelectionBox
|
||||
{
|
||||
public Pair<float2, float2>? SelectionBox
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dragStart == dragEnd) return null;
|
||||
return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Cursor ChooseCursor()
|
||||
{
|
||||
@@ -102,14 +102,14 @@ namespace OpenRa.Game
|
||||
|
||||
if (uog != null && uog.selection.Count > 0
|
||||
&& uog.selection.Any(a => a.traits.Contains<Traits.Mobile>())
|
||||
&& uog.selection.All( a => a.Owner == Game.LocalPlayer ))
|
||||
&& uog.selection.All(a => a.Owner == Game.LocalPlayer))
|
||||
{
|
||||
var umts = uog.selection.Select(a => a.traits.GetOrDefault<Mobile>())
|
||||
.Where(m => m != null)
|
||||
.Select(m => m.GetMovementType())
|
||||
.Distinct();
|
||||
|
||||
if (!umts.Any( umt => Game.IsCellBuildable( dragEnd.ToInt2(), umt ) ))
|
||||
if (!umts.Any(umt => Game.IsCellBuildable(dragEnd.ToInt2(), umt)))
|
||||
return Cursor.MoveBlocked;
|
||||
return Cursor.Move;
|
||||
}
|
||||
|
||||
@@ -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