Skip to content

Commit 2629f29

Browse files
committed
refactor: make getProjectedScreenPosition pure
1 parent 112964b commit 2629f29

File tree

3 files changed

+62
-23
lines changed

3 files changed

+62
-23
lines changed

src/main/java/org/runejs/client/MovedStatics.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,22 +1951,27 @@ public static void method311(Component arg1) {
19511951
arg1.removeFocusListener(Class59.keyFocusListener);
19521952
}
19531953

1954-
public static void method450() {
1955-
if (Player.headIconDrawType == 2) {
1956-
MovedStatics.getProjectedScreenPosition(2 * ActorDefinition.hintIconPosZ, Class35.hintIconInnerPosY + (-Class26.baseY + hintIconPosY << 7), (ProducingGraphicsBuffer.hintIconPosX + -baseX << 7) + Landscape.hintIconInnerPosX);
1957-
if (ISAAC.anInt522 > -1 && pulseCycle % 20 < 10)
1958-
hintIconSprites[0].drawImage(ISAAC.anInt522 + -12, -28 + Class44.anInt1048);
1959-
}
1960-
}
1954+
public static void method450() {
1955+
if (Player.headIconDrawType != 2) {
1956+
return;
1957+
}
1958+
1959+
Point2d screenPos = MovedStatics.getProjectedScreenPosition(2 * ActorDefinition.hintIconPosZ, Class35.hintIconInnerPosY + (-Class26.baseY + hintIconPosY << 7), (ProducingGraphicsBuffer.hintIconPosX + -baseX << 7) + Landscape.hintIconInnerPosX);
1960+
1961+
if (screenPos == null) {
1962+
return;
1963+
}
1964+
1965+
if (pulseCycle % 20 < 10)
1966+
hintIconSprites[0].drawImage(screenPos.x - 12, screenPos.y - 28);
1967+
}
19611968

19621969
/**
19631970
* Project 3d pos to 3d
19641971
*/
1965-
public static void getProjectedScreenPosition(int z, int y, int x) {
1972+
public static Point2d getProjectedScreenPosition(int z, int y, int x) {
19661973
if (x < 128 || y < 128 || x > 13056 || y > 13056) {
1967-
Class44.anInt1048 = -1;
1968-
ISAAC.anInt522 = -1;
1969-
return;
1974+
return null;
19701975
}
19711976

19721977
int drawHeight = Scene.getFloorDrawHeight(Player.worldLevel, x, y) - z;
@@ -1990,19 +1995,20 @@ public static void getProjectedScreenPosition(int z, int y, int x) {
19901995
y = y * cosinePitch + drawHeight * sinePitch >> 16;
19911996
drawHeight = tmp;
19921997

1993-
// statics to hold entity draw location
1998+
// TODO (jkm) why don't we draw below y=50?
19941999
if (y < 50) {
1995-
Class44.anInt1048 = -1;
1996-
ISAAC.anInt522 = -1;
1997-
} else {
1998-
if (ScreenController.frameMode == ScreenMode.FIXED) {
1999-
ISAAC.anInt522 = 256 + (x << 9) / y;
2000-
Class44.anInt1048 = (drawHeight << 9) / y + 167;
2001-
} else {
2002-
ISAAC.anInt522 = ScreenController.drawWidth / 2 + (x << 9) / y;
2003-
Class44.anInt1048 = (drawHeight << 9) / y + ScreenController.drawHeight / 2;
2004-
}
2000+
return null;
2001+
}
2002+
2003+
return new Point2d((x << 9) / y, (drawHeight << 9) / y)
2004+
.add(getScreenMidpoint());
2005+
}
20052006

2007+
public static Point2d getScreenMidpoint() {
2008+
if (ScreenController.frameMode == ScreenMode.FIXED) {
2009+
return new Point2d(256, 167);
2010+
} else {
2011+
return new Point2d(ScreenController.drawWidth / 2, ScreenController.drawHeight / 2);
20062012
}
20072013
}
20082014

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.runejs.client.scene;
2+
3+
public class Point2d {
4+
public final int x;
5+
public final int y;
6+
7+
public Point2d(int x, int y) {
8+
this.x = x;
9+
this.y = y;
10+
}
11+
12+
public Point2d add(Point2d other) {
13+
return new Point2d(x + other.x, y + other.y);
14+
}
15+
16+
public Point2d addX(int x) {
17+
return new Point2d(this.x + x, this.y );
18+
}
19+
20+
public Point2d addY(int y) {
21+
return new Point2d(this.x, this.y + y );
22+
}
23+
}

src/main/java/org/runejs/client/scene/tile/FloorDecoration.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.runejs.client.net.IncomingPackets;
1616
import org.runejs.client.scene.GroundItemTile;
1717
import org.runejs.client.scene.InteractiveObject;
18+
import org.runejs.client.scene.Point2d;
1819
import org.runejs.client.util.SignlinkNode;
1920
import org.runejs.client.*;
2021

@@ -33,7 +34,16 @@ public class FloorDecoration {
3334
public int z;
3435

3536
public static void method342(int arg1, Actor arg2) {
36-
MovedStatics.getProjectedScreenPosition(arg1, arg2.worldY, arg2.worldX);
37+
Point2d screenPos = MovedStatics.getProjectedScreenPosition(arg1, arg2.worldY, arg2.worldX);
38+
39+
if (screenPos == null) {
40+
Class44.anInt1048 = -1;
41+
ISAAC.anInt522 = -1;
42+
return;
43+
}
44+
45+
Class44.anInt1048 = screenPos.y;
46+
ISAAC.anInt522 = screenPos.x;
3747
}
3848

3949
public static void constructMapRegion(boolean generatedMap) {

0 commit comments

Comments
 (0)