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

@@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA
if (barrel != null && a.Info.MuzzleSequence != null)
{
// 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;
if (a.Info.MuzzleSplitFacings > 0)

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Buildings
for (var i = 0; i < rows * width; 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);
// Some mods may define terrain-specific bibs

View File

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

View File

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

View File

@@ -66,6 +66,8 @@ namespace OpenRA.Mods.RA.Effects
this.args = args;
this.pos = args.Source;
var world = args.SourceActor.World;
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));
@@ -89,7 +91,7 @@ namespace OpenRA.Mods.RA.Effects
if (info.Image != null)
{
anim = new Animation(info.Image, GetEffectiveFacing);
anim = new Animation(world, info.Image, GetEffectiveFacing);
anim.PlayRepeating("idle");
}

View File

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

View File

@@ -17,13 +17,15 @@ namespace OpenRA.Mods.RA.Effects
class CrateEffect : IEffect
{
readonly string palette;
Actor a;
Animation anim = new Animation("crate-effects");
readonly Actor a;
readonly Animation anim;
public CrateEffect(Actor a, string seq, string palette)
{
this.a = a;
this.palette = palette;
anim = new Animation(a.World, "crate-effects");
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.cell = pos.ToCPos();
this.palette = palette;
anim = new Animation("explosion");
anim = new Animation(world, "explosion");
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this)));
}

View File

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

View File

@@ -16,27 +16,29 @@ namespace OpenRA.Mods.RA.Effects
{
class GpsSatellite : IEffect
{
WPos Pos;
Animation Anim = new Animation("sputnik");
WPos pos;
readonly Animation anim;
public GpsSatellite(WPos pos)
public GpsSatellite(World world, WPos pos)
{
Pos = pos;
Anim.PlayRepeating("idle");
this.pos = pos;
anim = new Animation(world, "sputnik");
anim.PlayRepeating("idle");
}
public void Tick( World world )
{
Anim.Tick();
Pos += new WVec(0, 0, 427);
anim.Tick();
pos += new WVec(0, 0, 427);
if (Pos.Z > Pos.Y)
if (pos.Z > pos.Y)
world.AddFrameEndTask(w => w.Remove(this));
}
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;
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"))
anim.PlayThen("open", () => anim.PlayRepeating("idle"));
else

View File

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

View File

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

View File

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

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Effects
this.cargo = cargo;
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"));
if (pai != null)

View File

@@ -18,12 +18,15 @@ namespace OpenRA.Mods.RA.Effects
{
class PowerdownIndicator : IEffect
{
Actor a;
Animation anim = new Animation("poweroff");
readonly Actor a;
readonly Animation anim;
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)

View File

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

View File

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

View File

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

View File

@@ -17,11 +17,13 @@ namespace OpenRA.Mods.RA.Effects
class SatelliteLaunch : IEffect
{
int frame = 0;
Animation doors = new Animation("atek");
WPos pos;
readonly Animation doors;
readonly WPos pos;
public SatelliteLaunch(Actor a)
{
doors = new Animation(a.World, "atek");
doors.PlayThen("active",
() => a.World.AddFrameEndTask(w => w.Remove(this)));
@@ -33,7 +35,7 @@ namespace OpenRA.Mods.RA.Effects
doors.Tick();
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)

View File

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

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.RA.Orders
var palette = rbi.Palette ?? (Producer.Owner != 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;

View File

@@ -21,15 +21,15 @@ namespace OpenRA.Mods.RA.Render
public override object Create(ActorInitializer init) { return new RenderBuildingWarFactory( init, this ); }
/* 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 anim = new Animation(RenderSprites.GetImage(building), () => 0);
var p = BaseBuildingPreview(world, building, pr);
var anim = new Animation(world, RenderSprites.GetImage(building), () => 0);
anim.PlayRepeating("idle-top");
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)
: 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>();
// 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
foreach (var image in info.ImagesByFullness)
new Animation(image);
new Animation(self.World, image);
}
public override void Tick(Actor self)

View File

@@ -25,15 +25,15 @@ namespace OpenRA.Mods.RA.Render
class WithCrateBody : INotifyParachuteLanded
{
Actor self;
Animation anim;
readonly Actor self;
readonly Animation anim;
public WithCrateBody(Actor self, WithCrateBodyInfo info)
{
this.self = self;
var rs = self.Trait<RenderSprites>();
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");
rs.anims.Add("", anim);
}

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Render
var rs = self.Trait<RenderSprites>();
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);
rs.anims.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim,
() => 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>();
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);
rs.anims.Add("idle_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Render
getFacing = turreted != null ? () => turreted.turretFacing :
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);
anims.Add(barrel,
new AnimationWithOffset(muzzleFlash,

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Render
rs = self.Trait<RenderSimple>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
anim = new Animation(rs.GetImage(self));
anim = new Animation(self.World, rs.GetImage(self));
anim.PlayFetchIndex(info.Sequence,
() => playerResources.OreCapacity != 0
? ((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>();
movement = self.Trait<IMove>();
rotorAnim = new Animation(rs.GetImage(self));
rotorAnim = new Animation(self.World, rs.GetImage(self));
rotorAnim.PlayRepeating(info.Sequence);
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
() => 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>();
anim = new Animation("smoke_m");
anim = new Animation(self.World, "smoke_m");
rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking));
}

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Render
arms = self.TraitsImplementing<Armament>()
.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);
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
anim, () => TurretOffset(self), null, () => false, p => ZOffsetFromCenter(self, p, 1)));

View File

@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA
// Facing rotation
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);
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.worldRenderer = worldRenderer;
cantBuild = new Animation("clock");
cantBuild = new Animation(world, "clock");
cantBuild.PlayFetchIndex("idle", () => 0);
clock = new Animation("clock");
clock = new Animation(world, "clock");
VisibleQueues = new List<ProductionQueue>();
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 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);
WidgetUtils.DrawSHPCentered(icon.Image, drawPos + iconOffset, worldRenderer);

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA.Widgets
{
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)
continue;
var icon = new Animation(RenderSimple.GetImage(actor));
var icon = new Animation(world, RenderSimple.GetImage(actor));
icon.Play(actor.Traits.Get<TooltipInfo>().Icon);
var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0);
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.worldRenderer = worldRenderer;
clocks = new Dictionary<string, Animation>();
icon = new Animation("icon");
icon = new Animation(world, "icon");
}
protected ObserverSupportPowerIconsWidget(ObserverSupportPowerIconsWidget other)
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Widgets
{
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);
icon = new Animation("icon");
clock = new Animation("clock");
icon = new Animation(world, "icon");
clock = new Animation(world, "clock");
}
public override Rectangle EventBounds