Skip to content

Commit 04f602c

Browse files
committed
refactor: create clipping debug renderer
1 parent aa41061 commit 04f602c

File tree

5 files changed

+178
-2
lines changed

5 files changed

+178
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ public static void method353() {
874874
KeyFocusListener.draw3dScreen();
875875

876876
DebugTools.drawWalkPath();
877+
DebugTools.drawClipping();
877878

878879
if(ScreenController.frameMode == ScreenMode.FIXED) {
879880
Console.console.drawConsole(512, 334);

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

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.runejs.client.frame;
22

3+
import org.runejs.client.Landscape;
34
import org.runejs.client.MovedStatics;
45
import org.runejs.client.cache.media.TypeFace;
56
import org.runejs.client.media.Rasterizer;
7+
import org.runejs.client.media.renderable.actor.Player;
68
import org.runejs.client.scene.Point2d;
79

810
public class DebugTools {
@@ -55,4 +57,155 @@ public static void drawWalkPath() {
5557
TypeFace.fontSmall.drawStringLeft(walkpathX[walkpathX.length - 1] + "," + walkpathY[walkpathY.length - 1], pathFinishPos.x, pathFinishPos.y, 0x00AAFF);
5658
}
5759
}
60+
61+
public static boolean clippingEnabled = false;
62+
63+
public static void drawClipping() {
64+
if (!clippingEnabled) {
65+
return;
66+
}
67+
68+
for (int x = 0; x < 104; x++) {
69+
for (int y = 0; y < 104; y++) {
70+
int data = Landscape.currentCollisionMap[Player.worldLevel].clippingData[x][y];
71+
72+
Point2d screenPos = MovedStatics.getProjectedScreenPosition(0, y * 128 + 64, x * 128 + 64);
73+
74+
if (screenPos == null) {
75+
continue;
76+
}
77+
78+
Point2d posSW = MovedStatics.getProjectedScreenPosition(0, y * 128, x * 128);
79+
Point2d posNW = MovedStatics.getProjectedScreenPosition(0, y * 128 + 128, x * 128);
80+
Point2d posSE = MovedStatics.getProjectedScreenPosition(0, y * 128, x * 128 + 128);
81+
Point2d posNE = MovedStatics.getProjectedScreenPosition(0, y * 128 + 128, x * 128 + 128);
82+
83+
Point2d posSWA = MovedStatics.getProjectedScreenPosition(100, y * 128, x * 128);
84+
Point2d posNWA = MovedStatics.getProjectedScreenPosition(100, y * 128 + 128, x * 128);
85+
Point2d posSEA = MovedStatics.getProjectedScreenPosition(100, y * 128, x * 128 + 128);
86+
Point2d posNEA = MovedStatics.getProjectedScreenPosition(100, y * 128 + 128, x * 128 + 128);
87+
88+
int blockWalkColor = 0xFF0000;
89+
int blockProjectileColor = 0x539FE9;
90+
91+
if ((data & 0x2) == 0x2) {
92+
if (posNE != null && posNW != null) {
93+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNW.x, posNW.y, blockWalkColor);
94+
}
95+
}
96+
97+
if ((data & 0x8) == 0x8) {
98+
if (posSE != null && posNE != null) {
99+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posNE.x, posNE.y, blockWalkColor);
100+
}
101+
}
102+
103+
if ((data & 0x20) == 0x20) {
104+
if (posSE != null && posSW != null) {
105+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSW.x, posSW.y, blockWalkColor);
106+
}
107+
}
108+
109+
if ((data & 0x80) == 0x80) {
110+
if (posSW != null && posNW != null) {
111+
Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posNW.x, posNW.y, blockWalkColor);
112+
}
113+
}
114+
115+
if ((data & 0x100) == 0x100) {
116+
if (posNE != null && posNW != null) {
117+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNW.x, posNW.y, blockWalkColor);
118+
}
119+
if (posSE != null && posNE != null) {
120+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posNE.x, posNE.y, blockWalkColor);
121+
}
122+
if (posSE != null && posSW != null) {
123+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSW.x, posSW.y, blockWalkColor);
124+
}
125+
if (posSW != null && posNW != null) {
126+
Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posNW.x, posNW.y, blockWalkColor);
127+
}
128+
}
129+
130+
if ((data & 0x400) == 0x400) {
131+
if (posNEA != null && posNWA != null) {
132+
Rasterizer.drawDiagonalLine(posNEA.x, posNEA.y, posNWA.x, posNWA.y, blockProjectileColor);
133+
134+
if (posNE != null) {
135+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor);
136+
}
137+
138+
if (posNW != null) {
139+
Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor);
140+
}
141+
}
142+
}
143+
144+
if ((data & 0x1000) == 0x1000) {
145+
if (posSEA != null && posNEA != null) {
146+
Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posNEA.x, posNEA.y, blockProjectileColor);
147+
}
148+
}
149+
150+
if ((data & 0x4000) == 0x4000) {
151+
if (posSEA != null && posSWA != null) {
152+
Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posSWA.x, posSWA.y, blockProjectileColor);
153+
}
154+
}
155+
156+
if ((data & 0x8000) == 0x8000) {
157+
if (posSWA != null && posNWA != null) {
158+
Rasterizer.drawDiagonalLine(posSWA.x, posSWA.y, posNWA.x, posNWA.y, blockProjectileColor);
159+
}
160+
}
161+
162+
if ((data & 0x20000) == 0x20000) {
163+
if (posNEA != null && posNWA != null) {
164+
Rasterizer.drawDiagonalLine(posNEA.x, posNEA.y, posNWA.x, posNWA.y, blockProjectileColor);
165+
166+
if (posNE != null) {
167+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor);
168+
}
169+
170+
if (posNW != null) {
171+
Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor);
172+
}
173+
}
174+
if (posSEA != null && posNEA != null) {
175+
Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posNEA.x, posNEA.y, blockProjectileColor);
176+
177+
if (posSE != null) {
178+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSEA.x, posSEA.y, blockProjectileColor);
179+
}
180+
181+
if (posNE != null) {
182+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor);
183+
}
184+
}
185+
if (posSEA != null && posSWA != null) {
186+
Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posSWA.x, posSWA.y, blockProjectileColor);
187+
188+
if (posSE != null) {
189+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSEA.x, posSEA.y, blockProjectileColor);
190+
}
191+
192+
if (posSW != null) {
193+
Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posSWA.x, posSWA.y, blockProjectileColor);
194+
}
195+
}
196+
if (posSWA != null && posNWA != null) {
197+
Rasterizer.drawDiagonalLine(posSWA.x, posSWA.y, posNWA.x, posNWA.y, blockProjectileColor);
198+
199+
if (posSW != null) {
200+
Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posSWA.x, posSWA.y, blockProjectileColor);
201+
}
202+
203+
if (posNW != null) {
204+
Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor);
205+
}
206+
}
207+
}
208+
}
209+
}
210+
}
58211
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.runejs.client.frame.console.Commands;
2+
3+
import org.runejs.client.frame.DebugTools;
4+
import org.runejs.client.frame.console.Command;
5+
import org.runejs.client.frame.console.Console;
6+
7+
public class DebugClippingCommand extends Command {
8+
public DebugClippingCommand() {
9+
super(new String[]{"debugclip"}, "Toggles clipping rendering.");
10+
}
11+
12+
@Override
13+
public void execute(Console console, String[] cmdInput) {
14+
DebugTools.clippingEnabled = !DebugTools.clippingEnabled;
15+
if(DebugTools.clippingEnabled) {
16+
console.log("<col=00FF00>Clipping is now drawn.</col> <col=FF0000>Red = blocks walk.</col> <col=539FE9>Blue = blocks projectiles.</col>");
17+
} else {
18+
console.log("<col=FF0000>Clipping is now hidden</col>");
19+
}
20+
}
21+
}

