Merge branch 'master' of git://github.com/chrisforbes/OpenRA into cpu-independent
This commit is contained in:
@@ -47,8 +47,7 @@ namespace OpenRa
|
||||
{
|
||||
if (orderGenerator == null) return;
|
||||
|
||||
var orders = orderGenerator.Order(xy.ToInt2(), mi)
|
||||
.Where(order => order.Validate()).ToArray();
|
||||
var orders = orderGenerator.Order(xy.ToInt2(), mi).ToArray();
|
||||
recentOrders.AddRange( orders );
|
||||
|
||||
var voicedActor = orders.Select(o => o.Subject)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -8,41 +8,24 @@ namespace OpenRa
|
||||
public sealed class Order
|
||||
{
|
||||
public readonly string OrderString;
|
||||
readonly uint SubjectId;
|
||||
readonly uint TargetActorId;
|
||||
public readonly Actor Subject;
|
||||
public readonly Actor TargetActor;
|
||||
public readonly int2 TargetLocation;
|
||||
public readonly string TargetString;
|
||||
public bool IsImmediate;
|
||||
|
||||
public Actor Subject { get { return ActorFromUInt(SubjectId); } }
|
||||
public Actor TargetActor { get { return ActorFromUInt(TargetActorId); } }
|
||||
public Player Player { get { return Subject.Owner; } }
|
||||
|
||||
public Order(string orderString, Actor subject,
|
||||
Actor targetActor, int2 targetLocation, string targetString)
|
||||
: this( orderString, UIntFromActor( subject ),
|
||||
UIntFromActor( targetActor ), targetLocation, targetString) {}
|
||||
|
||||
Order(string orderString, uint subjectId,
|
||||
uint targetActorId, int2 targetLocation, string targetString)
|
||||
{
|
||||
this.OrderString = orderString;
|
||||
this.SubjectId = subjectId;
|
||||
this.TargetActorId = targetActorId;
|
||||
this.Subject = subject;
|
||||
this.TargetActor = targetActor;
|
||||
this.TargetLocation = targetLocation;
|
||||
this.TargetString = targetString;
|
||||
}
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
if ((SubjectId != 0xffffffff) && Subject == null)
|
||||
return false;
|
||||
if ((TargetActorId != 0xffffffff) && TargetActor == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] Serialize()
|
||||
{
|
||||
if (IsImmediate) /* chat, whatever */
|
||||
@@ -69,8 +52,8 @@ namespace OpenRa
|
||||
var w = new BinaryWriter(ret);
|
||||
w.Write( (byte)0xFF );
|
||||
w.Write(OrderString);
|
||||
w.Write(SubjectId);
|
||||
w.Write(TargetActorId);
|
||||
w.Write(UIntFromActor(Subject));
|
||||
w.Write(UIntFromActor(TargetActor));
|
||||
w.Write(TargetLocation.X);
|
||||
w.Write(TargetLocation.Y);
|
||||
w.Write(TargetString != null);
|
||||
@@ -103,7 +86,11 @@ namespace OpenRa
|
||||
if (r.ReadBoolean())
|
||||
targetString = r.ReadString();
|
||||
|
||||
return new Order( order, subjectId, targetActorId, targetLocation, targetString);
|
||||
Actor subject, targetActor;
|
||||
if( !TryGetActorFromUInt( subjectId, out subject ) || !TryGetActorFromUInt( targetActorId, out targetActor ) )
|
||||
return null;
|
||||
|
||||
return new Order( order, subject, targetActor, targetLocation, targetString);
|
||||
}
|
||||
|
||||
case 0xfe:
|
||||
@@ -126,10 +113,23 @@ namespace OpenRa
|
||||
return a.ActorID;
|
||||
}
|
||||
|
||||
static Actor ActorFromUInt(uint aID)
|
||||
static bool TryGetActorFromUInt(uint aID, out Actor ret )
|
||||
{
|
||||
if (aID == 0xFFFFFFFF) return null;
|
||||
return Game.world.Actors.SingleOrDefault(x => x.ActorID == aID);
|
||||
if( aID == 0xFFFFFFFF )
|
||||
{
|
||||
ret = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( var a in Game.world.Actors.Where( x => x.ActorID == aID ) )
|
||||
{
|
||||
ret = a;
|
||||
return true;
|
||||
}
|
||||
ret = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Named constructors for Orders.
|
||||
|
||||
@@ -27,8 +27,12 @@ namespace OpenRa.Orders
|
||||
var ms = new MemoryStream(bytes);
|
||||
var reader = new BinaryReader(ms);
|
||||
var ret = new List<Order>();
|
||||
while (ms.Position < ms.Length)
|
||||
ret.Add(Order.Deserialize(reader));
|
||||
while( ms.Position < ms.Length )
|
||||
{
|
||||
var o = Order.Deserialize( reader );
|
||||
if( o != null )
|
||||
ret.Add( o );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace OpenRa.Orders
|
||||
{
|
||||
var orders = sources
|
||||
.SelectMany(s => s.OrdersForFrame(frame))
|
||||
.Where(o => o.Validate()) /* drop bogus things */
|
||||
.SelectMany(x => x.ToOrderList())
|
||||
.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[]>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ namespace OpenRa.Orders
|
||||
{
|
||||
var p = Game.controller.MousePosition;
|
||||
var c = Order(p.ToInt2(), mi)
|
||||
.Where(o => o.Validate())
|
||||
.Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation))
|
||||
.FirstOrDefault(a => a != null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user