Skip to content

Commit

Permalink
feat: True tile view + mes tick added to ::debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Pazaz committed Dec 22, 2023
1 parent e097105 commit 6f2c1e6
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 11 deletions.
72 changes: 69 additions & 3 deletions client/src/main/java/jagex2/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public final class Client extends GameShell {
private boolean showDebug = false;
private int chatEra = 2; // 0 - early beta, 1 - late beta, 2 - launch

/**
* Are we ticking or are we tocking?
*/
private boolean lastTickFlag = false;

@OriginalMember(owner = "client!client", name = "E", descriptor = "I")
public static int opHeld1Counter;

Expand Down Expand Up @@ -2286,10 +2291,10 @@ public void drawDebug() {
continue;
}

Draw2D.drawLine(x0, y0, x1, y1, color);
Draw2D.drawLine(x0, y0, x2, y2, color);
Draw2D.drawLine(x0, y0, x3, y3, (color & 0xFEFEFE) >> 1);
Draw2D.drawLine(x1, y1, x2, y2, (color & 0xFEFEFE) >> 1);
Draw2D.drawLine(x0, y0, x1, y1, color);
Draw2D.drawLine(x0, y0, x2, y2, color);
Draw2D.drawLine(x1, y1, x3, y3, color);
Draw2D.drawLine(x2, y2, x3, y3, color);
}
Expand Down Expand Up @@ -2318,8 +2323,65 @@ public void drawDebug() {

if (showOccluders) {
this.fontPlain11.drawStringRight(String.format("Occluders: %d Active: %d", World3D.levelOccluderCount[World3D.topLevel], World3D.activeOccluderCount), x, y, 0xFFFF00, true);
y += 13;
}
}

if (showDebug) {
if (lastTickFlag) {
this.fontPlain11.drawStringRight("tock", x, y, 0xFFFF00, true);
} else {
this.fontBold12.drawStringRight("tick", x, y, 0xFFFF00, true);
}

y += 13;
}

if (showDebug) {
// display true tile
if (this.localPlayer.pathLength > 0 || this.localPlayer.forceMoveEndCycle >= loopCycle || this.localPlayer.forceMoveStartCycle > loopCycle) {
this.drawTileOverlay(this.localPlayer.pathTileX[0] * 128 + 64, this.localPlayer.pathTileZ[0] * 128 + 64, this.currentLevel, 0x666666, true);
}

// display local client tile
this.drawTileOverlay(this.localPlayer.x, this.localPlayer.z, this.currentLevel, 0x444444, false);
}
}

private void drawTileOverlay(int x, int z, int level, int color, boolean crossed) {
int height = this.getHeightmapY(level, x, z);
int x0 = -1, y0 = -1;
int x1 = -1, y1 = -1;
int x2 = -1, y2 = -1;
int x3 = -1, y3 = -1;

// x/z should be the center of a tile which is 128 client-units large, so +/- 64 puts us at the edges
this.project(x - 64, height, z - 64);
x0 = this.projectX;
y0 = this.projectY;
this.project(x + 64, height, z - 64);
x1 = this.projectX;
y1 = this.projectY;
this.project(x - 64, height, z + 64);
x2 = this.projectX;
y2 = this.projectY;
this.project(x + 64, height, z + 64);
x3 = this.projectX;
y3 = this.projectY;

// one of our points failed to project
if ((x0 == -1) || (x1 == -1) || (x2 == -1) || (x3 == -1)) {
return;
}

if (crossed) {
Draw2D.drawLine(x0, y0, x3, y3, (color & 0xFEFEFE) >> 1);
Draw2D.drawLine(x1, y1, x2, y2, (color & 0xFEFEFE) >> 1);
}
Draw2D.drawLine(x0, y0, x1, y1, color);
Draw2D.drawLine(x0, y0, x2, y2, color);
Draw2D.drawLine(x1, y1, x3, y3, color);
Draw2D.drawLine(x2, y2, x3, y3, color);
}

