stripped out dead netplay code
This commit is contained in:
@@ -8,26 +8,26 @@ using System.Drawing;
|
|||||||
using OpenRa.Game.Traits;
|
using OpenRa.Game.Traits;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
public IOrderGenerator orderGenerator;
|
public IOrderGenerator orderGenerator;
|
||||||
|
|
||||||
List<Order> recentOrders = new List<Order>();
|
List<Order> recentOrders = new List<Order>();
|
||||||
|
|
||||||
void ApplyOrders(float2 xy, bool left)
|
void ApplyOrders(float2 xy, bool left)
|
||||||
{
|
{
|
||||||
var doVoice = null as Actor;
|
var doVoice = null as Actor;
|
||||||
if( orderGenerator != null )
|
if (orderGenerator != null)
|
||||||
foreach( var order in orderGenerator.Order( xy.ToInt2(), left ) )
|
foreach (var order in orderGenerator.Order(xy.ToInt2(), left))
|
||||||
{
|
{
|
||||||
recentOrders.Add( order );
|
recentOrders.Add(order);
|
||||||
//UnitOrders.ProcessOrder( order );
|
//UnitOrders.ProcessOrder( order );
|
||||||
if( order.Subject != null && order.Player == Game.LocalPlayer )
|
if (order.Subject != null && order.Player == Game.LocalPlayer)
|
||||||
doVoice = order.Subject;
|
doVoice = order.Subject;
|
||||||
}
|
}
|
||||||
if( doVoice != null )
|
if (doVoice != null)
|
||||||
Game.PlaySound( Game.SovietVoices.First.GetNext() + GetVoiceSuffix( doVoice ), false );
|
Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(doVoice), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Order> GetRecentOrders()
|
public List<Order> GetRecentOrders()
|
||||||
@@ -35,89 +35,89 @@ namespace OpenRa.Game
|
|||||||
var ret = recentOrders;
|
var ret = recentOrders;
|
||||||
recentOrders = new List<Order>();
|
recentOrders = new List<Order>();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetVoiceSuffix( Actor unit )
|
static string GetVoiceSuffix(Actor unit)
|
||||||
{
|
{
|
||||||
var suffixes = new[] { ".r01", ".r03" };
|
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)
|
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))
|
if (!(orderGenerator is PlaceBuilding))
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
ApplyOrders(xy, true);
|
ApplyOrders(xy, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move)
|
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move)
|
||||||
dragEnd = xy;
|
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 (!(orderGenerator is PlaceBuilding))
|
||||||
{
|
{
|
||||||
if (dragStart != xy)
|
if (dragStart != xy)
|
||||||
orderGenerator = new UnitOrderGenerator(
|
orderGenerator = new UnitOrderGenerator(
|
||||||
Game.SelectUnitsInBox( Game.CellSize * dragStart, Game.CellSize * xy ) );
|
Game.SelectUnitsInBox(Game.CellSize * dragStart, Game.CellSize * xy));
|
||||||
else
|
else
|
||||||
orderGenerator = new UnitOrderGenerator(
|
orderGenerator = new UnitOrderGenerator(
|
||||||
Game.SelectUnitOrBuilding( Game.CellSize * xy ) );
|
Game.SelectUnitOrBuilding(Game.CellSize * xy));
|
||||||
}
|
}
|
||||||
|
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButtons.None && mi.Event == MouseInputEvent.Move)
|
if (mi.Button == MouseButtons.None && mi.Event == MouseInputEvent.Move)
|
||||||
{
|
{
|
||||||
/* update the cursor to reflect the thing under us - note this
|
/* update the cursor to reflect the thing under us - note this
|
||||||
* needs to also happen when the *thing* changes, so per-frame hook */
|
* needs to also happen when the *thing* changes, so per-frame hook */
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down)
|
||||||
ApplyOrders(xy, false);
|
ApplyOrders(xy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<float2, float2>? SelectionBox
|
public Pair<float2, float2>? SelectionBox
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (dragStart == dragEnd) return null;
|
if (dragStart == dragEnd) return null;
|
||||||
return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd);
|
return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor ChooseCursor()
|
public Cursor ChooseCursor()
|
||||||
{
|
{
|
||||||
var uog = orderGenerator as UnitOrderGenerator;
|
var uog = orderGenerator as UnitOrderGenerator;
|
||||||
|
|
||||||
if (uog != null)
|
if (uog != null)
|
||||||
uog.selection.RemoveAll(a => a.IsDead);
|
uog.selection.RemoveAll(a => a.IsDead);
|
||||||
|
|
||||||
if (uog != null && uog.selection.Count > 0
|
if (uog != null && uog.selection.Count > 0
|
||||||
&& uog.selection.Any(a => a.traits.Contains<Traits.Mobile>())
|
&& 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>())
|
var umts = uog.selection.Select(a => a.traits.GetOrDefault<Mobile>())
|
||||||
.Where(m => m != null)
|
.Where(m => m != null)
|
||||||
.Select(m => m.GetMovementType())
|
.Select(m => m.GetMovementType())
|
||||||
.Distinct();
|
.Distinct();
|
||||||
|
|
||||||
if (!umts.Any( umt => Game.IsCellBuildable( dragEnd.ToInt2(), umt ) ))
|
if (!umts.Any(umt => Game.IsCellBuildable(dragEnd.ToInt2(), umt)))
|
||||||
return Cursor.MoveBlocked;
|
return Cursor.MoveBlocked;
|
||||||
return Cursor.Move;
|
return Cursor.Move;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
|
if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
|
||||||
return Cursor.Select;
|
return Cursor.Select;
|
||||||
|
|
||||||
return Cursor.Default;
|
return Cursor.Default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ namespace OpenRa.Game
|
|||||||
public static TerrainRenderer terrain;
|
public static TerrainRenderer terrain;
|
||||||
public static Viewport viewport;
|
public static Viewport viewport;
|
||||||
public static PathFinder PathFinder;
|
public static PathFinder PathFinder;
|
||||||
public static Network network;
|
|
||||||
public static WorldRenderer worldRenderer;
|
public static WorldRenderer worldRenderer;
|
||||||
public static Controller controller;
|
public static Controller controller;
|
||||||
|
|
||||||
@@ -37,7 +36,9 @@ namespace OpenRa.Game
|
|||||||
public static BuildingInfluenceMap BuildingInfluence;
|
public static BuildingInfluenceMap BuildingInfluence;
|
||||||
public static UnitInfluenceMap UnitInfluence;
|
public static UnitInfluenceMap UnitInfluence;
|
||||||
|
|
||||||
static ISoundEngine soundEngine;
|
static ISoundEngine soundEngine;
|
||||||
|
|
||||||
|
public static string Replay;
|
||||||
|
|
||||||
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer)
|
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer)
|
||||||
{
|
{
|
||||||
@@ -69,15 +70,15 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
PathFinder = new PathFinder(map, terrain.tileSet);
|
PathFinder = new PathFinder(map, terrain.tileSet);
|
||||||
|
|
||||||
network = new Network();
|
|
||||||
|
|
||||||
controller = new Controller();
|
controller = new Controller();
|
||||||
worldRenderer = new WorldRenderer(renderer);
|
worldRenderer = new WorldRenderer(renderer);
|
||||||
|
|
||||||
soundEngine = new ISoundEngine();
|
soundEngine = new ISoundEngine();
|
||||||
sounds = new Cache<string, ISoundSource>(LoadSound);
|
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);
|
PlaySound("intro.aud", false);
|
||||||
}
|
}
|
||||||
@@ -128,7 +129,6 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public static void Tick()
|
public static void Tick()
|
||||||
{
|
{
|
||||||
var stuffFromOtherPlayers = network.Tick(); // todo: actually use the orders!
|
|
||||||
world.Update();
|
world.Update();
|
||||||
UnitInfluence.Tick();
|
UnitInfluence.Tick();
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ namespace OpenRa.Game
|
|||||||
SheetBuilder.Initialize(renderer);
|
SheetBuilder.Initialize(renderer);
|
||||||
|
|
||||||
UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false);
|
UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false);
|
||||||
WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false);
|
WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false);
|
||||||
|
Game.Replay = settings.GetValue("replay", "");
|
||||||
|
|
||||||
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
|
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
|
||||||
settings.GetValue("player", 1));
|
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="IOrderGenerator.cs" />
|
||||||
<Compile Include="PlaceBuilding.cs" />
|
<Compile Include="PlaceBuilding.cs" />
|
||||||
<Compile Include="TechTree\Item.cs" />
|
<Compile Include="TechTree\Item.cs" />
|
||||||
<Compile Include="Network\Packet.cs" />
|
|
||||||
<Compile Include="Player.cs" />
|
<Compile Include="Player.cs" />
|
||||||
<Compile Include="Race.cs" />
|
<Compile Include="Race.cs" />
|
||||||
<Compile Include="Support\SharedResources.cs" />
|
<Compile Include="Support\SharedResources.cs" />
|
||||||
<Compile Include="Graphics\Sheet.cs" />
|
<Compile Include="Graphics\Sheet.cs" />
|
||||||
<Compile Include="Support\Log.cs" />
|
<Compile Include="Support\Log.cs" />
|
||||||
<Compile Include="Network\Network.cs" />
|
|
||||||
<Compile Include="PathFinder.cs" />
|
<Compile Include="PathFinder.cs" />
|
||||||
<Compile Include="Graphics\Sequence.cs" />
|
<Compile Include="Graphics\Sequence.cs" />
|
||||||
<Compile Include="Order.cs" />
|
<Compile Include="Order.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user