Skip to content

Commit d56e864

Browse files
authored
Merge pull request #162 from runejs/refactor/refactors-for-tile-markers
refactor: remove static screen projection, use pure function to calculate instead
2 parents 1d50eaa + 159fc66 commit d56e864

File tree

14 files changed

+195
-137
lines changed

14 files changed

+195
-137
lines changed

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

Lines changed: 76 additions & 65 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import org.runejs.client.io.Buffer;
66

77
public class Class35 implements Interface3 {
8-
public static int anInt1730 = 0;
8+
/**
9+
* Position of the hint icon within the specific tile.
10+
*/
11+
public static int hintIconInnerPosY = 0;
912
public static boolean aBoolean1734 = false;
1013
public static boolean aBoolean1735 = true;
1114
/**

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.runejs.client;
22

33
import org.runejs.client.cache.def.ActorDefinition;
4-
import org.runejs.client.cache.def.OverlayDefinition;
54
import org.runejs.client.cache.media.AnimationSequence;
65
import org.runejs.client.cache.media.ImageRGB;
76
import org.runejs.client.frame.ScreenController;
@@ -137,8 +136,8 @@ else if(isTeammate)
137136
}
138137
}
139138
if(Player.headIconDrawType == 2) {
140-
int hintX = -(Player.localPlayer.worldY / 32) + 2 + 4 * (-Class26.baseY + MovedStatics.anInt175);
141-
int hintY = 4 * (ProducingGraphicsBuffer.anInt1637 - MovedStatics.baseX) - (-2 + Player.localPlayer.worldX / 32);
139+
int hintX = -(Player.localPlayer.worldY / 32) + 2 + 4 * (-Class26.baseY + MovedStatics.hintIconPosY);
140+
int hintY = 4 * (ProducingGraphicsBuffer.hintIconPosX - MovedStatics.baseX) - (-2 + Player.localPlayer.worldX / 32);
142141
MovedStatics.drawMinimapMark(Class40_Sub3.aClass40_Sub5_Sub14_Sub4Array2019[1], hintY, hintX);
143142
}
144143
if(Player.headIconDrawType == 10 && ProducingGraphicsBuffer.anInt1623 >= 0 && Player.trackedPlayers.length > ProducingGraphicsBuffer.anInt1623) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class Class44 implements Runnable {
1414
public static byte[][] aByteArrayArray1039 = new byte[250][];
1515
public static int modewhere = 0;
1616
public static IndexedImage chatboxBackgroundImage;
17-
public static int anInt1048 = -1;
1817
public static int anInt1049 = 0;
1918

2019

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public class Landscape {
3030
public static int mouseY = 0;
3131
public static CollisionMap[] currentCollisionMap = new CollisionMap[4];
3232
public static int[] anIntArray1168;
33-
public static int anInt1170 = 0;
33+
/**
34+
* Position of the hint icon within the specific tile.
35+
*/
36+
public static int hintIconInnerPosX = 0;
3437
public static int anInt1171 = 0;
3538
public static String[] menuActionTexts = new String[500];
3639
public static ProducingGraphicsBuffer framePieceRight;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ public static void method353() {
867867

868868
Npc.currentScene.render(activeCamera, i);
869869
Npc.currentScene.clearInteractiveObjectCache();
870-
Class33.method404();
871-
MovedStatics.method450();
870+
Class33.draw2DActorAttachments();
871+
MovedStatics.drawPositionHintIcon();
872872
((Class35) Rasterizer3D.interface3).method425(MovedStatics.anInt199);
873873
KeyFocusListener.draw3dScreen();
874874

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

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ public class MovedStatics {
9393
public static int anInt573 = -1;
9494
public static boolean menuOpen = false;
9595
public static volatile long aLong174 = 0L;
96-
public static int anInt175 = 0;
96+
97+
/**
98+
* Position of the hint icon in world coordinates (e.g. 3222,3222).
99+
*/
100+
public static int hintIconPosY = 0;
97101
public static int[] anIntArray178;
98102
public static int[] chatboxLineOffsets;
99103
public static int anInt199 = 0;
@@ -1947,54 +1951,69 @@ public static void method311(Component arg1) {
19471951
arg1.removeFocusListener(Class59.keyFocusListener);
19481952
}
19491953

1950-
public static void method450() {
1951-
if (Player.headIconDrawType == 2) {
1952-
MovedStatics.method312(2 * ActorDefinition.anInt2404, Class35.anInt1730 + (-Class26.baseY + anInt175 << 7), (ProducingGraphicsBuffer.anInt1637 + -baseX << 7) + Landscape.anInt1170, 4976905);
1953-
if (ISAAC.anInt522 > -1 && pulseCycle % 20 < 10)
1954-
hintIconSprites[0].drawImage(ISAAC.anInt522 + -12, -28 + Class44.anInt1048);
1955-
}
1956-
}
1954+
/**
1955+
* Draws the 2d yellow arrow hint icon in the world.
1956+
*/
1957+
public static void drawPositionHintIcon() {
1958+
if (Player.headIconDrawType != 2) {
1959+
return;
1960+
}
19571961

1958-
public static void method312(int arg0, int arg1, int arg2, int arg3) {
1959-
if(arg2 < 128 || arg1 < 128 || arg2 > 13056 || arg1 > 13056) {
1960-
Class44.anInt1048 = -1;
1961-
ISAAC.anInt522 = -1;
1962-
} else {
1963-
int i = Scene.getFloorDrawHeight(Player.worldLevel, arg2, arg1) + -arg0;
1964-
1965-
Point3d cameraPos = Main.getActiveCamera().getPosition();
1966-
CameraRotation rotation = Main.getActiveCamera().getRotation();
1967-
1968-
arg1 -= cameraPos.y;
1969-
i -= cameraPos.z;
1970-
int i_1_ = Model.COSINE[rotation.pitch];
1971-
int i_2_ = Model.SINE[rotation.pitch];
1972-
arg2 -= cameraPos.x;
1973-
int i_3_ = Model.SINE[rotation.yaw];
1974-
int i_4_ = Model.COSINE[rotation.yaw];
1975-
int i_5_ = arg1 * i_3_ + arg2 * i_4_ >> 16;
1976-
arg1 = i_4_ * arg1 - arg2 * i_3_ >> 16;
1977-
if(arg3 != 4976905)
1978-
English.password = null;
1979-
arg2 = i_5_;
1980-
i_5_ = i * i_1_ - arg1 * i_2_ >> 16;
1981-
arg1 = arg1 * i_1_ + i * i_2_ >> 16;
1982-
i = i_5_;
1983-
if(arg1 < 50) {
1984-
Class44.anInt1048 = -1;
1985-
ISAAC.anInt522 = -1;
1986-
} else {
1987-
if(ScreenController.frameMode == ScreenMode.FIXED){
1988-
ISAAC.anInt522 = 256 + (arg2 << 9) / arg1;
1989-
Class44.anInt1048 = (i << 9) / arg1 + 167;
1990-
} else {
1991-
ISAAC.anInt522 = ScreenController.drawWidth/2 + (arg2 << 9) / arg1;
1992-
Class44.anInt1048 = (i << 9) / arg1 + ScreenController.drawHeight/2;
1993-
}
1994-
1995-
}
1996-
}
1997-
}
1962+
Point2d screenPos = MovedStatics.getProjectedScreenPosition(2 * ActorDefinition.hintIconPosZ, Class35.hintIconInnerPosY + (-Class26.baseY + hintIconPosY << 7), (ProducingGraphicsBuffer.hintIconPosX + -baseX << 7) + Landscape.hintIconInnerPosX);
1963+
1964+
if (screenPos == null) {
1965+
return;
1966+
}
1967+
1968+
if (pulseCycle % 20 < 10)
1969+
hintIconSprites[0].drawImage(screenPos.x - 12, screenPos.y - 28);
1970+
}
1971+
1972+
/**
1973+
* Project 3d pos to 3d
1974+
*/
1975+
public static Point2d getProjectedScreenPosition(int z, int y, int x) {
1976+
if (x < 128 || y < 128 || x > 13056 || y > 13056) {
1977+
return null;
1978+
}
1979+
1980+
int drawHeight = Scene.getFloorDrawHeight(Player.worldLevel, x, y) - z;
1981+
1982+
Point3d cameraPos = Main.getActiveCamera().getPosition();
1983+
CameraRotation rotation = Main.getActiveCamera().getRotation();
1984+
1985+
x -= cameraPos.x;
1986+
y -= cameraPos.y;
1987+
drawHeight -= cameraPos.z;
1988+
int cosinePitch = Model.COSINE[rotation.pitch];
1989+
int sinePitch = Model.SINE[rotation.pitch];
1990+
int sineYaw = Model.SINE[rotation.yaw];
1991+
int cosineYaw = Model.COSINE[rotation.yaw];
1992+
1993+
// rotate x/y/z according to camera pos
1994+
int tmp = y * sineYaw + x * cosineYaw >> 16;
1995+
y = cosineYaw * y - x * sineYaw >> 16;
1996+
x = tmp;
1997+
tmp = drawHeight * cosinePitch - y * sinePitch >> 16;
1998+
y = y * cosinePitch + drawHeight * sinePitch >> 16;
1999+
drawHeight = tmp;
2000+
2001+
// TODO (jkm) why don't we draw below y=50?
2002+
if (y < 50) {
2003+
return null;
2004+
}
2005+
2006+
return new Point2d((x << 9) / y, (drawHeight << 9) / y)
2007+
.add(getScreenMidpoint());
2008+
}
2009+
2010+
public static Point2d getScreenMidpoint() {
2011+
if (ScreenController.frameMode == ScreenMode.FIXED) {
2012+
return new Point2d(256, 167);
2013+
} else {
2014+
return new Point2d(ScreenController.drawWidth / 2, ScreenController.drawHeight / 2);
2015+
}
2016+
}
19982017

19992018
public static void method313() {
20002019
for(int i = -1; Player.localPlayerCount > i; i++) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ public abstract class ProducingGraphicsBuffer {
1313
public static ProducingGraphicsBuffer aProducingGraphicsBuffer_1631;
1414
public static SignlinkNode updateServerSignlinkNode;
1515
public static int anInt1634 = 0;
16-
public static int anInt1637 = 0;
16+
17+
/**
18+
* Position of the hint icon in world coordinates (e.g. 3222,3222)
19+
*/
20+
public static int hintIconPosX = 0;
1721
public static ProducingGraphicsBuffer muteButton;
1822

1923
public int height;

src/main/java/org/runejs/client/cache/def/ActorDefinition.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public class ActorDefinition extends CachedNode implements EntityDefinition {
2323

2424
public static int[] sidebarOffsets;
2525
public static int menuActionRow = 0;
26-
public static int anInt2404 = 0;
26+
27+
/**
28+
* Draw height of the icon in 3d positions.
29+
*/
30+
public static int hintIconPosZ = 0;
2731
public static int count;
2832

2933
public boolean isClickable = true;

src/main/java/org/runejs/client/frame/Minimap.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.runejs.client.media.renderable.actor.Actor;
1313
import org.runejs.client.media.renderable.actor.Npc;
1414
import org.runejs.client.media.renderable.actor.Player;
15-
import org.runejs.client.scene.GroundItemTile;
16-
import org.runejs.client.scene.SceneCamera;
1715
import org.runejs.client.scene.tile.Wall;
1816
import org.runejs.client.*;
1917

@@ -181,8 +179,8 @@ else if(isTeammate)
181179
}
182180
}
183181
if(Player.headIconDrawType == 2) {
184-
int hintY = -(Player.localPlayer.worldY / 32) + 2 + 4 * (-Class26.baseY + MovedStatics.anInt175);
185-
int hintX = 4 * (ProducingGraphicsBuffer.anInt1637 - MovedStatics.baseX) - (-2 + Player.localPlayer.worldX / 32);
182+
int hintY = -(Player.localPlayer.worldY / 32) + 2 + 4 * (-Class26.baseY + MovedStatics.hintIconPosY);
183+
int hintX = 4 * (ProducingGraphicsBuffer.hintIconPosX - MovedStatics.baseX) - (-2 + Player.localPlayer.worldX / 32);
186184
drawMinimapMark(Class40_Sub3.aClass40_Sub5_Sub14_Sub4Array2019[1], hintX, hintY);
187185
}
188186
if(Player.headIconDrawType == 10 && ProducingGraphicsBuffer.anInt1623 >= 0 && Player.trackedPlayers.length > ProducingGraphicsBuffer.anInt1623) {

0 commit comments

Comments
 (0)