Skip to content

Commit a3c4e22

Browse files
authored
Merge pull request #10 from JaThePlayer/perf/AssistRectangle
Optimise AssistRectangle and implement camera culling.
2 parents e4db68d + ac09286 commit a3c4e22

1 file changed

Lines changed: 27 additions & 15 deletions

File tree

Code/Entities/AssistRectangle.cs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Celeste.Mod.Entities;
2+
using Celeste.Mod.Helpers;
23
using Microsoft.Xna.Framework;
34
using Monocle;
45

@@ -16,32 +17,43 @@ public AssistRectangle(Vector2 position, int width, int height, Color color)
1617
Position = position;
1718
Collider = new Hitbox(width, height);
1819
this.color = color;
20+
Active = false;
1921
}
2022
public AssistRectangle(EntityData data, Vector2 offset) : this(data.Position + offset, data.Width, data.Height, Calc.HexToColor(data.Attr("color")))
2123
{
2224

2325
}
2426
public override void Render()
2527
{
26-
int num = (int)Left;
27-
int num2 = (int)Right;
28-
int num3 = (int)Top;
29-
int num4 = (int)Bottom;
30-
Draw.Rect(num + 4, num3 + 4, Width - 8f, Height - 8f, color * secretAlpha);
31-
for (float num5 = num; num5 < (float)(num2 - 3); num5 += 3f)
28+
int left = (int)Left;
29+
int top = (int)Top;
30+
float width = Width;
31+
float height = Height;
32+
33+
if (!CullHelper.IsRectangleVisible(left, top, width, height))
3234
{
33-
Draw.Line(num5, num3, num5 + 2f, num3, color);
34-
Draw.Line(num5, num4 - 1, num5 + 2f, num4 - 1, color);
35+
return;
3536
}
36-
for (float num6 = num3; num6 < (float)(num4 - 3); num6 += 3f)
37+
38+
int right = (int)Right;
39+
int bottom = (int)Bottom;
40+
41+
Draw.Rect(left + 4, top + 4, width - 8f, height - 8f, color * secretAlpha);
42+
for (float x = left; x < right - 3; x += 3f)
43+
{
44+
Draw.Rect(x, top, 2, 1, color);
45+
Draw.Rect(x, bottom - 1, 2, 1, color);
46+
}
47+
for (float y = top; y < bottom - 3; y += 3f)
3748
{
38-
Draw.Line(num + 1, num6, num + 1, num6 + 2f, color);
39-
Draw.Line(num2, num6, num2, num6 + 2f, color);
49+
Draw.Rect(left, y, 1, 2, color);
50+
Draw.Rect(right - 1, y, 1, 2, color);
4051
}
41-
Draw.Rect(num + 1, num3, 1f, 2f, color);
42-
Draw.Rect(num2 - 2, num3, 2f, 2f, color);
43-
Draw.Rect(num, num4 - 2, 2f, 2f, color);
44-
Draw.Rect(num2 - 2, num4 - 2, 2f, 2f, color);
52+
Draw.Rect(left + 1, top, 1f, 2f, color);
53+
Draw.Rect(right - 2, top, 2f, 2f, color);
54+
Draw.Rect(left, bottom - 2, 2f, 2f, color);
55+
Draw.Rect(right - 2, bottom - 2, 2f, 2f, color);
56+
4557
base.Render();
4658
}
4759
}

0 commit comments

Comments
 (0)