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)

View File

@@ -70,9 +70,36 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
public class RenderVoxels : IRender, INotifyOwnerChanged
public class RenderVoxels : IRender, ITick, INotifyOwnerChanged
{
class AnimationWrapper
{
readonly ModelAnimation model;
bool cachedVisible;
WVec cachedOffset;
public AnimationWrapper(ModelAnimation model)
{
this.model = model;
}
public bool Tick()
{
// Return to the caller whether the renderable position or size has changed
var visible = model.IsVisible;
var offset = model.OffsetFunc != null ? model.OffsetFunc() : WVec.Zero;
var updated = visible != cachedVisible || offset != cachedOffset;
cachedVisible = visible;
cachedOffset = offset;
return updated;
}
}
readonly List<ModelAnimation> components = new List<ModelAnimation>();
readonly Dictionary<ModelAnimation, AnimationWrapper> wrappers = new Dictionary<ModelAnimation, AnimationWrapper>();
readonly Actor self;
readonly RenderVoxelsInfo info;
readonly BodyOrientation body;
@@ -91,6 +118,16 @@ namespace OpenRA.Mods.Common.Traits.Render
bool initializePalettes = true;
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { initializePalettes = true; }
void ITick.Tick(Actor self)
{
var updated = false;
foreach (var w in wrappers.Values)
updated |= w.Tick();
if (updated)
self.World.ScreenMap.AddOrUpdate(self);
}
protected PaletteReference colorPalette, normalsPalette, shadowPalette;
IEnumerable<IRenderable> IRender.Render(Actor self, WorldRenderer wr)
{
@@ -118,7 +155,16 @@ namespace OpenRA.Mods.Common.Traits.Render
}
public string Image { get { return info.Image ?? self.Info.Name; } }
public void Add(ModelAnimation v) { components.Add(v); }
public void Remove(ModelAnimation v) { components.Remove(v); }
public void Add(ModelAnimation m)
{
components.Add(m);
wrappers.Add(m, new AnimationWrapper(m));
}
public void Remove(ModelAnimation m)
{
components.Remove(m);
wrappers.Remove(m);
}
}
}