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)
{
this.pos = pos;
anim = new Animation("moveflsh");
anim = new Animation(world, "moveflsh");
anim.PlayThen("idle", () => world.AddFrameEndTask(w => w.Remove(this)));
}

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Graphics
public bool IsDecoration = false;
public Func<bool> Paused;
Func<int> facingFunc;
readonly Func<int> facingFunc;
int frame = 0;
bool backwards = false;
@@ -29,27 +29,19 @@ namespace OpenRA.Graphics
public string Name { get { return name; } }
readonly SequenceProvider sequenceProvider;
static SequenceProvider lastSequenceProvider;
public Animation(string name)
: this(name, () => 0) {}
public Animation(World world, string name)
: 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.tickFunc = () => {};
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; } }

View File

@@ -19,9 +19,9 @@ namespace OpenRA.Traits
{
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");
return anim.Render(WPos.Zero, WVec.Zero, 0, pr, Scale);
@@ -35,7 +35,7 @@ namespace OpenRA.Traits
public RenderSimple(Actor self, Func<int> baseFacing)
: base(self)
{
anims.Add("", new Animation(GetImage(self), baseFacing));
anims.Add("", new Animation(self.World, GetImage(self), baseFacing));
Info = self.Info.Traits.Get<RenderSimpleInfo>();
}

View File

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

View File

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

View File

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