OrdersForFrame now returns serialized orders
This commit is contained in:
@@ -5,7 +5,7 @@ namespace OpenRa.Orders
|
|||||||
interface IOrderSource
|
interface IOrderSource
|
||||||
{
|
{
|
||||||
void SendLocalOrders(int localFrame, List<Order> localOrders);
|
void SendLocalOrders(int localFrame, List<Order> localOrders);
|
||||||
List<Order> OrdersForFrame(int currentFrame);
|
List<byte[]> OrdersForFrame(int currentFrame);
|
||||||
bool IsReadyForFrame(int frameNumber);
|
bool IsReadyForFrame(int frameNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRa.Orders
|
namespace OpenRa.Orders
|
||||||
{
|
{
|
||||||
class LocalOrderSource : IOrderSource
|
class LocalOrderSource : IOrderSource
|
||||||
{
|
{
|
||||||
Dictionary<int, List<Order>> orders = new Dictionary<int, List<Order>>();
|
Dictionary<int, List<byte[]>> orders = new Dictionary<int, List<byte[]>>();
|
||||||
|
|
||||||
public List<Order> OrdersForFrame(int currentFrame)
|
public List<byte[]> OrdersForFrame(int currentFrame)
|
||||||
{
|
{
|
||||||
if (!orders.ContainsKey(currentFrame))
|
if (!orders.ContainsKey(currentFrame))
|
||||||
return new List<Order>();
|
return new List<byte[]>();
|
||||||
|
|
||||||
var result = orders[currentFrame];
|
var result = orders[currentFrame];
|
||||||
orders.Remove(currentFrame);
|
orders.Remove(currentFrame);
|
||||||
@@ -19,7 +20,7 @@ namespace OpenRa.Orders
|
|||||||
public void SendLocalOrders(int localFrame, List<Order> localOrders)
|
public void SendLocalOrders(int localFrame, List<Order> localOrders)
|
||||||
{
|
{
|
||||||
if (localFrame == 0) return;
|
if (localFrame == 0) return;
|
||||||
orders[localFrame] = localOrders;
|
orders[localFrame] = localOrders.Select(o=>o.Serialize()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsReadyForFrame(int frameNumber)
|
public bool IsReadyForFrame(int frameNumber)
|
||||||
|
|||||||
@@ -92,10 +92,9 @@ namespace OpenRa.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Order> OrdersForFrame(int currentFrame)
|
public List<byte[]> OrdersForFrame(int currentFrame)
|
||||||
{
|
{
|
||||||
var orderData = ExtractOrders(currentFrame);
|
return ExtractOrders(currentFrame).ToList();
|
||||||
return orderData.SelectMany(a => a.ToOrderList()).ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendLocalOrders(int localFrame, List<Order> localOrders)
|
public void SendLocalOrders(int localFrame, List<Order> localOrders)
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ namespace OpenRa.Orders
|
|||||||
{
|
{
|
||||||
var orders = sources
|
var orders = sources
|
||||||
.SelectMany(s => s.OrdersForFrame(frame))
|
.SelectMany(s => s.OrdersForFrame(frame))
|
||||||
|
.SelectMany(x => x.ToOrderList())
|
||||||
.Where(o => o.Validate()) /* drop bogus things */
|
.Where(o => o.Validate()) /* drop bogus things */
|
||||||
.OrderBy(o => o.Player.Index)
|
.OrderBy(o => o.Player.Index)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|||||||
@@ -14,25 +14,25 @@ namespace OpenRa.Orders
|
|||||||
|
|
||||||
public void SendLocalOrders(int localFrame, List<Order> localOrders) { }
|
public void SendLocalOrders(int localFrame, List<Order> localOrders) { }
|
||||||
|
|
||||||
public List<Order> OrdersForFrame(int frameNumber)
|
public List<byte[]> OrdersForFrame(int frameNumber)
|
||||||
{
|
{
|
||||||
if (frameNumber == 0)
|
if (frameNumber == 0)
|
||||||
return new List<Order>();
|
return new List<byte[]>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var len = replayReader.ReadInt32() - 4;
|
var len = replayReader.ReadInt32() - 4;
|
||||||
var frame = replayReader.ReadInt32();
|
var frame = replayReader.ReadInt32();
|
||||||
var ret = replayReader.ReadBytes(len).ToOrderList();
|
var ret = replayReader.ReadBytes(len);
|
||||||
|
|
||||||
if (frameNumber != frame)
|
if (frameNumber != frame)
|
||||||
throw new InvalidOperationException("Attempted time-travel in OrdersForFrame (replay)");
|
throw new InvalidOperationException("Attempted time-travel in OrdersForFrame (replay)");
|
||||||
|
|
||||||
return ret;
|
return new List<byte[]> { ret };
|
||||||
}
|
}
|
||||||
catch (EndOfStreamException)
|
catch (EndOfStreamException)
|
||||||
{
|
{
|
||||||
return new List<Order>();
|
return new List<byte[]>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user