From ac092861e272cd51af8f8437b60e9c31e189b1ca Mon Sep 17 00:00:00 2001 From: JaThePlayer Date: Wed, 27 Aug 2025 23:46:20 +0200 Subject: [PATCH] Optimise AssistRectangle and implement camera culling. --- Code/Entities/AssistRectangle.cs | 42 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Code/Entities/AssistRectangle.cs b/Code/Entities/AssistRectangle.cs index 8a5915d..4e0bf10 100644 --- a/Code/Entities/AssistRectangle.cs +++ b/Code/Entities/AssistRectangle.cs @@ -1,4 +1,5 @@ using Celeste.Mod.Entities; +using Celeste.Mod.Helpers; using Microsoft.Xna.Framework; using Monocle; @@ -16,6 +17,7 @@ public AssistRectangle(Vector2 position, int width, int height, Color color) Position = position; Collider = new Hitbox(width, height); this.color = color; + Active = false; } public AssistRectangle(EntityData data, Vector2 offset) : this(data.Position + offset, data.Width, data.Height, Calc.HexToColor(data.Attr("color"))) { @@ -23,25 +25,35 @@ public AssistRectangle(EntityData data, Vector2 offset) : this(data.Position + o } public override void Render() { - int num = (int)Left; - int num2 = (int)Right; - int num3 = (int)Top; - int num4 = (int)Bottom; - Draw.Rect(num + 4, num3 + 4, Width - 8f, Height - 8f, color * secretAlpha); - for (float num5 = num; num5 < (float)(num2 - 3); num5 += 3f) + int left = (int)Left; + int top = (int)Top; + float width = Width; + float height = Height; + + if (!CullHelper.IsRectangleVisible(left, top, width, height)) { - Draw.Line(num5, num3, num5 + 2f, num3, color); - Draw.Line(num5, num4 - 1, num5 + 2f, num4 - 1, color); + return; } - for (float num6 = num3; num6 < (float)(num4 - 3); num6 += 3f) + + int right = (int)Right; + int bottom = (int)Bottom; + + Draw.Rect(left + 4, top + 4, width - 8f, height - 8f, color * secretAlpha); + for (float x = left; x < right - 3; x += 3f) + { + Draw.Rect(x, top, 2, 1, color); + Draw.Rect(x, bottom - 1, 2, 1, color); + } + for (float y = top; y < bottom - 3; y += 3f) { - Draw.Line(num + 1, num6, num + 1, num6 + 2f, color); - Draw.Line(num2, num6, num2, num6 + 2f, color); + Draw.Rect(left, y, 1, 2, color); + Draw.Rect(right - 1, y, 1, 2, color); } - Draw.Rect(num + 1, num3, 1f, 2f, color); - Draw.Rect(num2 - 2, num3, 2f, 2f, color); - Draw.Rect(num, num4 - 2, 2f, 2f, color); - Draw.Rect(num2 - 2, num4 - 2, 2f, 2f, color); + Draw.Rect(left + 1, top, 1f, 2f, color); + Draw.Rect(right - 2, top, 2f, 2f, color); + Draw.Rect(left, bottom - 2, 2f, 2f, color); + Draw.Rect(right - 2, bottom - 2, 2f, 2f, color); + base.Render(); } }