Change animations to use the proper SequenceProvider

Remove references to the global "Game" and use the SequenceProvider
of the current world/map.
This commit is contained in:
Pavlos Touboulidis
2014-05-11 03:05:47 +03:00
parent 6eabc6adf5
commit b560268495
52 changed files with 132 additions and 117 deletions

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Effects
public MoveFlash(WPos pos, World world) public MoveFlash(WPos pos, World world)
{ {
this.pos = pos; this.pos = pos;
anim = new Animation("moveflsh"); anim = new Animation(world, "moveflsh");
anim.PlayThen("idle", () => world.AddFrameEndTask(w => w.Remove(this))); anim.PlayThen("idle", () => world.AddFrameEndTask(w => w.Remove(this)));
} }

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Graphics
public bool IsDecoration = false; public bool IsDecoration = false;
public Func<bool> Paused; public Func<bool> Paused;
Func<int> facingFunc; readonly Func<int> facingFunc;
int frame = 0; int frame = 0;
bool backwards = false; bool backwards = false;
@@ -29,27 +29,19 @@ namespace OpenRA.Graphics
public string Name { get { return name; } } public string Name { get { return name; } }
readonly SequenceProvider sequenceProvider; readonly SequenceProvider sequenceProvider;
static SequenceProvider lastSequenceProvider;
public Animation(string name) public Animation(World world, string name)
: this(name, () => 0) {} : this(world, name, () => 0) { }
public Animation(string name, Func<int> facingFunc) public Animation(World world, string name, Func<int> facingFunc)
: this(world.Map.SequenceProvider, name, facingFunc) { }
public Animation(SequenceProvider sequenceProvider, string name, Func<int> facingFunc)
{ {
this.sequenceProvider = sequenceProvider;
this.name = name.ToLowerInvariant(); this.name = name.ToLowerInvariant();
this.tickFunc = () => {}; this.tickFunc = () => {};
this.facingFunc = facingFunc; this.facingFunc = facingFunc;
// TODO: This is wrong, don't use the static
if (Game.orderManager != null && Game.orderManager.world != null && Game.orderManager.world.Map != null)
sequenceProvider = Game.orderManager.world.Map.SequenceProvider;
// HACK: This just makes sure we have a sequence provider in between map changes for delayed actions
// It sucks but it can only be removed when we don't use the statics above but replace them with
// a possible parameter on this constructor.
if (sequenceProvider == null)
sequenceProvider = lastSequenceProvider;
else
lastSequenceProvider = sequenceProvider;
} }
int CurrentFrame { get { return backwards ? CurrentSequence.Start + CurrentSequence.Length - frame - 1 : frame; } } int CurrentFrame { get { return backwards ? CurrentSequence.Start + CurrentSequence.Length - frame - 1 : frame; } }

View File