src/main/java/org/runejs/client/frame/console/Console.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private void initialiseCommands() {
6161
commands.add(new AlphaCommand());
6262
commands.add(new ClearCommand());
6363
commands.add(new DebugCommand());
64+
commands.add(new DebugClippingCommand());
6465
commands.add(new DebugViewCommand());
6566
commands.add(new DebugWalkCommand());
6667
commands.add(new DebugWidgetsCommand());

src/main/java/org/runejs/client/scene/util/CollisionMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public void unmarkWall(int x, int y, int position, int orientation, boolean impe
515515
public void markBlocked(int y, int x) {
516516
x -= insetX;
517517
y -= insetY;
518-
clippingData[x][y] = BitUtils.bitWiseOR(clippingData[x][y], 2097152);
518+
clippingData[x][y] = BitUtils.bitWiseOR(clippingData[x][y], 0x200000);
519519
}
520520

521521
public boolean reachedFacingObject(int currentX, int currentY, int goalX, int goalY, int goalDX, int goalDY, int surroundings) {
@@ -643,7 +643,7 @@ public boolean reachedWall(int currentX, int currentY, int goalX, int goalY, int
643643
}
644644

645645
public void orClipTable(int x, int y, int flag) {
646-
clippingData[x][y] = BitUtils.bitWiseAND(clippingData[x][y], -flag + 16777215);
646+
clippingData[x][y] = BitUtils.bitWiseAND(clippingData[x][y], -flag + 0xffffff);
647647
}
648648

649649
public boolean reachedWallDecoration(int currentX, int currentY, int goalX, int goalY, int goalPosition, int goalOrientation) {

0 commit comments

Comments
 (0)