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:
@@ -61,6 +61,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Sync] public Actor Carryable { get; private set; }
|
||||
public CarryallState State { get; private set; }
|
||||
|
||||
int cachedFacing;
|
||||
IActorPreview[] carryablePreview = null;
|
||||
|
||||
/// <summary>Offset between the carryall's and the carried actor's CenterPositions</summary>
|
||||
@@ -84,6 +85,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Cargo may be killed in the same tick as, but after they are attached
|
||||
if (Carryable != null && Carryable.IsDead)
|
||||
DetachCarryable(self);
|
||||
|
||||
// HACK: We don't have an efficient way to know when the preview
|
||||
// bounds change, so assume that we need to update the screen map
|
||||
// (only) when the facing changes
|
||||
if (facing.Facing != cachedFacing && carryablePreview != null)
|
||||
{
|
||||
self.World.ScreenMap.AddOrUpdate(self);
|
||||
cachedFacing = facing.Facing;
|
||||
}
|
||||
}
|
||||
|
||||
void INotifyActorDisposing.Disposing(Actor self)
|
||||
@@ -126,6 +136,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
Carryable = carryable;
|
||||
State = CarryallState.Carrying;
|
||||
self.World.ScreenMap.AddOrUpdate(self);
|
||||
|
||||
CarryableOffset = OffsetForCarryable(self, carryable);
|
||||
return true;
|
||||
@@ -134,6 +145,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public virtual void DetachCarryable(Actor self)
|
||||
{
|
||||
UnreserveCarryable(self);
|
||||
self.World.ScreenMap.AddOrUpdate(self);
|
||||
|
||||
carryablePreview = null;
|
||||
CarryableOffset = WVec.Zero;
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void ITickRender.TickRender(WorldRenderer wr, Actor self)
|
||||
{
|
||||
IRenderable[] renderables = null;
|
||||
Rectangle[] bounds = null;
|
||||
for (var playerIndex = 0; playerIndex < frozenStates.Count; playerIndex++)
|
||||
{
|
||||
var frozen = frozenStates[playerIndex].FrozenActor;
|
||||
@@ -137,11 +138,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
isRendering = true;
|
||||
renderables = self.Render(wr).ToArray();
|
||||
bounds = self.ScreenBounds(wr).ToArray();
|
||||
|
||||
isRendering = false;
|
||||
}
|
||||
|
||||
frozen.NeedRenderables = false;
|
||||
frozen.Renderables = renderables;
|
||||
frozen.ScreenBounds = bounds;
|
||||
self.World.ScreenMap.AddOrUpdate(self.World.Players[playerIndex], frozen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user