Simple MapEntity visibility culling (structures outside the camera view or items with nothing to render aren't drawn)
Could be optimized further, but already gives a pretty nice performance boost
This commit is contained in:
@@ -475,6 +475,15 @@ namespace Barotrauma
|
||||
if (convexHulls != null) convexHulls.ForEach(x => x.Remove());
|
||||
}
|
||||
|
||||
public override bool IsVisible(Rectangle WorldView)
|
||||
{
|
||||
Rectangle worldRect = WorldRect;
|
||||
|
||||
if (worldRect.X > WorldView.Right || worldRect.Right < WorldView.X) return false;
|
||||
if (worldRect.Y < WorldView.Y - WorldView.Height || worldRect.Y - worldRect.Height > WorldView.Y) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
|
||||
{
|
||||
@@ -514,7 +523,7 @@ namespace Barotrauma
|
||||
spriteBatch,
|
||||
new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)),
|
||||
new Vector2(rect.Width, rect.Height),
|
||||
Vector2.Zero, color, Point.Zero);
|
||||
color, Point.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,7 +562,7 @@ namespace Barotrauma
|
||||
spriteBatch,
|
||||
new Vector2(sections[i].rect.X + drawOffset.X, -(sections[i].rect.Y + drawOffset.Y)),
|
||||
new Vector2(sections[i].rect.Width, sections[i].rect.Height),
|
||||
Vector2.Zero, color,
|
||||
color,
|
||||
textureOffset, depth);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user