@OriginalMember(owner = "client!client", name = "c", descriptor = "(Z)V")
private void runMidi() {
Expand Down Expand Up @@ -8055,6 +8117,9 @@ private void addMessage(@OriginalArg(0) int arg0, @OriginalArg(1) String arg1, @
this.messageSender[local20] = this.messageSender[local20 - 1];
this.messageText[local20] = this.messageText[local20 - 1];
}
if (showDebug && arg0 == 0) {
arg1 = "[" + (this.loopCycle / 30) + "]: " + arg1;
}
this.messageType[0] = arg0;
this.messageSender[0] = arg3;
this.messageText[0] = arg1;
Expand Down Expand Up @@ -10508,6 +10573,7 @@ private boolean read() {
return true;
}
if (this.packetType == 184) {
this.lastTickFlag = !this.lastTickFlag;
this.readPlayerInfo(this.in, this.packetSize);
if (this.sceneState == 1) {
this.sceneState = 2;
Expand Down
68 changes: 60 additions & 8 deletions webclient/src/main/java/jagex2/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2310,10 +2310,10 @@ public void drawDebug() {
continue;
}

Draw2D.drawLine(x0, y0, x1, y1, color);
Draw2D.drawLine(x0, y0, x2, y2, color);
Draw2D.drawLine(x0, y0, x3, y3, (color & 0xFEFEFE) >> 1);
Draw2D.drawLine(x1, y1, x2, y2, (color & 0xFEFEFE) >> 1);
Draw2D.drawLine(x0, y0, x1, y1, color);
Draw2D.drawLine(x0, y0, x2, y2, color);
Draw2D.drawLine(x1, y1, x3, y3, color);
Draw2D.drawLine(x2, y2, x3, y3, color);
}
Expand All @@ -2325,20 +2325,69 @@ public void drawDebug() {
if (showPerformance) {
this.fontPlain11.drawStringRight(String.format("FPS: %d", super.fps), x, y, 0xFFFF00, true);
y += 13;
}

if (showOccluders) {
this.fontPlain11.drawStringRight(String.format("Occluders: %d Active: %d", World3D.levelOccluderCount[World3D.topLevel], World3D.activeOccluderCount), x, y, 0xFFFF00, true);
y += 13;
}

if (showDebug) {
if (lastTickFlag) {
this.fontPlain11.drawStringRight("tock", x, y, 0xFFFF00, true);
} else {
this.fontBold12.drawStringRight("tick", x, y, 0xFFFF00, true);
}

y += 13;
}

if (showOccluders) {
this.fontPlain11.drawStringRight(String.format("Occluders: %d Active: %d", World3D.levelOccluderCount[World3D.topLevel], World3D.activeOccluderCount), x, y, 0xFFFF00, true);
}
}
}

if (showDebug) {
// display true tile
if (this.localPlayer.pathLength > 0 || this.localPlayer.forceMoveEndCycle >= loopCycle || this.localPlayer.forceMoveStartCycle > loopCycle) {
this.drawTileOverlay(this.localPlayer.pathTileX[0] * 128 + 64, this.localPlayer.pathTileZ[0] * 128 + 64, this.currentLevel, 0x666666, true);
}

// display local client tile
this.drawTileOverlay(this.localPlayer.x, this.localPlayer.z, this.currentLevel, 0x444444, false);
}
}

private void drawTileOverlay(int x, int z, int level, int color, boolean crossed) {
int height = this.getHeightmapY(level, x, z);
int x0 = -1, y0 = -1;
int x1 = -1, y1 = -1;
int x2 = -1, y2 = -1;
int x3 = -1, y3 = -1;

// x/z should be the center of a tile which is 128 client-units large, so +/- 64 puts us at the edges
this.project(x - 64, height, z - 64);
x0 = this.projectX;
y0 = this.projectY;
this.project(x + 64, height, z - 64);
x1 = this.projectX;
y1 = this.projectY;
this.project(x - 64, height, z + 64);
x2 = this.projectX;
y2 = this.projectY;
this.project(x + 64, height, z + 64);
x3 = this.projectX;
y3 = this.projectY;

// one of our points failed to project
if ((x0 == -1) || (x1 == -1) || (x2 == -1) || (x3 == -1)) {
return;
}

if (crossed) {
Draw2D.drawLine(x0, y0, x3, y3, (color & 0xFEFEFE) >> 1);
Draw2D.drawLine(x1, y1, x2, y2, (color & 0xFEFEFE) >> 1);
}
Draw2D.drawLine(x0, y0, x1, y1, color);
Draw2D.drawLine(x0, y0, x2, y2, color);
Draw2D.drawLine(x1, y1, x3, y3, color);
Draw2D.drawLine(x2, y2, x3, y3, color);
}

@OriginalMember(owner = "client!client", name = "c", descriptor = "(Z)V")
private void runMidi() {
Expand Down Expand Up @@ -8056,6 +8105,9 @@ private void addMessage(@OriginalArg(0) int arg0, @OriginalArg(1) String arg1, @
this.messageSender[local20] = this.messageSender[local20 - 1];
this.messageText[local20] = this.messageText[local20 - 1];
}
if (showDebug && arg0 == 0) {
arg1 = "[" + (this.loopCycle / 30) + "]: " + arg1;
}
this.messageType[0] = arg0;
this.messageSender[0] = arg3;
this.messageText[0] = arg1;
Expand Down

0 comments on commit 6f2c1e6

Please sign in to comment.