Serialize the actor generation for network orders

This commit is contained in:
abcdefg30
2022-06-24 16:15:13 +02:00
committed by teinarss
parent 13145557c8
commit d1f7fb8fb8
3 changed files with 11 additions and 6 deletions

View File

@@ -118,8 +118,10 @@ namespace OpenRA
{
case TargetType.Actor:
{
if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out var targetActor))
target = Target.FromActor(targetActor);
var actorID = r.ReadUInt32();
var actorGeneration = r.ReadInt32();
if (world != null && TryGetActorFromUInt(world, actorID, out var targetActor))
target = Target.FromSerializedActor(targetActor, actorGeneration);
break;
}
@@ -367,6 +369,7 @@ namespace OpenRA
{
case TargetType.Actor:
w.Write(UIntFromActor(Target.SerializableActor));
w.Write(Target.SerializableGeneration);
break;
case TargetType.FrozenActor:
w.Write(Target.FrozenActor.Viewer.PlayerActor.ActorID);

View File

@@ -77,6 +77,6 @@ namespace OpenRA.Server
// The protocol for server and world orders
// This applies after the handshake has completed, and is provided to support
// alternative server implementations that wish to support multiple versions in parallel
public const int Orders = 19;
public const int Orders = 20;
}
}

View File

@@ -56,11 +56,11 @@ namespace OpenRA.Traits
generation = 0;
}
Target(Actor a)
Target(Actor a, int generation)
{
type = TargetType.Actor;
actor = a;
generation = a.Generation;
this.generation = generation;
terrainCenterPosition = WPos.Zero;
terrainPositions = null;
@@ -85,7 +85,7 @@ namespace OpenRA.Traits
public static Target FromPos(WPos p) { return new Target(p); }
public static Target FromTargetPositions(in Target t) { return new Target(t.CenterPosition, t.Positions.ToArray()); }
public static Target FromCell(World w, CPos c, SubCell subCell = SubCell.FullCell) { return new Target(w, c, subCell); }
public static Target FromActor(Actor a) { return a != null ? new Target(a) : Invalid; }
public static Target FromActor(Actor a) { return a != null ? new Target(a, a.Generation) : Invalid; }
public static Target FromFrozenActor(FrozenActor fa) { return new Target(fa); }
public Actor Actor => actor;
@@ -225,8 +225,10 @@ namespace OpenRA.Traits
}
// Expose internal state for serialization by the orders code *only*
internal static Target FromSerializedActor(Actor a, int generation) { return a != null ? new Target(a, generation) : Invalid; }
internal TargetType SerializableType => type;
internal Actor SerializableActor => actor;
internal int SerializableGeneration => generation;
internal CPos? SerializableCell => cell;
internal SubCell? SerializableSubCell => subCell;
internal WPos SerializablePos => terrainCenterPosition;