Skip to content

Commit d59f49d

Browse files
authored
Merge pull request #167 from runejs/debug-clipping-view
feat: create debugclip view to inspect clipping info
2 parents aa41061 + dab5ba1 commit d59f49d

File tree

5 files changed

+202
-2
lines changed

5 files changed

+202
-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: 162 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,164 @@ 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 int clippingRenderDistance = 0;
62+
63+
public static void drawClipping() {
64+
if (clippingRenderDistance == 0) {
65+
return;
66+
}
67+
68+
int tileX = Player.localPlayer.worldX >> 7;
69+
int tileY = Player.localPlayer.worldY >> 7;
70+
71+
for (int x = Math.max(0, tileX - clippingRenderDistance); x < Math.min(104, tileX + clippingRenderDistance); x++) {
72+
for (int y = Math.max(0, tileY - clippingRenderDistance); y < Math.min(104, tileY + clippingRenderDistance); y++) {
73+
int data = Landscape.currentCollisionMap[Player.worldLevel].clippingData[x][y];
74+
75+
// center of tile to avoid needless projection calcs in next step
76+
Point2d screenPos = MovedStatics.getProjectedScreenPosition(0, y * 128 + 64, x * 128 + 64);
77+
78+
if (screenPos == null) {
79+
continue;
80+
}
81+
82+
// ground-level points to indicate walkability
83+
Point2d posSW = MovedStatics.getProjectedScreenPosition(0, y * 128, x * 128);
84+
Point2d posNW = MovedStatics.getProjectedScreenPosition(0, y * 128 + 128, x * 128);
85+
Point2d posSE = MovedStatics.getProjectedScreenPosition(0, y * 128, x * 128 + 128);
86+
Point2d posNE = MovedStatics.getProjectedScreenPosition(0, y * 128 + 128, x * 128 + 128);
87+
88+
// mid-level points to indicate projectile shootability
89+
Point2d posSWA = MovedStatics.getProjectedScreenPosition(100, y * 128, x * 128);
90+
Point2d posNWA = MovedStatics.getProjectedScreenPosition(100, y * 128 + 128, x * 128);
91+
Point2d posSEA = MovedStatics.getProjectedScreenPosition(100, y * 128, x * 128 + 128);
92+
Point2d posNEA = MovedStatics.getProjectedScreenPosition(100, y * 128 + 128, x * 128 + 128);
93+
94+
int blockWalkColor = 0xFF0000;
95+
int blockProjectileColor = 0x539FE9;
96+
97+
if ((data & 0x2) == 0x2) { // north
98+
if (posNE != null && posNW != null) {
99+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNW.x, posNW.y, blockWalkColor);
100+
}
101+
}
102+
103+
if ((data & 0x8) == 0x8) { // east
104+
if (posSE != null && posNE != null) {
105+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posNE.x, posNE.y, blockWalkColor);
106+
}
107+
}
108+
109+
if ((data & 0x20) == 0x20) { // south
110+
if (posSE != null && posSW != null) {
111+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSW.x, posSW.y, blockWalkColor);
112+
}
113+
}
114+
115+
if ((data & 0x80) == 0x80) { // west
116+
if (posSW != null && posNW != null) {
117+
Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posNW.x, posNW.y, blockWalkColor);
118+
}
119+
}
120+
121+
if ((data & 0x100) == 0x100) { // total block
122+
if (posNE != null && posNW != null) {
123+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNW.x, posNW.y, blockWalkColor);
124+
}
125+
if (posSE != null && posNE != null) {
126+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posNE.x, posNE.y, blockWalkColor);
127+
}
128+
if (posSE != null && posSW != null) {
129+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSW.x, posSW.y, blockWalkColor);
130+
}
131+
if (posSW != null && posNW != null) {
132+
Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posNW.x, posNW.y, blockWalkColor);
133+
}
134+
}
135+
136+
// below this are projectiles. these draw more lines than the ground-level ones,
137+
// because there are vertical bars to join them to the ground
138+
139+
if ((data & 0x400) == 0x400) { // north (projectile)
140+
if (posNEA != null && posNWA != null) {
141+
Rasterizer.drawDiagonalLine(posNEA.x, posNEA.y, posNWA.x, posNWA.y, blockProjectileColor);
142+
143+
if (posNE != null) {
144+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor);
145+
}
146+
147+
if (posNW != null) {
148+
Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor);
149+
}
150+
}
151+
}
152+
153+
if ((data & 0x1000) == 0x1000) { // east (projectile)
154+
if (posSEA != null && posNEA != null) {
155+
Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posNEA.x, posNEA.y, blockProjectileColor);
156+
}
157+
}
158+
159+
if ((data & 0x4000) == 0x4000) { // south (projectile)
160+
if (posSEA != null && posSWA != null) {
161+
Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posSWA.x, posSWA.y, blockProjectileColor);
162+
}
163+
}
164+
165+
if ((data & 0x10000) == 0x10000) { // west (projectile)
166+
if (posSWA != null && posNWA != null) {
167+
Rasterizer.drawDiagonalLine(posSWA.x, posSWA.y, posNWA.x, posNWA.y, blockProjectileColor);
168+
}
169+
}
170+
171+
if ((data & 0x20000) == 0x20000) { // total block (projectile)
172+
if (posNEA != null && posNWA != null) {
173+
Rasterizer.drawDiagonalLine(posNEA.x, posNEA.y, posNWA.x, posNWA.y, blockProjectileColor);
174+
175+
if (posNE != null) {
176+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor);
177+
}
178+
179+
if (posNW != null) {
180+
Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor);
181+
}
182+
}
183+
if (posSEA != null && posNEA != null) {
184+
Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posNEA.x, posNEA.y, blockProjectileColor);
185+
186+
if (posSE != null) {
187+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSEA.x, posSEA.y, blockProjectileColor);
188+
}
189+
190+
if (posNE != null) {
191+
Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor);
192+
}
193+
}
194+
if (posSEA != null && posSWA != null) {
195+
Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posSWA.x, posSWA.y, blockProjectileColor);
196+
197+
if (posSE != null) {
198+
Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSEA.x, posSEA.y, blockProjectileColor);
199+
}
200+
201+
if (posSW != null) {
202+
Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posSWA.x, posSWA.y, blockProjectileColor);
203+
}
204+
}
205+
if (posSWA != null && posNWA != null) {
206+
Rasterizer.drawDiagonalLine(posSWA.x, posSWA.y, posNWA.x, posNWA.y, blockProjectileColor);
207+
208+
if (posSW != null) {
209+
Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posSWA.x, posSWA.y, blockProjectileColor);
210+
}
211+
212+
if (posNW != null) {
213+
Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor);
214+
}
215+
}
216+
}
217+
}
218+
}
219+
}
58220
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
boolean radiusProvided = cmdInput.length == 2;
15+
int radius = radiusProvided ? Integer.parseInt(cmdInput[1]) : 10;
16+
17+
if (DebugTools.clippingRenderDistance != 0) {
18+
if (!radiusProvided) {
19+
console.log("<col=FF0000>Clipping is now hidden</col>");
20+
DebugTools.clippingRenderDistance = 0;
21+
return;
22+
}
23+
24+
DebugTools.clippingRenderDistance = radius;
25+
console.log("<col=FF0000>Radius updated to: " + radius + "</col>");
26+
return;
27+
}
28+
29+
DebugTools.clippingRenderDistance = radius;
30+
console.log("<col=00FF00>Clipping is now drawn.</col> <col=FF0000>Red = blocks walk.</col> <col=539FE9>Blue = blocks projectiles.</col>");
31+
32+
if (!radiusProvided) {
33+
console.log("Using default radius: " + radius + ". You can use e.g. `debugclip 15` to increase radius to 15.");
34+
}
35+
}
36+
}

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)