mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-10 10:20:44 -07:00
Normalize camera movement rounding, created Camera class
This commit is contained in:
parent
143d14e960
commit
9701d3d1c8
17 changed files with 122 additions and 86 deletions
68
client/src/main/java/Camera.java
Normal file
68
client/src/main/java/Camera.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import org.openrs2.deob.annotation.OriginalMember;
|
||||
import org.openrs2.deob.annotation.Pc;
|
||||
|
||||
public class Camera {
|
||||
@OriginalMember(owner = "client!fl", name = "s", descriptor = "I")
|
||||
public static double pitchTarget = 128;
|
||||
|
||||
@OriginalMember(owner = "client!eg", name = "d", descriptor = "I")
|
||||
public static double yawTarget = 0;
|
||||
|
||||
public static int pitchDirection = -1;
|
||||
|
||||
public static int yawDirection = -1;
|
||||
|
||||
public static int getPitch() {
|
||||
return pitchDirection == 1 ? (int)Math.ceil(pitchTarget) : (int)pitchTarget;
|
||||
}
|
||||
|
||||
public static int getYaw() {
|
||||
return yawDirection == 1 ? (int)Math.floor(yawTarget) : (int)yawTarget;
|
||||
}
|
||||
|
||||
public static double mod(double a, double b) {
|
||||
return ((a % b) + b) % b;
|
||||
}
|
||||
|
||||
@OriginalMember(owner = "client!gn", name = "b", descriptor = "(B)V")
|
||||
public static void clampCameraAngle() {
|
||||
if (pitchTarget < 128) {
|
||||
pitchTarget = 128;
|
||||
}
|
||||
if (pitchTarget > 383) {
|
||||
pitchTarget = 383;
|
||||
}
|
||||
yawTarget = mod(yawTarget, 2047.0d);
|
||||
@Pc(33) int local33 = Static81.cameraX >> 7;
|
||||
@Pc(37) int local37 = Static111.cameraZ >> 7;
|
||||
@Pc(43) int local43 = Static207.method3685(Static55.level, Static81.cameraX, Static111.cameraZ);
|
||||
@Pc(45) int local45 = 0;
|
||||
@Pc(64) int local64;
|
||||
if (local33 > 3 && local37 > 3 && local33 < 100 && local37 < 100) {
|
||||
for (local64 = local33 - 4; local64 <= local33 + 4; local64++) {
|
||||
for (@Pc(73) int local73 = local37 - 4; local73 <= local37 + 4; local73++) {
|
||||
@Pc(80) int local80 = Static55.level;
|
||||
if (local80 < 3 && (Static12.tileSettings[1][local64][local73] & 0x2) == 2) {
|
||||
local80++;
|
||||
}
|
||||
@Pc(117) int local117 = (Static232.aByteArrayArrayArray13[local80][local64][local73] & 0xFF) * 8 + local43 - Static83.activeTileHeightMap[local80][local64][local73];
|
||||
if (local117 > local45) {
|
||||
local45 = local117;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
local64 = local45 * 192;
|
||||
if (local64 > 98048) {
|
||||
local64 = 98048;
|
||||
}
|
||||
if (local64 < 32768) {
|
||||
local64 = 32768;
|
||||
}
|
||||
if (Static234.anInt5245 < local64) {
|
||||
Static234.anInt5245 += (local64 - Static234.anInt5245) / 24;
|
||||
} else if (local64 < Static234.anInt5245) {
|
||||
Static234.anInt5245 += (local64 - Static234.anInt5245) / 80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -438,19 +438,27 @@ public abstract class GameShell extends Applet implements Runnable, FocusListene
|
|||
if (Keyboard.pressedKeys[Keyboard.KEY_UP] || Keyboard.pressedKeys[Keyboard.KEY_DOWN] || Keyboard.pressedKeys[Keyboard.KEY_LEFT] || Keyboard.pressedKeys[Keyboard.KEY_RIGHT]) {
|
||||
double vertical = calcRenderDelta(18.0d);
|
||||
if (Keyboard.pressedKeys[Keyboard.KEY_UP]) {
|
||||
Static72.pitchTarget += vertical;
|
||||
Camera.pitchDirection = 0;
|
||||
Camera.pitchTarget += vertical;
|
||||
} else if (Keyboard.pressedKeys[Keyboard.KEY_DOWN]) {
|
||||
Static72.pitchTarget -= vertical;
|
||||
Camera.pitchDirection = 1;
|
||||
Camera.pitchTarget -= vertical;
|
||||
} else {
|
||||
Camera.pitchDirection = -1;
|
||||
}
|
||||
|
||||
double horizontal = calcRenderDelta(24.0d);
|
||||
if (Keyboard.pressedKeys[Keyboard.KEY_LEFT]) {
|
||||
Static57.yawTarget -= horizontal;
|
||||
Camera.yawDirection = 1;
|
||||
Camera.yawTarget -= horizontal;
|
||||
} else if (Keyboard.pressedKeys[Keyboard.KEY_RIGHT]) {
|
||||
Static57.yawTarget += horizontal;
|
||||
Camera.yawDirection = 0;
|
||||
Camera.yawTarget += horizontal;
|
||||
} else {
|
||||
Camera.yawDirection = -1;
|
||||
}
|
||||
|
||||
Static87.clampCameraAngle();
|
||||
Camera.clampCameraAngle();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,10 +44,14 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis
|
|||
int accelY = this.mouseWheelY - y;
|
||||
this.mouseWheelX = x;
|
||||
this.mouseWheelY = y;
|
||||
Static57.yawTarget += accelX * 2;
|
||||
Static72.pitchTarget -= (accelY << 1);
|
||||
Camera.yawDirection = -1;
|
||||
Camera.yawTarget += accelX * 2;
|
||||
Camera.pitchDirection = -1;
|
||||
Camera.pitchTarget -= accelY * 2;
|
||||
Camera.clampCameraAngle();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Static93.instance != null) {
|
||||
Static93.anInt2467 = 0;
|
||||
Static147.anInt3521 = x;
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ public final class Static103 {
|
|||
} else if (Static102.method2075(Static173.self.movementQueueZ[0], 0, 0, true, 0, local15, 0, 0, 1, local19, Static173.self.movementQueueX[0])) {
|
||||
Static6.outboundBuffer.p1(Static1.anInt5);
|
||||
Static6.outboundBuffer.p1(Static107.anInt2878);
|
||||
Static6.outboundBuffer.p2((int)Static57.yawTarget);
|
||||
Static6.outboundBuffer.p2(Camera.getYaw());
|
||||
Static6.outboundBuffer.p1(57);
|
||||
Static6.outboundBuffer.p1(Static59.anInt1814);
|
||||
Static6.outboundBuffer.p1(Static273.anInt4130);
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ public final class Static160 {
|
|||
Static129.method2504(arg0, arg1, arg2.anIntArray37, arg2.anIntArray45);
|
||||
}
|
||||
} else if (GlRenderer.enabled) {
|
||||
((GlSprite) Static106.aClass3_Sub2_Sub1_7).method1427(arg0, arg1, arg2.anInt445, arg2.anInt459, Static106.aClass3_Sub2_Sub1_7.anInt1867 / 2, Static106.aClass3_Sub2_Sub1_7.anInt1859 / 2, (int)Static57.yawTarget, 256, (GlSprite) arg2.method489(false));
|
||||
((GlSprite) Static106.aClass3_Sub2_Sub1_7).method1427(arg0, arg1, arg2.anInt445, arg2.anInt459, Static106.aClass3_Sub2_Sub1_7.anInt1867 / 2, Static106.aClass3_Sub2_Sub1_7.anInt1859 / 2, Camera.getYaw(), 256, (GlSprite) arg2.method489(false));
|
||||
} else {
|
||||
((SoftwareSprite) Static106.aClass3_Sub2_Sub1_7).method313(arg0, arg1, arg2.anInt445, arg2.anInt459, Static106.aClass3_Sub2_Sub1_7.anInt1867 / 2, Static106.aClass3_Sub2_Sub1_7.anInt1859 / 2, (int)Static57.yawTarget, arg2.anIntArray37, arg2.anIntArray45);
|
||||
((SoftwareSprite) Static106.aClass3_Sub2_Sub1_7).method313(arg0, arg1, arg2.anInt445, arg2.anInt459, Static106.aClass3_Sub2_Sub1_7.anInt1867 / 2, Static106.aClass3_Sub2_Sub1_7.anInt1859 / 2, Camera.getYaw(), arg2.anIntArray37, arg2.anIntArray45);
|
||||
}
|
||||
Static31.aBooleanArray29[arg3] = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public final class Static243 {
|
|||
Static260.anInt5014 = 0;
|
||||
Static132.anInt3291 = (int) (Math.random() * 100.0D) - 50;
|
||||
Static84.anInt2255 = 0;
|
||||
Static57.yawTarget = (int) (Math.random() * 20.0D) - 10 & 0x7FF;
|
||||
Camera.yawTarget = (int) (Math.random() * 20.0D) - 10 & 0x7FF;
|
||||
Static107.anInt2875 = -1;
|
||||
Static267.anInt5774 = 0;
|
||||
Static270.anInt5795 = 0;
|
||||
|
|
|
|||
|
|
@ -51,16 +51,20 @@ public final class Static250 {
|
|||
for (@Pc(93) int local93 = 0; local93 < Static182.keyQueueSize; local93++) {
|
||||
@Pc(104) int code = Static227.keyCodes[local93];
|
||||
if (code == Keyboard.KEY_UP) {
|
||||
Static72.pitchTarget = (int)Static72.pitchTarget + 47 & 0xFFFFFFF0;
|
||||
Camera.pitchDirection = 1;
|
||||
Camera.pitchTarget = Camera.getPitch() + 47 & 0xFFFFFFF0;
|
||||
} else if (code == Keyboard.KEY_DOWN) {
|
||||
Static72.pitchTarget = (int)Static72.pitchTarget - 17 & 0xFFFFFFF0;
|
||||
Camera.pitchDirection = 0;
|
||||
Camera.pitchTarget = Camera.getPitch() - 17 & 0xFFFFFFF0;
|
||||
} else if (code == Keyboard.KEY_LEFT) {
|
||||
Static57.yawTarget = (int)Static57.yawTarget - 65 & 0xFFFFFF80;
|
||||
Camera.yawDirection = 1;
|
||||
Camera.yawTarget = Camera.getYaw() - 65 & 0xFFFFFF80;
|
||||
} else if (code == Keyboard.KEY_RIGHT) {
|
||||
Static57.yawTarget = (int)Static57.yawTarget + 191 & 0xFFFFFF80;
|
||||
Camera.yawDirection = 0;
|
||||
Camera.yawTarget = Camera.getYaw() + 191 & 0xFFFFFF80;
|
||||
}
|
||||
}
|
||||
Static87.clampCameraAngle();
|
||||
Camera.clampCameraAngle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ public final class Static253 {
|
|||
@Pc(59) int local59;
|
||||
@Pc(57) int local57;
|
||||
if (Static227.cameraType == 1) {
|
||||
local57 = Static230.anInt5161 + (int)Static57.yawTarget & 0x7FF;
|
||||
local59 = (int)Static72.pitchTarget;
|
||||
local57 = Static230.anInt5161 + Camera.getYaw() & 0x7FF;
|
||||
local59 = Camera.getPitch();
|
||||
if (local59 < Static234.anInt5245 / 256) {
|
||||
local59 = Static234.anInt5245 / 256;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -697,13 +697,13 @@ public final class Static4 {
|
|||
local786 = Static57.aClass3_Sub15_Sub1_3.g2();
|
||||
local864 = Static57.aClass3_Sub15_Sub1_3.g2();
|
||||
if (Static248.method3288(local786)) {
|
||||
Static57.yawTarget = local133;
|
||||
Static72.pitchTarget = local864;
|
||||
Camera.yawTarget = local133;
|
||||
Camera.pitchTarget = local864;
|
||||
if (Static227.cameraType == 2) {
|
||||
Static240.cameraPitch = (int)Static72.pitchTarget;
|
||||
Static184.cameraYaw = (int)Static57.yawTarget;
|
||||
Static240.cameraPitch = Camera.getPitch();
|
||||
Static184.cameraYaw = Camera.getYaw();
|
||||
}
|
||||
Static87.clampCameraAngle();
|
||||
Camera.clampCameraAngle();
|
||||
}
|
||||
Static164.anInt3985 = -1;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public final class Static54 {
|
|||
Static129.method2496(arg2, arg1, arg2 + arg3.anInt445, arg1 + arg3.anInt459);
|
||||
}
|
||||
if (Static270.anInt5795 != 2 && Static270.anInt5795 != 5 && Static89.aClass3_Sub2_Sub1_5 != null) {
|
||||
@Pc(48) int local48 = Static59.anInt1814 + (int)Static57.yawTarget & 0x7FF;
|
||||
@Pc(48) int local48 = Static59.anInt1814 + Camera.getYaw() & 0x7FF;
|
||||
@Pc(57) int local57 = Static173.self.anInt3412 / 32 + 48;
|
||||
@Pc(67) int local67 = 464 - Static173.self.anInt3421 / 32;
|
||||
if (GlRenderer.enabled) {
|
||||
|
|
|
|||
|
|
@ -9,10 +9,7 @@ public final class Static57 {
|
|||
@OriginalMember(owner = "client!eg", name = "t", descriptor = "I")
|
||||
public static int anInt1757;
|
||||
|
||||
@OriginalMember(owner = "client!eg", name = "d", descriptor = "I")
|
||||
public static double yawTarget = 0;
|
||||
|
||||
@OriginalMember(owner = "client!eg", name = "e", descriptor = "Lclient!i;")
|
||||
@OriginalMember(owner = "client!eg", name = "e", descriptor = "Lclient!i;")
|
||||
public static final Packet aClass3_Sub15_Sub1_3 = new Packet(65536);
|
||||
|
||||
@OriginalMember(owner = "client!eg", name = "v", descriptor = "I")
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public final class Static60 {
|
|||
return;
|
||||
}
|
||||
@Pc(21) int local21 = arg3 * arg3 + arg2 * arg2;
|
||||
@Pc(27) int local27 = Static59.anInt1814 + (int)Static57.yawTarget & 0x7FF;
|
||||
@Pc(27) int local27 = Static59.anInt1814 + Camera.getYaw() & 0x7FF;
|
||||
@Pc(39) int local39 = Math.max(arg0.anInt445 / 2, arg0.anInt459 / 2) + 10;
|
||||
if (local39 * local39 < local21) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -13,10 +13,7 @@ public final class Static72 {
|
|||
@OriginalMember(owner = "client!fl", name = "D", descriptor = "[[I")
|
||||
public static int[][] regionsXteaKeys;
|
||||
|
||||
@OriginalMember(owner = "client!fl", name = "s", descriptor = "I")
|
||||
public static double pitchTarget = 128;
|
||||
|
||||
@OriginalMember(owner = "client!fl", name = "B", descriptor = "I")
|
||||
@OriginalMember(owner = "client!fl", name = "B", descriptor = "I")
|
||||
public static int updatedVarcstrsWriterIndex = 0;
|
||||
|
||||
@OriginalMember(owner = "client!fl", name = "H", descriptor = "Lclient!na;")
|
||||
|
|
|
|||
|
|
@ -243,8 +243,8 @@ public final class Static81 {
|
|||
Static16.anInt551 = 20;
|
||||
Static197.aBoolean228 = false;
|
||||
Static6.outboundBuffer.p1isaac(21);
|
||||
Static6.outboundBuffer.p2add((int)Static72.pitchTarget);
|
||||
Static6.outboundBuffer.p2le((int)Static57.yawTarget);
|
||||
Static6.outboundBuffer.p2add(Camera.getPitch());
|
||||
Static6.outboundBuffer.p2le(Camera.getYaw());
|
||||
}
|
||||
if (GameShell.focus && !Static67.prevFocus) {
|
||||
Static67.prevFocus = true;
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ public final class Static87 {
|
|||
continue;
|
||||
}
|
||||
local276 -= local30.anInt459 / 2;
|
||||
local503 = (int)Static57.yawTarget + Static59.anInt1814 & 0x7FF;
|
||||
local503 = Camera.getYaw() + Static59.anInt1814 & 0x7FF;
|
||||
local270 -= local30.anInt445 / 2;
|
||||
local514 = MathUtils.anIntArray223[local503];
|
||||
local518 = MathUtils.anIntArray225[local503];
|
||||
|
|
@ -892,48 +892,6 @@ public final class Static87 {
|
|||
}
|
||||
}
|
||||
|
||||
@OriginalMember(owner = "client!gn", name = "b", descriptor = "(B)V")
|
||||
public static void clampCameraAngle() {
|
||||
if (Static72.pitchTarget < 128) {
|
||||
Static72.pitchTarget = 128;
|
||||
}
|
||||
if (Static72.pitchTarget > 383) {
|
||||
Static72.pitchTarget = 383;
|
||||
}
|
||||
Static57.yawTarget = (int)Static57.yawTarget & 2047;
|
||||
@Pc(33) int local33 = Static81.cameraX >> 7;
|
||||
@Pc(37) int local37 = Static111.cameraZ >> 7;
|
||||
@Pc(43) int local43 = Static207.method3685(Static55.level, Static81.cameraX, Static111.cameraZ);
|
||||
@Pc(45) int local45 = 0;
|
||||
@Pc(64) int local64;
|
||||
if (local33 > 3 && local37 > 3 && local33 < 100 && local37 < 100) {
|
||||
for (local64 = local33 - 4; local64 <= local33 + 4; local64++) {
|
||||
for (@Pc(73) int local73 = local37 - 4; local73 <= local37 + 4; local73++) {
|
||||
@Pc(80) int local80 = Static55.level;
|
||||
if (local80 < 3 && (Static12.tileSettings[1][local64][local73] & 0x2) == 2) {
|
||||
local80++;
|
||||
}
|
||||
@Pc(117) int local117 = (Static232.aByteArrayArrayArray13[local80][local64][local73] & 0xFF) * 8 + local43 - Static83.activeTileHeightMap[local80][local64][local73];
|
||||
if (local117 > local45) {
|
||||
local45 = local117;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
local64 = local45 * 192;
|
||||
if (local64 > 98048) {
|
||||
local64 = 98048;
|
||||
}
|
||||
if (local64 < 32768) {
|
||||
local64 = 32768;
|
||||
}
|
||||
if (Static234.anInt5245 < local64) {
|
||||
Static234.anInt5245 += (local64 - Static234.anInt5245) / 24;
|
||||
} else if (local64 < Static234.anInt5245) {
|
||||
Static234.anInt5245 += (local64 - Static234.anInt5245) / 80;
|
||||
}
|
||||
}
|
||||
|
||||
@OriginalMember(owner = "client!gn", name = "a", descriptor = "(IZI)I")
|
||||
public static int method1814(@OriginalArg(0) int arg0, @OriginalArg(2) int arg1) {
|
||||
if (arg1 == -1) {
|
||||
|
|
|
|||
|
|
@ -3102,21 +3102,21 @@ public final class Static88 {
|
|||
}
|
||||
if (opcode == 5504) {
|
||||
isp -= 2;
|
||||
Static72.pitchTarget = Static254.intStack[isp];
|
||||
Static57.yawTarget = Static254.intStack[isp + 1];
|
||||
Camera.pitchTarget = Static254.intStack[isp];
|
||||
Camera.yawTarget = Static254.intStack[isp + 1];
|
||||
if (Static227.cameraType == 2) {
|
||||
Static184.cameraYaw = (int)Static57.yawTarget;
|
||||
Static240.cameraPitch = (int)Static72.pitchTarget;
|
||||
Static184.cameraYaw = Camera.getYaw();
|
||||
Static240.cameraPitch = Camera.getPitch();
|
||||
}
|
||||
Static87.clampCameraAngle();
|
||||
Camera.clampCameraAngle();
|
||||
continue;
|
||||
}
|
||||
if (opcode == 5505) {
|
||||
Static254.intStack[isp++] = (int)Static72.pitchTarget;
|
||||
Static254.intStack[isp++] = Camera.getPitch();
|
||||
continue;
|
||||
}
|
||||
if (opcode == 5506) {
|
||||
Static254.intStack[isp++] = (int)Static57.yawTarget;
|
||||
Static254.intStack[isp++] = Camera.getYaw();
|
||||
continue;
|
||||
}
|
||||
} else if (opcode < 5700) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public final class Static97 {
|
|||
return;
|
||||
}
|
||||
local30 -= 10;
|
||||
@Pc(58) int local58 = Static59.anInt1814 + (int)Static57.yawTarget & 0x7FF;
|
||||
@Pc(58) int local58 = Static59.anInt1814 + Camera.getYaw() & 0x7FF;
|
||||
@Pc(62) int local62 = MathUtils.anIntArray225[local58];
|
||||
@Pc(66) int local66 = MathUtils.anIntArray223[local58];
|
||||
@Pc(74) int local74 = local66 * 256 / (Static273.anInt4130 + 256);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue