Use IRender.ScreenBounds in ScreenMap.

Traits are now required to trigger a ScreenMap update whenever they
believe that their ScreenBounds have changed.
This commit is contained in:
Paul Chote
2017-12-09 19:09:17 +00:00
committed by reaperrr
parent fa65fef4d1
commit 8fcc80b05a
8 changed files with 141 additions and 24 deletions

View File

@@ -101,6 +101,10 @@ namespace OpenRA.Mods.Common.Traits.Render
public readonly bool IsPlayerPalette;
public PaletteReference PaletteReference { get; private set; }
bool cachedVisible;
WVec cachedOffset;
ISpriteSequence cachedSequence;
public AnimationWrapper(AnimationWithOffset animation, string palette, bool isPlayerPalette)
{
Animation = animation;
@@ -127,6 +131,24 @@ namespace OpenRA.Mods.Common.Traits.Render
return Animation.DisableFunc == null || !Animation.DisableFunc();
}
}
public bool Tick()
{
// Tick the animation
Animation.Animation.Tick();
// Return to the caller whether the renderable position or size has changed
var visible = IsVisible;
var offset = Animation.OffsetFunc != null ? Animation.OffsetFunc() : WVec.Zero;
var sequence = Animation.Animation.CurrentSequence;
var updated = visible != cachedVisible || offset != cachedOffset || sequence != cachedSequence;
cachedVisible = visible;
cachedOffset = offset;
cachedSequence = sequence;
return updated;
}
}
readonly string faction;
@@ -196,8 +218,12 @@ namespace OpenRA.Mods.Common.Traits.Render
protected virtual void Tick(Actor self)
{
var updated = false;
foreach (var a in anims)
a.Animation.Animation.Tick();
updated |= a.Tick();
if (updated)
self.World.ScreenMap.AddOrUpdate(self);
}
public void Add(AnimationWithOffset anim, string palette = null, bool isPlayerPalette = false)