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