Add support for only rendering effects inside screen bounds
This commit is contained in:
committed by
Paul Chote
parent
8ca43e3d6b
commit
1aebf9857c
@@ -13,6 +13,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
@@ -33,6 +34,7 @@ namespace OpenRA.Traits
|
||||
readonly Func<Actor, bool> actorIsInWorld = a => a.IsInWorld;
|
||||
readonly Cache<Player, SpatiallyPartitioned<FrozenActor>> partitionedFrozenActors;
|
||||
readonly SpatiallyPartitioned<Actor> partitionedActors;
|
||||
readonly SpatiallyPartitioned<IEffect> partitionedEffects;
|
||||
WorldRenderer worldRenderer;
|
||||
|
||||
public ScreenMap(World world, ScreenMapInfo info)
|
||||
@@ -43,6 +45,7 @@ namespace OpenRA.Traits
|
||||
partitionedFrozenActors = new Cache<Player, SpatiallyPartitioned<FrozenActor>>(
|
||||
_ => new SpatiallyPartitioned<FrozenActor>(width, height, info.BinSize));
|
||||
partitionedActors = new SpatiallyPartitioned<Actor>(width, height, info.BinSize);
|
||||
partitionedEffects = new SpatiallyPartitioned<IEffect>(width, height, info.BinSize);
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr) { worldRenderer = wr; }
|
||||
@@ -88,6 +91,37 @@ namespace OpenRA.Traits
|
||||
partitionedActors.Remove(a);
|
||||
}
|
||||
|
||||
public void Add(IEffect effect, WPos position, Size size)
|
||||
{
|
||||
var screenPos = worldRenderer.ScreenPxPosition(position);
|
||||
var screenBounds = new Rectangle(screenPos.X - size.Width / 2, screenPos.Y - size.Height / 2, size.Width, size.Height);
|
||||
partitionedEffects.Add(effect, screenBounds);
|
||||
}
|
||||
|
||||
public void Add(IEffect effect, WPos position, Sprite sprite)
|
||||
{
|
||||
var size = new Size((int)sprite.Size.X, (int)sprite.Size.Y);
|
||||
Add(effect, position, size);
|
||||
}
|
||||
|
||||
public void Update(IEffect effect, WPos position, Size size)
|
||||
{
|
||||
var screenPos = worldRenderer.ScreenPxPosition(position);
|
||||
var screenBounds = new Rectangle(screenPos.X - size.Width / 2, screenPos.Y - size.Height / 2, size.Width, size.Height);
|
||||
partitionedEffects.Update(effect, screenBounds);
|
||||
}
|
||||
|
||||
public void Update(IEffect effect, WPos position, Sprite sprite)
|
||||
{
|
||||
var size = new Size((int)sprite.Size.X, (int)sprite.Size.Y);
|
||||
Update(effect, position, size);
|
||||
}
|
||||
|
||||
public void Remove(IEffect e)
|
||||
{
|
||||
partitionedEffects.Remove(e);
|
||||
}
|
||||
|
||||
public IEnumerable<FrozenActor> FrozenActorsAt(Player viewer, int2 worldPx)
|
||||
{
|
||||
if (viewer == null)
|
||||
@@ -120,6 +154,11 @@ namespace OpenRA.Traits
|
||||
return ActorsInBox(RectWithCorners(a, b));
|
||||
}
|
||||
|
||||
public IEnumerable<IEffect> EffectsInBox(int2 a, int2 b)
|
||||
{
|
||||
return partitionedEffects.InBox(RectWithCorners(a, b));
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> ActorsInBox(Rectangle r)
|
||||
{
|
||||
return partitionedActors.InBox(r).Where(actorIsInWorld);
|
||||
@@ -130,6 +169,11 @@ namespace OpenRA.Traits
|
||||
return FrozenActorsInBox(p, RectWithCorners(a, b));
|
||||
}
|
||||
|
||||
public IEnumerable<IEffect> EffectsInBox(Rectangle r)
|
||||
{
|
||||
return partitionedEffects.InBox(r);
|
||||
}
|
||||
|
||||
public IEnumerable<FrozenActor> FrozenActorsInBox(Player p, Rectangle r)
|
||||
{
|
||||
if (p == null)
|
||||
|
||||
Reference in New Issue
Block a user