Renamed SyncAttribute to VerifySyncAttribute

This commit is contained in:
Pavel Penev
2023-12-05 15:06:48 +02:00
committed by Gustas Kažukauskas
parent ec75dcd9e9
commit d4fd66adf9
66 changed files with 117 additions and 114 deletions

View File

@@ -202,10 +202,10 @@ namespace OpenRA.Network
{
const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
var fields = type.GetFields(Flags)
.Where(fi => !fi.IsLiteral && !fi.IsStatic && fi.HasAttribute<SyncAttribute>())
.Where(fi => !fi.IsLiteral && !fi.IsStatic && fi.HasAttribute<VerifySyncAttribute>())
.ToList();
var properties = type.GetProperties(Flags)
.Where(pi => pi.HasAttribute<SyncAttribute>())
.Where(pi => pi.HasAttribute<VerifySyncAttribute>())
.ToList();
foreach (var prop in properties)

View File

@@ -21,7 +21,7 @@ using OpenRA.Traits;
namespace OpenRA
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class SyncAttribute : Attribute { }
public sealed class VerifySyncAttribute : Attribute { }
// Marker interface
public interface ISync { }
@@ -70,7 +70,7 @@ namespace OpenRA
il.MarkLabel(l);
}
else if (type != typeof(int))
throw new NotImplementedException($"SyncAttribute on member of unhashable type: {type.FullName}");
throw new NotImplementedException($"{nameof(VerifySyncAttribute)} on member of unhashable type: {type.FullName}");
il.Emit(OpCodes.Xor);
}
@@ -86,7 +86,7 @@ namespace OpenRA
il.Emit(OpCodes.Ldc_I4_0);
const BindingFlags Binding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
foreach (var field in t.GetFields(Binding).Where(x => x.HasAttribute<SyncAttribute>()))
foreach (var field in t.GetFields(Binding).Where(x => x.HasAttribute<VerifySyncAttribute>()))
{
il.Emit(OpCodes.Ldloc, this_);
il.Emit(OpCodes.Ldfld, field);
@@ -94,7 +94,7 @@ namespace OpenRA
EmitSyncOpcodes(field.FieldType, il);
}
foreach (var prop in t.GetProperties(Binding).Where(x => x.HasAttribute<SyncAttribute>()))
foreach (var prop in t.GetProperties(Binding).Where(x => x.HasAttribute<VerifySyncAttribute>()))
{
il.Emit(OpCodes.Ldloc, this_);
il.EmitCall(OpCodes.Call, prop.GetGetMethod(true), null);

View File

@@ -21,8 +21,9 @@ namespace OpenRA.Traits
public class DebugPauseState : ISync
{
readonly World world;
[Sync]
public bool Paused => world.Paused;
[VerifySync]
public bool IsWorldPaused => world.Paused;
public DebugPauseState(World world) { this.world = world; }
}

View File

@@ -244,10 +244,10 @@ namespace OpenRA.Traits
public class FrozenActorLayer : IRender, ITick, ISync
{
[Sync]
[VerifySync]
public int VisibilityHash;
[Sync]
[VerifySync]
public int FrozenHash;
readonly int binSize;

View File

@@ -100,7 +100,8 @@ namespace OpenRA.Traits
readonly ProjectedCellLayer<ShroudCellType> resolvedType;
bool disabledChanged;
[Sync]
[VerifySync]
bool disabled;
public bool Disabled
{

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Cnc.Projectiles
int ticksUntilRemove;
int damageDuration;
[Sync]
[VerifySync]
WPos target;
public TeslaZap(TeslaZapInfo info, ProjectileArgs args)

View File

@@ -43,10 +43,10 @@ namespace OpenRA.Mods.Cnc.Traits
{
readonly AttackTeslaInfo info;
[Sync]
[VerifySync]
int charges;
[Sync]
[VerifySync]
int timeToRecharge;
public AttackTesla(Actor self, AttackTeslaInfo info)

View File

@@ -55,10 +55,10 @@ namespace OpenRA.Mods.Cnc.Traits
IPositionable iPositionable;
// Return-to-origin logic
[Sync]
[VerifySync]
public CPos Origin;
[Sync]
[VerifySync]
public int ReturnTicks = 0;
public Chronoshiftable(ActorInitializer init, ChronoshiftableInfo info)

View File

@@ -69,13 +69,13 @@ namespace OpenRA.Mods.Cnc.Traits
bool returnOriginal;
bool selling;
[Sync]
[VerifySync]
int returnTicks = 0;
[Sync]
[VerifySync]
readonly CPos origin;
[Sync]
[VerifySync]
bool triggered;
public ConyardChronoReturn(ActorInitializer init, ConyardChronoReturnInfo info)

View File

@@ -27,17 +27,17 @@ namespace OpenRA.Mods.Cnc.Traits
sealed class GpsWatcher : ISync, IPreventsShroudReset
{
[Sync]
[VerifySync]
public bool Launched { get; private set; }
[Sync]
[VerifySync]
public bool GrantedAllies { get; private set; }
[Sync]
[VerifySync]
public bool Granted { get; private set; }
// Whether this watcher has explored the terrain (by becoming Launched, or an ally becoming Launched)
[Sync]
[VerifySync]
bool explored;
readonly Player owner;

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Cnc.Traits
sealed class PortableChrono : PausableConditionalTrait<PortableChronoInfo>, IIssueOrder, IResolveOrder, ITick, ISelectionBar, IOrderVoice, ISync
{
readonly IMove move;
[Sync]
[VerifySync]
int chargeTick = 0;
public PortableChrono(Actor self, PortableChronoInfo info)

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Cnc.Traits
IEnumerable<int> speedModifiers;
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
[Sync]
[VerifySync]
public WAngle Facing
{
get => Orientation.Yaw;
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Cnc.Traits
public WRot Orientation { get; private set; }
[Sync]
[VerifySync]
public WPos CenterPosition { get; private set; }
public CPos TopLeft => self.World.Map.CellContaining(CenterPosition);

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Lint
const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly;
while (type != null)
{
if (((MemberInfo[])type.GetFields(Flags)).Concat(type.GetProperties(Flags)).Any(Utility.HasAttribute<SyncAttribute>))
if (((MemberInfo[])type.GetFields(Flags)).Concat(type.GetProperties(Flags)).Any(Utility.HasAttribute<VerifySyncAttribute>))
return true;
type = type.BaseType;
}

View File

@@ -95,13 +95,13 @@ namespace OpenRA.Mods.Common.Projectiles
readonly WDist speed;
readonly WDist weaponRange;
[Sync]
[VerifySync]
WPos headPos;
[Sync]
[VerifySync]
WPos tailPos;
[Sync]
[VerifySync]
WPos target;
int length;

View File

@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Projectiles
readonly ContrailRenderable contrail;
[Sync]
[VerifySync]
protected WPos pos, lastPos, target, source;
int length;

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Projectiles
WVec velocity;
[Sync]
[VerifySync]
WPos pos, lastPos;
public GravityBomb(GravityBombInfo info, ProjectileArgs args)

View File

@@ -118,10 +118,10 @@ namespace OpenRA.Mods.Common.Projectiles
int interval;
bool showHitAnim;
[Sync]
[VerifySync]
WPos target;
[Sync]
[VerifySync]
WPos source;
public LaserZap(LaserZapInfo info, ProjectileArgs args, Color color)

View File

@@ -229,7 +229,7 @@ namespace OpenRA.Mods.Common.Projectiles
WVec tarVel;
WVec predVel;
[Sync]
[VerifySync]
WPos pos;
WVec velocity;
@@ -240,10 +240,10 @@ namespace OpenRA.Mods.Common.Projectiles
WAngle renderFacing;
[Sync]
[VerifySync]
int hFacing;
[Sync]
[VerifySync]
int vFacing;
public Missile(MissileInfo info, ProjectileArgs args)

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Projectiles
int ticks;
bool animationComplete;
[Sync]
[VerifySync]
WPos target;
// Computing these in Railgun instead of RailgunRenderable saves Info.Duration ticks of computation.

View File

@@ -39,13 +39,13 @@ namespace OpenRA.Mods.Common.Traits
readonly HashSet<PPos> footprint;
[Sync]
[VerifySync]
CPos cachedLocation;
[Sync]
[VerifySync]
WDist cachedRange;
[Sync]
[VerifySync]
protected bool CachedTraitDisabled { get; private set; }
WPos cachedPos;

View File

@@ -242,7 +242,7 @@ namespace OpenRA.Mods.Common.Traits
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
IOverrideAircraftLanding overrideAircraftLanding;
[Sync]
[VerifySync]
public WAngle Facing
{
get => Orientation.Yaw;
@@ -263,7 +263,7 @@ namespace OpenRA.Mods.Common.Traits
public WRot Orientation { get; private set; }
[Sync]
[VerifySync]
public WPos CenterPosition { get; private set; }
public CPos TopLeft => self.World.Map.CellContaining(CenterPosition);

View File

@@ -27,13 +27,13 @@ namespace OpenRA.Mods.Common.Traits
{
readonly AttackBomberInfo info;
[Sync]
[VerifySync]
Target target;
[Sync]
[VerifySync]
bool inAttackRange;
[Sync]
[VerifySync]
bool facingTarget = true;
public event Action<Actor> OnRemovedFromWorld = self => { };

View File

@@ -53,10 +53,10 @@ namespace OpenRA.Mods.Common.Traits
readonly Stack<int> tokens = [];
// HACK: Temporarily needed until Rearm activity is gone for good
[Sync]
[VerifySync]
public int RemainingTicks;
[Sync]
[VerifySync]
public int CurrentAmmoCount { get; private set; }
public bool HasAmmo => CurrentAmmoCount > 0;

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits
readonly string attackOrderName = "Attack";
readonly string forceAttackOrderName = "ForceAttack";
[Sync]
[VerifySync]
public bool IsAiming { get; set; }
public IEnumerable<Armament> Armaments => getArmaments();

View File

@@ -137,13 +137,13 @@ namespace OpenRA.Mods.Common.Traits
readonly bool allowMovement;
[Sync]
[VerifySync]
int nextScanTime = 0;
public UnitStance Stance { get; private set; }
public bool AllowMove => allowMovement && Stance > UnitStance.Defend;
[Sync]
[VerifySync]
public Actor Aggressor;
// NOT SYNCED: do not refer to this anywhere other than UI code

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
readonly BodyOrientationInfo info;
readonly Lazy<int> quantizedFacings;
[Sync]
[VerifySync]
public int QuantizedFacings => quantizedFacings.Value;
public BodyOrientation(ActorInitializer init, BodyOrientationInfo info)

View File

@@ -267,6 +267,7 @@ namespace OpenRA.Mods.Common.Traits
INotifyAddedToWorld, INotifyRemovedFromWorld
{
public readonly BuildingInfo Info;
readonly Actor self;
readonly BuildingInfluence influence;
@@ -274,7 +275,7 @@ namespace OpenRA.Mods.Common.Traits
readonly (CPos, SubCell)[] targetableCells;
readonly CPos[] transitOnlyCells;
[Sync]
[VerifySync]
public CPos TopLeft { get; }
public WPos CenterPosition { get; }

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int OpenPosition;
[Sync]
[VerifySync]
public int Position { get; private set; }
int desiredPosition;

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
isNotActiveAlly = player => player.WinState != WinState.Undefined || self.Owner.RelationshipWith(player) != PlayerRelationship.Ally;
}
[Sync]
[VerifySync]
public int RepairersHash
{
get

View File

@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits
readonly Actor self;
// The actor we are currently carrying.
[Sync]
[VerifySync]
public Actor Carryable { get; protected set; }
public CarryallState State { get; protected set; }

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
PlayerResources resources;
Cloak[] cloaks;
[Sync]
[VerifySync]
public int Ticks { get; private set; }
public CashTrickler(CashTricklerInfo info)

View File

@@ -45,10 +45,10 @@ namespace OpenRA.Mods.Common.Traits
{
readonly IHealth health;
[Sync]
[VerifySync]
int ticks;
[Sync]
[VerifySync]
int damageTicks;
public ChangesHealth(Actor self, ChangesHealthInfo info)

View File

@@ -117,7 +117,7 @@ namespace OpenRA.Mods.Common.Traits
readonly float3 cloakedColor;
readonly float cloakedColorAlpha;
[Sync]
[VerifySync]
int remainingTime;
bool isDocking;

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
public class GrantChargedConditionOnToggle : PausableConditionalTrait<GrantChargedConditionOnToggleInfo>,
IIssueOrder, IResolveOrder, ITick, ISelectionBar, IOrderVoice, ISync, IIssueDeployOrder
{
[Sync]
[VerifySync]
int chargeTick = 0;
bool isActive = false;

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
int token;
int delayedtoken;
[Sync]
[VerifySync]
public int Duration { get; private set; }
public GrantConditionOnClientDock(GrantConditionOnClientDockInfo info)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
int token;
int delayedtoken;
[Sync]
[VerifySync]
public int Duration { get; private set; }
public GrantConditionOnHostDock(GrantConditionOnHostDockInfo info)

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
int token = Actor.InvalidConditionToken;
[Sync]
[VerifySync]
int ticks;
public GrantConditionOnProduction(GrantConditionOnProductionInfo info)

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
int conditionToken = Actor.InvalidConditionToken;
// If the trait is paused this may be true with no condition granted
[Sync]
[VerifySync]
bool enabled = false;
public ToggleConditionOnOrder(ToggleConditionOnOrderInfo info)

View File

@@ -80,10 +80,10 @@ namespace OpenRA.Mods.Common.Traits
bool collected;
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
[Sync]
[VerifySync]
int ticks;
[Sync]
[VerifySync]
public CPos Location;
public Crate(ActorInitializer init, CrateInfo info)

View File

@@ -61,10 +61,10 @@ namespace OpenRA.Mods.Common.Traits
public WPos DockPosition => self.CenterPosition + Info.DockOffset;
[Sync]
[VerifySync]
bool preventDock = false;
[Sync]
[VerifySync]
protected Actor dockedClientActor = null;
protected DockClientManager dockedClient = null;

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
readonly ExperienceTricklerInfo info;
readonly GainsExperience gainsExperience;
[Sync]
[VerifySync]
int ticks;
public ExperienceTrickler(Actor self, ExperienceTricklerInfo info)

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
public class FireWarheads : PausableConditionalTrait<FireWarheadsInfo>, ITick, ISync
{
[Sync]
[VerifySync]
int cooldown = 0;
public FireWarheads(FireWarheadsInfo info)

View File

@@ -65,10 +65,10 @@ namespace OpenRA.Mods.Common.Traits
readonly List<(int RequiredExperience, string Condition)> nextLevel = [];
// Stored as a percentage of our value
[Sync]
[VerifySync]
public int Experience { get; private set; }
[Sync]
[VerifySync]
public int Level { get; private set; }
public readonly int MaxLevel;

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Traits
public override BitSet<DockType> GetDockType => Info.Type;
[Sync]
[VerifySync]
int currentUnloadTicks;
public Harvester(Actor self, HarvesterInfo info)

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits
DisplayHP = HP;
}
[Sync]
[VerifySync]
public int HP { get; private set; }
public int MaxHP { get; }

View File

@@ -78,13 +78,13 @@ namespace OpenRA.Mods.Common.Traits
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
[Sync]
[VerifySync]
public CPos TopLeft { get; private set; }
[Sync]
[VerifySync]
public WPos CenterPosition { get; private set; }
[Sync]
[VerifySync]
public WAngle Facing
{
get => Orientation.Yaw;

View File

@@ -43,9 +43,9 @@ namespace OpenRA.Mods.Common.Traits
occupied = [];
}
[Sync]
[VerifySync]
public CPos TopLeft { get; }
[Sync]
[VerifySync]
public WPos CenterPosition { get; }
public (CPos, SubCell)[] OccupiedCells() { return occupied; }

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
readonly Actor self;
readonly Func<CPos, bool> avoidTerrainFilter;
[Sync]
[VerifySync]
int panicStartedTick;
bool Panicking => panicStartedTick > 0;

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
{
readonly TakeCoverInfo info;
[Sync]
[VerifySync]
int remainingDuration = 0;
bool isProne = false;

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
readonly Actor self;
[Sync]
[VerifySync]
CPos minefieldStart;
public Minelayer(Actor self, MinelayerInfo info)

View File

@@ -223,7 +223,7 @@ namespace OpenRA.Mods.Common.Traits
#region IFacing
[Sync]
[VerifySync]
public WAngle Facing
{
get => orientation.Yaw;
@@ -236,10 +236,10 @@ namespace OpenRA.Mods.Common.Traits
#endregion
[Sync]
[VerifySync]
public CPos FromCell { get; private set; }
[Sync]
[VerifySync]
public CPos ToCell { get; private set; }
public Locomotor Locomotor { get; private set; }
@@ -248,7 +248,7 @@ namespace OpenRA.Mods.Common.Traits
#region IOccupySpace
[Sync]
[VerifySync]
public WPos CenterPosition { get; private set; }
public CPos TopLeft => ToCell;

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public class FrozenUnderFog : ICreatesFrozenActors, IRenderModifier, IDefaultVisibility,
ITickRender, ISync, INotifyCreated, INotifyOwnerChanged, INotifyActorDisposing
{
[Sync]
[VerifySync]
public int VisibilityHash;
readonly FrozenUnderFogInfo info;

View File

@@ -39,13 +39,13 @@ namespace OpenRA.Mods.Common.Traits
public event Action<Actor> OnEnteredDropRange = self => { };
public event Action<Actor> OnExitedDropRange = self => { };
[Sync]
[VerifySync]
bool inDropRange;
[Sync]
[VerifySync]
Target target;
[Sync]
[VerifySync]
int dropDelay;
bool checkForSuitableCell;

View File

@@ -82,25 +82,25 @@ namespace OpenRA.Mods.Common.Traits
readonly DeveloperModeInfo info;
public bool Enabled { get; private set; }
[Sync]
[VerifySync]
bool fastCharge;
[Sync]
[VerifySync]
bool allTech;
[Sync]
[VerifySync]
bool fastBuild;
[Sync]
[VerifySync]
bool disableShroud;
[Sync]
[VerifySync]
bool pathDebug;
[Sync]
[VerifySync]
bool unlimitedPower;
[Sync]
[VerifySync]
bool buildAnywhere;
public bool FastCharge => Enabled && fastCharge;

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
Player[] enemies;
Player[] allies;
[Sync]
[VerifySync]
public int ObjectivesHash
{
get

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
public class PlayerExperience : ISync
{
[Sync]
[VerifySync]
public int Experience { get; private set; }
public void GiveExperience(int num)

View File

@@ -95,13 +95,13 @@ namespace OpenRA.Mods.Common.Traits
lastNotificationTime = -Info.InsufficientFundsNotificationInterval;
}
[Sync]
[VerifySync]
public int Cash;
[Sync]
[VerifySync]
public int Resources;
[Sync]
[VerifySync]
public int ResourceCapacity;
public int Earned;

View File

@@ -153,12 +153,12 @@ namespace OpenRA.Mods.Common.Traits
public Actor Actor { get; }
[Sync]
[VerifySync]
public bool Enabled { get; protected set; }
public string Faction { get; private set; }
[Sync]
[VerifySync]
public bool IsValidFaction { get; private set; }
public ProductionQueue(ActorInitializer init, ProductionQueueInfo info)

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
readonly StrategicVictoryConditionsInfo info;
[Sync]
[VerifySync]
public int TicksLeft;
readonly Player player;

View File

@@ -41,10 +41,10 @@ namespace OpenRA.Mods.Common.Traits
readonly Dictionary<Actor, int> powerDrain = [];
[Sync]
[VerifySync]
public int PowerProvided { get; private set; }
[Sync]
[VerifySync]
public int PowerDrained { get; private set; }
public int ExcessPower => PowerProvided - PowerDrained;

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
AmmoPool ammoPool;
IReloadAmmoModifier[] modifiers;
[Sync]
[VerifySync]
int remainingTicks;
public ReloadAmmoPool(ReloadAmmoPoolInfo info)

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits.Render
int ticks;
[Sync]
[VerifySync]
public WVec WorldVisualOffset { get; private set; }
public Hovers(HoversInfo info)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
readonly Dictionary<string, int> contents = [];
readonly StoresResourcesInfo info;
[Sync]
[VerifySync]
public int ContentHash
{
get

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
Player originalOwner;
Player changingOwner;
[Sync]
[VerifySync]
int remaining = -1;
int duration;

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Traits
BodyOrientation body;
int quantizedFacings;
[Sync]
[VerifySync]
public int QuantizedFacings
{
get => quantizedFacings;

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.D2k.Projectiles
readonly WDist speed;
readonly SonicBlastRenderer renderer;
[Sync]
[VerifySync]
WPos pos, lastPos;
readonly WPos target;
int length;