Make ITick require explicit implementation

This commit is contained in:
reaperrr
2017-09-07 19:27:53 +02:00
committed by Matthias Mailänder
parent 85e60ef77f
commit 28e1f391e0
44 changed files with 69 additions and 43 deletions

View File

@@ -92,6 +92,7 @@ namespace OpenRA.Traits
} }
} }
[RequireExplicitImplementation]
public interface ITick { void Tick(Actor self); } public interface ITick { void Tick(Actor self); }
public interface ITickRender { void TickRender(WorldRenderer wr, Actor self); } public interface ITickRender { void TickRender(WorldRenderer wr, Actor self); }
public interface IRender { IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr); } public interface IRender { IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr); }

View File

@@ -583,7 +583,7 @@ namespace OpenRA.Mods.Common.AI
return null; return null;
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (!IsEnabled) if (!IsEnabled)
return; return;

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Scripting
context.WorldLoaded(); context.WorldLoaded();
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
context.Tick(self); context.Tick(self);
} }

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { } void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (!Info.SelfReloads) if (!Info.SelfReloads)
return; return;

View File

@@ -29,7 +29,12 @@ namespace OpenRA.Mods.Common.Traits
public AttackFollow(Actor self, AttackFollowInfo info) public AttackFollow(Actor self, AttackFollowInfo info)
: base(self, info) { } : base(self, info) { }
public virtual void Tick(Actor self) void ITick.Tick(Actor self)
{
Tick(self);
}
protected virtual void Tick(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
{ {

View File

@@ -199,7 +199,7 @@ namespace OpenRA.Mods.Common.Traits
yield return r; yield return r;
} }
public override void Tick(Actor self) protected override void Tick(Actor self)
{ {
base.Tick(self); base.Tick(self);

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
int remainingTicks; int remainingTicks;
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
{ {

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
self.Trait<RenderSprites>().Add(anim); self.Trait<RenderSprites>().Add(anim);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (--ticks <= 0) if (--ticks <= 0)
{ {

View File

@@ -45,7 +45,12 @@ namespace OpenRA.Mods.Common.Traits
Tick(self); Tick(self);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{
Tick(self);
}
protected void Tick(Actor self)
{ {
if (conditionManager == null) if (conditionManager == null)
return; return;

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
conditionManager = self.TraitOrDefault<ConditionManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (conditionManager == null) if (conditionManager == null)
return; return;

View File

@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Traits
desiredVRange = WDist.Zero; desiredVRange = WDist.Zero;
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (self.CenterPosition != cachedPosition || desiredRange != cachedRange || desiredVRange != cachedVRange) if (self.CenterPosition != cachedPosition || desiredRange != cachedRange || desiredVRange != cachedVRange)
{ {

View File

@@ -153,7 +153,7 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (info.Lifetime != 0 && self.IsInWorld && ++ticks >= info.Lifetime * 25) if (info.Lifetime != 0 && self.IsInWorld && ++ticks >= info.Lifetime * 25)
self.Dispose(); self.Dispose();

View File

@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits
self.InflictDamage(self.World.WorldActor, new Damage(delta, Info.DamageTypes)); self.InflictDamage(self.World.WorldActor, new Damage(delta, Info.DamageTypes));
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (IsTraitDisabled || health.HP <= damageThreshold || --damageTicks > 0) if (IsTraitDisabled || health.HP <= damageThreshold || --damageTicks > 0)
return; return;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
Captor = null; Captor = null;
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (Captor != null && (!Captor.IsInWorld || Captor.IsDead)) if (Captor != null && (!Captor.IsInWorld || Captor.IsDead))
EndCapture(); EndCapture();

View File

@@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Traits
InflictDamage(self, attacker, new Damage(MaxHP), true); InflictDamage(self, attacker, new Damage(MaxHP), true);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (hp > DisplayHP) if (hp > DisplayHP)
DisplayHP = hp; DisplayHP = hp;

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
remainingProneTime = info.ProneTime; remainingProneTime = info.ProneTime;
} }
public override void Tick(Actor self) protected override void Tick(Actor self)
{ {
base.Tick(self); base.Tick(self);

View File

@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Traits
return info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer); return info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (self.Disposed) if (self.Disposed)
return; return;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
t += 0.25f; t += 0.25f;
if (t >= 256) t = 0; if (t >= 256) t = 0;

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits
remainingFrames = ticks; remainingFrames = ticks;
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (remainingFrames > 0) if (remainingFrames > 0)
remainingFrames--; remainingFrames--;

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits
return info.Tilesets.Contains(tilesetId) && !info.ExcludeTilesets.Contains(tilesetId); return info.Tilesets.Contains(tilesetId) && !info.ExcludeTilesets.Contains(tilesetId);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (!validTileset) if (!validTileset)
return; return;

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
checkForSuitableCell = checkLandingCell; checkForSuitableCell = checkLandingCell;
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
var wasInDropRange = inDropRange; var wasInDropRange = inDropRange;
inDropRange = target.IsInRange(self.CenterPosition, info.DropRange); inDropRange = target.IsInRange(self.CenterPosition, info.DropRange);

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
[Sync] bool isActive = false; [Sync] bool isActive = false;
public override void Tick(Actor self) protected override void Tick(Actor self)
{ {
// PERF: Avoid LINQ. // PERF: Avoid LINQ.
isActive = false; isActive = false;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
mo = self.Trait<MissionObjectives>(); mo = self.Trait<MissionObjectives>();
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (self.Owner.WinState != WinState.Undefined || self.Owner.NonCombatant) return; if (self.Owner.WinState != WinState.Undefined || self.Owner.NonCombatant) return;

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
} }
// Here self is the player actor // Here self is the player actor
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
// TODO: Make the AI handle such notifications and remove Owner.IsBot from this check // TODO: Make the AI handle such notifications and remove Owner.IsBot from this check
// Disable notifications for AI and neutral players (creeps) and for spectators // Disable notifications for AI and neutral players (creeps) and for spectators

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
EarnedSamples.Dequeue(); EarnedSamples.Dequeue();
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (self.World.WorldTick % 1500 == 1) if (self.World.WorldTick % 1500 == 1)
UpdateEarnedThisMinute(); UpdateEarnedThisMinute();

View File

@@ -229,7 +229,12 @@ namespace OpenRA.Mods.Common.Traits
return ps.Buildable || developerMode.AllTech; return ps.Buildable || developerMode.AllTech;
} }
public virtual void Tick(Actor self) void ITick.Tick(Actor self)
{
Tick(self);
}
protected virtual void Tick(Actor self)
{ {
while (queue.Count > 0 && BuildableItems().All(b => b.Name != queue[0].Item)) while (queue.Count > 0 && BuildableItems().All(b => b.Name != queue[0].Item))
{ {

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
resources = self.Trait<PlayerResources>(); resources = self.Trait<PlayerResources>();
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (--nextSiloAdviceTime <= 0) if (--nextSiloAdviceTime <= 0)
{ {

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
public bool Holding { get { return Owned >= info.RatioRequired * Total / 100; } } public bool Holding { get { return Owned >= info.RatioRequired * Total / 100; } }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (player.WinState != WinState.Undefined || player.NonCombatant) return; if (player.WinState != WinState.Undefined || player.NonCombatant) return;

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
bool wasLowPower = false; bool wasLowPower = false;
bool wasHackEnabled; bool wasHackEnabled;
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (wasHackEnabled != devMode.UnlimitedPower) if (wasHackEnabled != devMode.UnlimitedPower)
{ {

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
actorsInRange.Clear(); actorsInRange.Clear();
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (!self.IsInWorld || self.CenterPosition == prevPosition) if (!self.IsInWorld || self.CenterPosition == prevPosition)
return; return;

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits.Render
bool wasStationary; bool wasStationary;
bool isMoving; bool isMoving;
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
return; return;

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits.Render
FindQueue(); FindQueue();
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
var current = queue.CurrentItem(); var current = queue.CurrentItem();
value = current != null ? 1 - (float)current.RemainingCost / current.TotalCost : 0; value = current != null ? 1 - (float)current.RemainingCost / current.TotalCost : 0;

View File

@@ -181,7 +181,12 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public virtual void Tick(Actor self) void ITick.Tick(Actor self)
{
Tick(self);
}
protected virtual void Tick(Actor self)
{ {
foreach (var a in anims) foreach (var a in anims)
a.Animation.Animation.Tick(); a.Animation.Animation.Tick();

View File

@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
foreach (var a in anims.Values) foreach (var a in anims.Values)
a.Animation.Tick(); a.Animation.Tick();

View File

@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Traits.Render
anim.Animation.PlayBackwardsThen(info.OpeningSequence, () => renderProlonged = false); anim.Animation.PlayBackwardsThen(info.OpeningSequence, () => renderProlonged = false);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (shadow != null) if (shadow != null)
shadow.Tick(); shadow.Tick();

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
int ticks; int ticks;
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
return; return;

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
health = self.Trait<Health>(); health = self.Trait<Health>();
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (self.IsDead || IsTraitDisabled) if (self.IsDead || IsTraitDisabled)
return; return;

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
getFacing = 0; getFacing = 0;
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (--ticks <= 0) if (--ticks <= 0)
{ {

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
foreach (var power in Powers.Values) foreach (var power in Powers.Values)
power.Tick(); power.Tick();

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits
rs.Add(new AnimationWithOffset(anim, () => pos, null)); rs.Add(new AnimationWithOffset(anim, () => pos, null));
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (tick >= length) if (tick >= length)
return; return;

View File

@@ -105,7 +105,12 @@ namespace OpenRA.Mods.Common.Traits
body = self.Trait<BodyOrientation>(); body = self.Trait<BodyOrientation>();
} }
public virtual void Tick(Actor self) void ITick.Tick(Actor self)
{
Tick(self);
}
protected virtual void Tick(Actor self)
{ {
// NOTE: FaceTarget is called in AttackTurreted.CanAttack if the turret has a target. // NOTE: FaceTarget is called in AttackTurreted.CanAttack if the turret has a target.
if (attack != null) if (attack != null)

View File

@@ -392,7 +392,7 @@ namespace OpenRA.Mods.Common.Traits
RemoveInfluenceInner(ref influenceNode.Next, toRemove); RemoveInfluenceInner(ref influenceNode.Next, toRemove);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
// Position updates are done in one pass // Position updates are done in one pass
// to ensure consistency during a tick // to ensure consistency during a tick

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits
.OptionOrDefault("crates", info.Enabled); .OptionOrDefault("crates", info.Enabled);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (!enabled) if (!enabled)
return; return;

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info; this.info = info;
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
foreach (var ping in Pings.ToArray()) foreach (var ping in Pings.ToArray())
if (!ping.Tick()) if (!ping.Tick())