@@ -19,9 +19,9 @@ namespace OpenRA.Traits
{ {
public override object Create(ActorInitializer init) { return new RenderSimple(init.self); } public override object Create(ActorInitializer init) { return new RenderSimple(init.self); }
public virtual IEnumerable<IRenderable> RenderPreview(ActorInfo ai, PaletteReference pr) public virtual IEnumerable<IRenderable> RenderPreview(World world, ActorInfo ai, PaletteReference pr)
{ {
var anim = new Animation(RenderSimple.GetImage(ai), () => 0); var anim = new Animation(world, RenderSimple.GetImage(ai), () => 0);
anim.PlayRepeating("idle"); anim.PlayRepeating("idle");
return anim.Render(WPos.Zero, WVec.Zero, 0, pr, Scale); return anim.Render(WPos.Zero, WVec.Zero, 0, pr, Scale);
@@ -35,7 +35,7 @@ namespace OpenRA.Traits
public RenderSimple(Actor self, Func<int> baseFacing) public RenderSimple(Actor self, Func<int> baseFacing)
: base(self) : base(self)
{ {
anims.Add("", new Animation(GetImage(self), baseFacing)); anims.Add("", new Animation(self.World, GetImage(self), baseFacing));
Info = self.Info.Traits.Get<RenderSimpleInfo>(); Info = self.Info.Traits.Get<RenderSimpleInfo>();
} }

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Traits
var group = self.World.Selection.GetControlGroupForActor(self); var group = self.World.Selection.GetControlGroupForActor(self);
if (group == null) return; if (group == null) return;
var pipImages = new Animation("pips"); var pipImages = new Animation(self.World, "pips");
var pal = wr.Palette(Info.Palette); var pal = wr.Palette(Info.Palette);
pipImages.PlayFetchIndex("groups", () => (int)group); pipImages.PlayFetchIndex("groups", () => (int)group);
pipImages.Tick(); pipImages.Tick();
@@ -75,7 +75,7 @@ namespace OpenRA.Traits
if (!pipSources.Any()) if (!pipSources.Any())
return; return;
var pipImages = new Animation("pips"); var pipImages = new Animation(self.World, "pips");
pipImages.PlayRepeating(pipStrings[0]); pipImages.PlayRepeating(pipStrings[0]);
var pipSize = pipImages.Image.size.ToInt2(); var pipSize = pipImages.Image.size.ToInt2();
@@ -115,7 +115,7 @@ namespace OpenRA.Traits
if (!self.Owner.IsAlliedWith(self.World.RenderPlayer)) if (!self.Owner.IsAlliedWith(self.World.RenderPlayer))
return; return;
var tagImages = new Animation("pips"); var tagImages = new Animation(self.World, "pips");
var pal = wr.Palette(Info.Palette); var pal = wr.Palette(Info.Palette);
var tagxyOffset = new int2(0, 6); var tagxyOffset = new int2(0, 6);
var tagBase = wr.Viewport.WorldToViewPx(basePosition); var tagBase = wr.Viewport.WorldToViewPx(basePosition);

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Widgets
if (Unit != null && Sequence != null) if (Unit != null && Sequence != null)
{ {
var anim = new Animation(Unit, () => Facing); var anim = new Animation(worldRenderer.world, Unit, () => Facing);
anim.PlayFetchIndex(Sequence, () => Frame); anim.PlayFetchIndex(Sequence, () => Frame);
GetAnimation = () => anim; GetAnimation = () => anim;
} }

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Widgets
public Func<string> GetPalette; public Func<string> GetPalette;
public Func<Sprite> GetSprite; public Func<Sprite> GetSprite;
readonly WorldRenderer worldRenderer; protected readonly WorldRenderer worldRenderer;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public SpriteWidget(WorldRenderer worldRenderer) public SpriteWidget(WorldRenderer worldRenderer)

View File

@@ -18,11 +18,11 @@ namespace OpenRA.Mods.Cnc.Effects
{ {
public class IonCannon : IEffect public class IonCannon : IEffect
{ {
Target target; readonly Target target;
Animation anim; readonly Animation anim;
Player firedBy; readonly Player firedBy;
string palette; readonly string palette;
string weapon; readonly string weapon;
public IonCannon(Player firedBy, string weapon, World world, CPos location, string effect, string palette) public IonCannon(Player firedBy, string weapon, World world, CPos location, string effect, string palette)
{ {
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Cnc.Effects
this.weapon = weapon; this.weapon = weapon;
this.palette = palette; this.palette = palette;
target = Target.FromCell(location); target = Target.FromCell(location);
anim = new Animation(effect); anim = new Animation(world, effect);
anim.PlayThen("idle", () => Finish(world)); anim.PlayThen("idle", () => Finish(world));
} }

View File

@@ -35,19 +35,19 @@ namespace OpenRA.Mods.RA.Render
var turret = self.TraitsImplementing<Turreted>() var turret = self.TraitsImplementing<Turreted>()
.First(t => t.Name == info.Turret); .First(t => t.Name == info.Turret);
left = new Animation(name, () => turret.turretFacing); left = new Animation(self.World, name, () => turret.turretFacing);
left.Play("left"); left.Play("left");
anims.Add("left", new AnimationWithOffset(left, null, () => facing.Facing > 128, 0)); anims.Add("left", new AnimationWithOffset(left, null, () => facing.Facing > 128, 0));
right = new Animation(name, () => turret.turretFacing); right = new Animation(self.World, name, () => turret.turretFacing);
right.Play("right"); right.Play("right");
anims.Add("right", new AnimationWithOffset(right, null, () => facing.Facing <= 128, 0)); anims.Add("right", new AnimationWithOffset(right, null, () => facing.Facing <= 128, 0));
var leftWake = new Animation(name); var leftWake = new Animation(self.World, name);
leftWake.Play("wake-left"); leftWake.Play("wake-left");
anims.Add("wake-left", new AnimationWithOffset(leftWake, null, () => facing.Facing > 128, -87)); anims.Add("wake-left", new AnimationWithOffset(leftWake, null, () => facing.Facing > 128, -87));
var rightWake = new Animation(name); var rightWake = new Animation(self.World, name);
rightWake.Play("wake-right"); rightWake.Play("wake-right");
anims.Add("wake-right", new AnimationWithOffset(rightWake, null, () => facing.Facing <= 128, -87)); anims.Add("wake-right", new AnimationWithOffset(rightWake, null, () => facing.Facing <= 128, -87));

View File

@@ -72,9 +72,9 @@ namespace OpenRA.Mods.Cnc.Widgets
tooltipContainer = Exts.Lazy(() => tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer)); Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
cantBuild = new Animation("clock"); cantBuild = new Animation(world, "clock");
cantBuild.PlayFetchIndex("idle", () => 0); cantBuild.PlayFetchIndex("idle", () => 0);
clock = new Animation("clock"); clock = new Animation(world, "clock");
} }
public override void Tick() public override void Tick()
@@ -183,7 +183,7 @@ namespace OpenRA.Mods.Cnc.Widgets
var x = i % Columns; var x = i % Columns;
var y = i / Columns; var y = i / Columns;
var rect = new Rectangle(rb.X + x * 64 + 1, rb.Y + y * 48 + 1, 64, 48); var rect = new Rectangle(rb.X + x * 64 + 1, rb.Y + y * 48 + 1, 64, 48);
var icon = new Animation(RenderSimple.GetImage(item)); var icon = new Animation(World, RenderSimple.GetImage(item));
icon.Play(item.Traits.Get<TooltipInfo>().Icon); icon.Play(item.Traits.Get<TooltipInfo>().Icon);
var pi = new ProductionIcon() var pi = new ProductionIcon()
{ {

View File

@@ -52,8 +52,8 @@ namespace OpenRA.Mods.Cnc.Widgets
tooltipContainer = Exts.Lazy(() => tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer)); Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
icon = new Animation("icon"); icon = new Animation(world, "icon");
clock = new Animation("clock"); clock = new Animation(world, "clock");
} }
public class SupportPowerIcon public class SupportPowerIcon

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Cnc
public WithFire(Actor self, WithFireInfo info) public WithFire(Actor self, WithFireInfo info)
{ {
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var roof = new Animation(rs.GetImage(self)); var roof = new Animation(self.World, rs.GetImage(self));
roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop")); roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop"));
rs.anims.Add("fire", new AnimationWithOffset(roof, null, null, 1024)); rs.anims.Add("fire", new AnimationWithOffset(roof, null, null, 1024));
} }

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Cnc
public WithRoof(Actor self) public WithRoof(Actor self)
{ {
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var roof = new Animation(rs.GetImage(self), () => self.Trait<IFacing>().Facing); var roof = new Animation(self.World, rs.GetImage(self), () => self.Trait<IFacing>().Facing);
roof.Play("roof"); roof.Play("roof");
rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024)); rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024));
} }

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Render
buildComplete = !self.HasTrait<Building>(); // always render instantly for units buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(rs.GetImage(self)); overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence); overlay.Play(info.Sequence);
rs.anims.Add("crane_overlay_{0}".F(info.Sequence), rs.anims.Add("crane_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, new AnimationWithOffset(overlay,

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render
if (!init.Contains<SkipMakeAnimsInit>()) if (!init.Contains<SkipMakeAnimsInit>())
{ {
var overlay = new Animation(rs.GetImage(init.self)); var overlay = new Animation(init.world, rs.GetImage(init.self));
overlay.PlayThen(info.Sequence, () => buildComplete = false); overlay.PlayThen(info.Sequence, () => buildComplete = false);
rs.anims.Add("make_overlay_{0}".F(info.Sequence), rs.anims.Add("make_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, null, () => !buildComplete)); new AnimationWithOffset(overlay, null, () => !buildComplete));

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Render
buildComplete = !self.HasTrait<Building>(); // always render instantly for units buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(rs.GetImage(self)); overlay = new Animation(self.World, rs.GetImage(self));
overlay.PlayRepeating(info.Sequence); overlay.PlayRepeating(info.Sequence);
rs.anims.Add("production_overlay_{0}".F(info.Sequence), rs.anims.Add("production_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, new AnimationWithOffset(overlay,

View File

@@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA
if (barrel != null && a.Info.MuzzleSequence != null) if (barrel != null && a.Info.MuzzleSequence != null)
{ {
// Muzzle facing is fixed once the firing starts // Muzzle facing is fixed once the firing starts
var muzzleAnim = new Animation(paxRender[a.Actor].GetImage(a.Actor), () => muzzleFacing); var muzzleAnim = new Animation(self.World, paxRender[a.Actor].GetImage(a.Actor), () => muzzleFacing);
var sequence = a.Info.MuzzleSequence; var sequence = a.Info.MuzzleSequence;
if (a.Info.MuzzleSplitFacings > 0) if (a.Info.MuzzleSplitFacings > 0)

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Buildings
for (var i = 0; i < rows * width; i++) for (var i = 0; i < rows * width; i++)
{ {
var index = i; var index = i;
var anim = new Animation(rs.GetImage(self)); var anim = new Animation(self.World, rs.GetImage(self));
var cellOffset = new CVec(i % width, i / width + bibOffset); var cellOffset = new CVec(i % width, i / width + bibOffset);
// Some mods may define terrain-specific bibs // Some mods may define terrain-specific bibs

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
{ {
Info = info; Info = info;
var anim = new Animation("fire", () => 0); var anim = new Animation(self.World, "fire", () => 0);
anim.IsDecoration = true; anim.IsDecoration = true;
anim.PlayRepeating(Info.Anim); anim.PlayRepeating(Info.Anim);
self.Trait<RenderSprites>().anims.Add("fire", anim); self.Trait<RenderSprites>().anims.Add("fire", anim);

View File

@@ -21,8 +21,8 @@ namespace OpenRA.Mods.RA.Effects
readonly WPos position; readonly WPos position;
readonly string palettePrefix; readonly string palettePrefix;
readonly string posterPalette; readonly string posterPalette;
readonly Animation arrow = new Animation("beacon"); readonly Animation arrow;
readonly Animation circles = new Animation("beacon"); readonly Animation circles;
readonly Animation poster; readonly Animation poster;
static readonly int maxArrowHeight = 512; static readonly int maxArrowHeight = 512;
int arrowHeight = maxArrowHeight; int arrowHeight = maxArrowHeight;
@@ -35,12 +35,15 @@ namespace OpenRA.Mods.RA.Effects
this.palettePrefix = palettePrefix; this.palettePrefix = palettePrefix;
this.posterPalette = posterPalette; this.posterPalette = posterPalette;
arrow = new Animation(owner.World, "beacon");
circles = new Animation(owner.World, "beacon");
arrow.Play("arrow"); arrow.Play("arrow");
circles.Play("circles"); circles.Play("circles");
if (posterType != null) if (posterType != null)
{ {
poster = new Animation("beacon"); poster = new Animation(owner.World, "beacon");
poster.Play(posterType); poster.Play(posterType);
} }

View File

@@ -66,6 +66,8 @@ namespace OpenRA.Mods.RA.Effects
this.args = args; this.args = args;
this.pos = args.Source; this.pos = args.Source;
var world = args.SourceActor.World;
if (info.Angle.Length > 1 && info.Speed.Length > 1) if (info.Angle.Length > 1 && info.Speed.Length > 1)
{ {
angle = new WAngle(args.SourceActor.World.SharedRandom.Next(info.Angle[0].Angle, info.Angle[1].Angle)); angle = new WAngle(args.SourceActor.World.SharedRandom.Next(info.Angle[0].Angle, info.Angle[1].Angle));
@@ -89,7 +91,7 @@ namespace OpenRA.Mods.RA.Effects
if (info.Image != null) if (info.Image != null)
{ {
anim = new Animation(info.Image, GetEffectiveFacing); anim = new Animation(world, info.Image, GetEffectiveFacing);
anim.PlayRepeating("idle"); anim.PlayRepeating("idle");
} }

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Effects
this.pos = pos; this.pos = pos;
this.cell = pos.ToCPos(); this.cell = pos.ToCPos();
this.paletteName = paletteName; this.paletteName = paletteName;
anim = new Animation(image); anim = new Animation(world, image);
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this)));
} }

View File

@@ -17,13 +17,15 @@ namespace OpenRA.Mods.RA.Effects
class CrateEffect : IEffect class CrateEffect : IEffect
{ {
readonly string palette; readonly string palette;
Actor a; readonly Actor a;
Animation anim = new Animation("crate-effects"); readonly Animation anim;
public CrateEffect(Actor a, string seq, string palette) public CrateEffect(Actor a, string seq, string palette)
{ {
this.a = a; this.a = a;
this.palette = palette; this.palette = palette;
anim = new Animation(a.World, "crate-effects");
anim.PlayThen(seq, () => a.World.AddFrameEndTask(w => w.Remove(this))); anim.PlayThen(seq, () => a.World.AddFrameEndTask(w => w.Remove(this)));
} }

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Effects
this.pos = pos; this.pos = pos;
this.cell = pos.ToCPos(); this.cell = pos.ToCPos();
this.palette = palette; this.palette = palette;
anim = new Animation("explosion"); anim = new Animation(world, "explosion");
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this)));
} }

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Effects
{ {
this.self = self; this.self = self;
this.info = info; this.info = info;
anim = new Animation("gpsdot"); anim = new Animation(self.World, "gpsdot");
anim.PlayRepeating(info.String); anim.PlayRepeating(info.String);
self.World.AddFrameEndTask(w => w.Add(this)); self.World.AddFrameEndTask(w => w.Add(this));

View File

@@ -16,27 +16,29 @@ namespace OpenRA.Mods.RA.Effects
{ {
class GpsSatellite : IEffect class GpsSatellite : IEffect
{ {
WPos Pos; WPos pos;
Animation Anim = new Animation("sputnik"); readonly Animation anim;
public GpsSatellite(WPos pos) public GpsSatellite(World world, WPos pos)
{ {
Pos = pos; this.pos = pos;
Anim.PlayRepeating("idle");
anim = new Animation(world, "sputnik");
anim.PlayRepeating("idle");
} }
public void Tick( World world ) public void Tick( World world )
{ {
Anim.Tick(); anim.Tick();
Pos += new WVec(0, 0, 427); pos += new WVec(0, 0, 427);
if (Pos.Z > Pos.Y) if (pos.Z > pos.Y)
world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
} }
public IEnumerable<IRenderable> Render(WorldRenderer wr) public IEnumerable<IRenderable> Render(WorldRenderer wr)
{ {
return Anim.Render(Pos, wr.Palette("effect")); return anim.Render(pos, wr.Palette("effect"));
} }
} }
} }

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Effects
pos = args.Source; pos = args.Source;
velocity = new WVec(WRange.Zero, WRange.Zero, -info.Velocity); velocity = new WVec(WRange.Zero, WRange.Zero, -info.Velocity);
anim = new Animation(info.Image); anim = new Animation(args.SourceActor.World, info.Image);
if (anim.HasSequence("open")) if (anim.HasSequence("open"))
anim.PlayThen("open", () => anim.PlayRepeating("idle")); anim.PlayThen("open", () => anim.PlayRepeating("idle"));
else else

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Effects
this.target = args.PassiveTarget; this.target = args.PassiveTarget;
if (info.HitAnim != null) if (info.HitAnim != null)
this.hitanim = new Animation(info.HitAnim); this.hitanim = new Animation(args.SourceActor.World, info.HitAnim);
} }
public void Tick(World world) public void Tick(World world)

View File

@@ -88,7 +88,7 @@ namespace OpenRA.Mods.RA.Effects
if (info.Image != null) if (info.Image != null)
{ {
anim = new Animation(info.Image, () => facing); anim = new Animation(args.SourceActor.World, info.Image, () => facing);
anim.PlayRepeating("idle"); anim.PlayRepeating("idle");
} }

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Effects
descendSource = targetPos + offset; descendSource = targetPos + offset;
descendTarget = targetPos; descendTarget = targetPos;
anim = new Animation(weapon); anim = new Animation(firedBy.World, weapon);
anim.PlayRepeating("up"); anim.PlayRepeating("up");
pos = launchPos; pos = launchPos;

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Effects
this.cargo = cargo; this.cargo = cargo;
var pai = cargo.Info.Traits.GetOrDefault<ParachuteAttachmentInfo>(); var pai = cargo.Info.Traits.GetOrDefault<ParachuteAttachmentInfo>();
paraAnim = new Animation(pai != null ? pai.ParachuteSprite : "parach"); paraAnim = new Animation(cargo.World, pai != null ? pai.ParachuteSprite : "parach");
paraAnim.PlayThen("open", () => paraAnim.PlayRepeating("idle")); paraAnim.PlayThen("open", () => paraAnim.PlayRepeating("idle"));
if (pai != null) if (pai != null)

View File

@@ -18,12 +18,15 @@ namespace OpenRA.Mods.RA.Effects
{ {
class PowerdownIndicator : IEffect class PowerdownIndicator : IEffect
{ {
Actor a; readonly Actor a;
Animation anim = new Animation("poweroff"); readonly Animation anim;
public PowerdownIndicator(Actor a) public PowerdownIndicator(Actor a)
{ {
this.a = a; anim.PlayRepeating("offline"); this.a = a;
anim = new Animation(a.World, "poweroff");
anim.PlayRepeating("offline");
} }
public void Tick(World world) public void Tick(World world)

View File

@@ -21,14 +21,19 @@ namespace OpenRA.Mods.RA.Effects
readonly Actor building; readonly Actor building;
readonly RA.RallyPoint rp; readonly RA.RallyPoint rp;
readonly string palettePrefix; readonly string palettePrefix;
public Animation flag = new Animation("rallypoint"); readonly Animation flag;
public Animation circles = new Animation("rallypoint"); readonly Animation circles;
public RallyPoint(Actor building, string palettePrefix) public RallyPoint(Actor building, string palettePrefix)
{ {
this.building = building; this.building = building;
rp = building.Trait<RA.RallyPoint>();
this.palettePrefix = palettePrefix; this.palettePrefix = palettePrefix;
rp = building.Trait<RA.RallyPoint>();
flag = new Animation(building.World, "rallypoint");
circles = new Animation(building.World, "rallypoint");
flag.PlayRepeating("flag"); flag.PlayRepeating("flag");
circles.Play("circles"); circles.Play("circles");
} }

View File

@@ -17,16 +17,17 @@ namespace OpenRA.Mods.RA.Effects
{ {
class Rank : IEffect class Rank : IEffect
{ {
Actor self; readonly Actor self;
Animation anim = new Animation("rank"); readonly Animation anim;
readonly string paletteName; readonly string paletteName;
public Rank(Actor self, string paletteName) public Rank(Actor self, string paletteName)
{ {
this.self = self; this.self = self;
this.paletteName = paletteName; this.paletteName = paletteName;
var xp = self.Trait<GainsExperience>();
var xp = self.Trait<GainsExperience>();
anim = new Animation(self.World, "rank");
anim.PlayRepeating("rank"); anim.PlayRepeating("rank");
anim.PlayFetchIndex("rank", () => xp.Level == 0 ? 0 : xp.Level - 1); anim.PlayFetchIndex("rank", () => xp.Level == 0 ? 0 : xp.Level - 1);
} }

View File

@@ -18,18 +18,20 @@ namespace OpenRA.Mods.RA.Effects
{ {
class RepairIndicator : IEffect class RepairIndicator : IEffect
{ {
Actor building; readonly Actor building;
Player player; readonly Player player;
string palettePrefix; readonly string palettePrefix;
Animation anim = new Animation("allyrepair"); readonly Animation anim;
RepairableBuilding rb; readonly RepairableBuilding rb;
public RepairIndicator(Actor building, string palettePrefix, Player player) public RepairIndicator(Actor building, string palettePrefix, Player player)
{ {
this.building = building; this.building = building;
this.player = player; this.player = player;
this.palettePrefix = palettePrefix; this.palettePrefix = palettePrefix;
rb = building.Trait<RepairableBuilding>(); rb = building.Trait<RepairableBuilding>();
anim = new Animation(building.World, "allyrepair");
anim.PlayRepeating("repair"); anim.PlayRepeating("repair");
} }

View File

@@ -17,11 +17,13 @@ namespace OpenRA.Mods.RA.Effects
class SatelliteLaunch : IEffect class SatelliteLaunch : IEffect
{ {
int frame = 0; int frame = 0;
Animation doors = new Animation("atek"); readonly Animation doors;
WPos pos; readonly WPos pos;
public SatelliteLaunch(Actor a) public SatelliteLaunch(Actor a)
{ {
doors = new Animation(a.World, "atek");
doors.PlayThen("active", doors.PlayThen("active",
() => a.World.AddFrameEndTask(w => w.Remove(this))); () => a.World.AddFrameEndTask(w => w.Remove(this)));
@@ -33,7 +35,7 @@ namespace OpenRA.Mods.RA.Effects
doors.Tick(); doors.Tick();
if (++frame == 19) if (++frame == 19)
world.AddFrameEndTask(w => w.Add(new GpsSatellite(pos))); world.AddFrameEndTask(w => w.Add(new GpsSatellite(world, pos)));
} }
public IEnumerable<IRenderable> Render(WorldRenderer wr) public IEnumerable<IRenderable> Render(WorldRenderer wr)

View File

@@ -26,7 +26,8 @@ namespace OpenRA.Mods.RA.Effects
this.world = world; this.world = world;
this.pos = pos; this.pos = pos;
this.cell = pos.ToCPos(); this.cell = pos.ToCPos();
anim = new Animation(trail);
anim = new Animation(world, trail);
anim.PlayThen("idle", anim.PlayThen("idle",
() => world.AddFrameEndTask(w => w.Remove(this))); () => world.AddFrameEndTask(w => w.Remove(this)));
} }

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.RA.Orders
var palette = rbi.Palette ?? (Producer.Owner != null ? var palette = rbi.Palette ?? (Producer.Owner != null ?
rbi.PlayerPalette + Producer.Owner.InternalName : null); rbi.PlayerPalette + Producer.Owner.InternalName : null);
preview = rbi.RenderPreview(rules.Actors[Building], wr.Palette(palette)); preview = rbi.RenderPreview(world, rules.Actors[Building], wr.Palette(palette));
} }
initialized = true; initialized = true;

View File

@@ -21,15 +21,15 @@ namespace OpenRA.Mods.RA.Render
public override object Create(ActorInitializer init) { return new RenderBuildingWarFactory( init, this ); } public override object Create(ActorInitializer init) { return new RenderBuildingWarFactory( init, this ); }
/* get around unverifiability */ /* get around unverifiability */
IEnumerable<IRenderable> BaseBuildingPreview(ActorInfo building, PaletteReference pr) IEnumerable<IRenderable> BaseBuildingPreview(World world, ActorInfo building, PaletteReference pr)
{ {
return base.RenderPreview(building, pr); return base.RenderPreview(world, building, pr);
} }
public override IEnumerable<IRenderable> RenderPreview(ActorInfo building, PaletteReference pr) public override IEnumerable<IRenderable> RenderPreview(World world, ActorInfo building, PaletteReference pr)
{ {
var p = BaseBuildingPreview(building, pr); var p = BaseBuildingPreview(world, building, pr);
var anim = new Animation(RenderSprites.GetImage(building), () => 0); var anim = new Animation(world, RenderSprites.GetImage(building), () => 0);
anim.PlayRepeating("idle-top"); anim.PlayRepeating("idle-top");
return p.Concat(anim.Render(WPos.Zero, WVec.Zero, 0, pr, Scale)); return p.Concat(anim.Render(WPos.Zero, WVec.Zero, 0, pr, Scale));
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Render
public RenderBuildingWarFactory(ActorInitializer init, RenderBuildingInfo info) public RenderBuildingWarFactory(ActorInitializer init, RenderBuildingInfo info)
: base(init, info) : base(init, info)
{ {
roof = new Animation(GetImage(init.self)); roof = new Animation(init.world, GetImage(init.self));
var bi = init.self.Info.Traits.Get<BuildingInfo>(); var bi = init.self.Info.Traits.Get<BuildingInfo>();
// Additional 512 units move from center -> top of cell // Additional 512 units move from center -> top of cell

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render
// HACK: Force images to be loaded up-front // HACK: Force images to be loaded up-front
foreach (var image in info.ImagesByFullness) foreach (var image in info.ImagesByFullness)
new Animation(image); new Animation(self.World, image);
} }
public override void Tick(Actor self) public override void Tick(Actor self)

View File

@@ -25,15 +25,15 @@ namespace OpenRA.Mods.RA.Render
class WithCrateBody : INotifyParachuteLanded class WithCrateBody : INotifyParachuteLanded
{ {
Actor self; readonly Actor self;
Animation anim; readonly Animation anim;
public WithCrateBody(Actor self, WithCrateBodyInfo info) public WithCrateBody(Actor self, WithCrateBodyInfo info)
{ {
this.self = self; this.self = self;
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var images = info.XmasImages.Any() && DateTime.Today.Month == 12 ? info.XmasImages : info.Images; var images = info.XmasImages.Any() && DateTime.Today.Month == 12 ? info.XmasImages : info.Images;
anim = new Animation(images.Random(Game.CosmeticRandom)); anim = new Animation(self.World, images.Random(Game.CosmeticRandom));
anim.Play("idle"); anim.Play("idle");
rs.anims.Add("", anim); rs.anims.Add("", anim);
} }

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Render
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>(); var body = self.Trait<IBodyOrientation>();
anim = new Animation(rs.GetImage(self), RenderSimple.MakeFacingFunc(self)); anim = new Animation(self.World, rs.GetImage(self), RenderSimple.MakeFacingFunc(self));
anim.Play(info.Sequence); anim.Play(info.Sequence);
rs.anims.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim, rs.anims.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Render
var disabled = self.TraitsImplementing<IDisable>(); var disabled = self.TraitsImplementing<IDisable>();
buildComplete = !self.HasTrait<Building>(); // always render instantly for units buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(rs.GetImage(self)); overlay = new Animation(self.World, rs.GetImage(self));
overlay.PlayRepeating(info.Sequence); overlay.PlayRepeating(info.Sequence);
rs.anims.Add("idle_overlay_{0}".F(info.Sequence), rs.anims.Add("idle_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, new AnimationWithOffset(overlay,

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Render
getFacing = turreted != null ? () => turreted.turretFacing : getFacing = turreted != null ? () => turreted.turretFacing :
facing != null ? (Func<int>)(() => facing.Facing) : () => 0; facing != null ? (Func<int>)(() => facing.Facing) : () => 0;
var muzzleFlash = new Animation(render.GetImage(self), getFacing); var muzzleFlash = new Animation(self.World, render.GetImage(self), getFacing);
visible.Add(barrel, false); visible.Add(barrel, false);
anims.Add(barrel, anims.Add(barrel,
new AnimationWithOffset(muzzleFlash, new AnimationWithOffset(muzzleFlash,

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Render
rs = self.Trait<RenderSimple>(); rs = self.Trait<RenderSimple>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>(); playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
anim = new Animation(rs.GetImage(self)); anim = new Animation(self.World, rs.GetImage(self));
anim.PlayFetchIndex(info.Sequence, anim.PlayFetchIndex(info.Sequence,
() => playerResources.OreCapacity != 0 () => playerResources.OreCapacity != 0
? ((10 * anim.CurrentSequence.Length - 1) * playerResources.Ore) / (10 * playerResources.OreCapacity) ? ((10 * anim.CurrentSequence.Length - 1) * playerResources.Ore) / (10 * playerResources.OreCapacity)

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Render
var body = self.Trait<IBodyOrientation>(); var body = self.Trait<IBodyOrientation>();
movement = self.Trait<IMove>(); movement = self.Trait<IMove>();
rotorAnim = new Animation(rs.GetImage(self)); rotorAnim = new Animation(self.World, rs.GetImage(self));
rotorAnim.PlayRepeating(info.Sequence); rotorAnim.PlayRepeating(info.Sequence);
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim, rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Render
{ {
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
anim = new Animation("smoke_m"); anim = new Animation(self.World, "smoke_m");
rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking)); rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking));
} }

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Render
arms = self.TraitsImplementing<Armament>() arms = self.TraitsImplementing<Armament>()
.Where(w => w.Info.Turret == info.Turret); .Where(w => w.Info.Turret == info.Turret);
anim = new Animation(rs.GetImage(self), () => t.turretFacing); anim = new Animation(self.World, rs.GetImage(self), () => t.turretFacing);
anim.Play(info.Sequence); anim.Play(info.Sequence);
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset( rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
anim, () => TurretOffset(self), null, () => false, p => ZOffsetFromCenter(self, p, 1))); anim, () => TurretOffset(self), null, () => false, p => ZOffsetFromCenter(self, p, 1)));

View File

@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA
// Facing rotation // Facing rotation
rotation = WRange.FromPDF(Game.CosmeticRandom, 2).Range * info.ROT / 1024; rotation = WRange.FromPDF(Game.CosmeticRandom, 2).Range * info.ROT / 1024;
var anim = new Animation(rs.GetImage(self), () => (int)facing); var anim = new Animation(init.world, rs.GetImage(self), () => (int)facing);
anim.PlayRepeating(info.Anim); anim.PlayRepeating(info.Anim);
rs.anims.Add(info.Anim, new AnimationWithOffset(anim, () => pos, null)); rs.anims.Add(info.Anim, new AnimationWithOffset(anim, () => pos, null));
} }

View File

@@ -63,9 +63,9 @@ namespace OpenRA.Mods.RA.Widgets
this.world = world; this.world = world;
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
cantBuild = new Animation("clock"); cantBuild = new Animation(world, "clock");
cantBuild.PlayFetchIndex("idle", () => 0); cantBuild.PlayFetchIndex("idle", () => 0);
clock = new Animation("clock"); clock = new Animation(world, "clock");
VisibleQueues = new List<ProductionQueue>(); VisibleQueues = new List<ProductionQueue>();
CurrentQueue = null; CurrentQueue = null;
} }
@@ -231,7 +231,7 @@ namespace OpenRA.Mods.RA.Widgets
{ {
var rect = new RectangleF(origin.X + x * IconWidth, origin.Y + IconHeight * y, IconWidth, IconHeight); var rect = new RectangleF(origin.X + x * IconWidth, origin.Y + IconHeight * y, IconWidth, IconHeight);
var drawPos = new float2(rect.Location); var drawPos = new float2(rect.Location);
var icon = new Animation(RenderSimple.GetImage(item)); var icon = new Animation(world, RenderSimple.GetImage(item));
icon.Play(item.Traits.Get<TooltipInfo>().Icon); icon.Play(item.Traits.Get<TooltipInfo>().Icon);
WidgetUtils.DrawSHPCentered(icon.Image, drawPos + iconOffset, worldRenderer); WidgetUtils.DrawSHPCentered(icon.Image, drawPos + iconOffset, worldRenderer);

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA.Widgets
{ {
if (!clocks.ContainsKey(queue.Trait)) if (!clocks.ContainsKey(queue.Trait))
{ {
clocks.Add(queue.Trait, new Animation("clock")); clocks.Add(queue.Trait, new Animation(world, "clock"));
} }
} }
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.RA.Widgets
if (actor == null) if (actor == null)
continue; continue;
var icon = new Animation(RenderSimple.GetImage(actor)); var icon = new Animation(world, RenderSimple.GetImage(actor));
icon.Play(actor.Traits.Get<TooltipInfo>().Icon); icon.Play(actor.Traits.Get<TooltipInfo>().Icon);
var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0); var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0);
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer, 0.5f); WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer, 0.5f);

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Widgets
this.world = world; this.world = world;
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
clocks = new Dictionary<string, Animation>(); clocks = new Dictionary<string, Animation>();
icon = new Animation("icon"); icon = new Animation(world, "icon");
} }
protected ObserverSupportPowerIconsWidget(ObserverSupportPowerIconsWidget other) protected ObserverSupportPowerIconsWidget(ObserverSupportPowerIconsWidget other)
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Widgets
{ {
if (!clocks.ContainsKey(power.a.Key)) if (!clocks.ContainsKey(power.a.Key))
{ {
clocks.Add(power.a.Key, new Animation("clock")); clocks.Add(power.a.Key, new Animation(world, "clock"));
} }
} }

View File

@@ -44,8 +44,8 @@ namespace OpenRA.Mods.RA.Widgets
{ {
base.Initialize(args); base.Initialize(args);
icon = new Animation("icon"); icon = new Animation(world, "icon");
clock = new Animation("clock"); clock = new Animation(world, "clock");
} }
public override Rectangle EventBounds public override Rectangle EventBounds