Skip to content

Commit

Permalink
refactor: Consistent number representation in Draw3D
Browse files Browse the repository at this point in the history
  • Loading branch information
Pazaz committed May 31, 2024
1 parent 35893e5 commit ce4b46d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 73 deletions.
4 changes: 2 additions & 2 deletions runetek3/src/main/java/jagex2/config/FloType.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FloType {
public int texture = -1;

@OriginalMember(owner = "client!fc", name = "g", descriptor = "Z")
private boolean opcode3 = false;
private boolean overlay = false;

@OriginalMember(owner = "client!fc", name = "h", descriptor = "Z")
public boolean occlude = true;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void decode(@OriginalArg(1) Packet dat) {
} else if (code == 2) {
this.texture = dat.g1();
} else if (code == 3) {
this.opcode3 = true;
this.overlay = true;
} else if (code == 5) {
this.occlude = false;
} else if (code == 6) {
Expand Down
11 changes: 10 additions & 1 deletion runetek3/src/main/java/jagex2/graphics/Draw2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,20 @@ public static void fillRectAlpha(@OriginalArg(0) int x, @OriginalArg(1) int y, @
width -= left - x;
x = left;
}

if (y < top) {
height -= top - y;
y = top;
}

if (x + width > right) {
width = right - x;
}

if (y + height > bottom) {
height = bottom - y;
}

@Pc(45) int invAlpha = 256 - alpha;
@Pc(53) int r0 = (rgb >> 16 & 0xFF) * alpha;
@Pc(61) int g0 = (rgb >> 8 & 0xFF) * alpha;
Expand All @@ -157,6 +161,7 @@ public static void fillRectAlpha(@OriginalArg(0) int x, @OriginalArg(1) int y, @
@Pc(136) int color = (r0 + r1 >> 8 << 16) + (g0 + g1 >> 8 << 8) + (b0 + b1 >> 8);
data[offset++] = color;
}

offset += step;
}
}
Expand All @@ -171,21 +176,25 @@ public static void fillCircle(@OriginalArg(0) int xCenter, @OriginalArg(1) int y
if (yStart < 0) {
yStart = 0;
}

@Pc(39) int yEnd = yCenter + yRadius;
if (yEnd >= height2d) {
yEnd = height2d - 1;
}

for (@Pc(48) int y = yStart; y <= yEnd; y++) {
@Pc(54) int midpoint = y - yCenter;
@Pc(65) int xRadius = (int) Math.sqrt((double) (yRadius * yRadius - midpoint * midpoint));
@Pc(65) int xRadius = (int) Math.sqrt((yRadius * yRadius) - (midpoint * midpoint));
@Pc(69) int xStart = xCenter - xRadius;
if (xStart < 0) {
xStart = 0;
}

@Pc(77) int xEnd = xCenter + xRadius;
if (xEnd >= width2d) {
xEnd = width2d - 1;
}

@Pc(90) int offset = xStart + y * width2d;
for (@Pc(92) int x = xStart; x <= xEnd; x++) {
@Pc(104) int r1 = (data[offset] >> 16 & 0xFF) * invAlpha;
Expand Down
Loading

0 comments on commit ce4b46d

Please sign in to comment.