mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-20 13:30:30 -07:00
Move camera movement out of update loop, delta time methods
This commit is contained in:
parent
72ab182425
commit
143d14e960
17 changed files with 71 additions and 52 deletions
|
|
@ -12,6 +12,8 @@ import org.openrs2.deob.annotation.Pc;
|
|||
@OriginalClass("client!rc")
|
||||
public abstract class GameShell extends Applet implements Runnable, FocusListener, WindowListener {
|
||||
|
||||
public static final long FIXED_UPDATE_RATE = 20;
|
||||
|
||||
@OriginalMember(owner = "client!sh", name = "l", descriptor = "[J")
|
||||
public static final long[] logicTimes = new long[32];
|
||||
|
||||
|
|
@ -82,9 +84,7 @@ public abstract class GameShell extends Applet implements Runnable, FocusListene
|
|||
public static int minimumDelay = 1;
|
||||
|
||||
@OriginalMember(owner = "client!ba", name = "B", descriptor = "I")
|
||||
public static int timePerFrame = 20;
|
||||
|
||||
public static int FIXED_UPDATE_RATE = 20;
|
||||
public static long VARIABLE_RENDER_RATE = 20;
|
||||
|
||||
@OriginalMember(owner = "client!cm", name = "b", descriptor = "Ljava/lang/Thread;")
|
||||
public static Thread thread;
|
||||
|
|
@ -125,6 +125,10 @@ public abstract class GameShell extends Applet implements Runnable, FocusListene
|
|||
|
||||
public static double subpixelY = 0.5d;
|
||||
|
||||
public static long updateDelta = 0;
|
||||
|
||||
public static long renderDelta = 0;
|
||||
|
||||
@OriginalMember(owner = "client!rc", name = "providesignlink", descriptor = "(Lsignlink!ll;)V")
|
||||
public static void providesignlink(@OriginalArg(0) SignLink signLink) {
|
||||
GameShell.signLink = signLink;
|
||||
|
|
@ -422,6 +426,34 @@ public abstract class GameShell extends Applet implements Runnable, FocusListene
|
|||
}
|
||||
}
|
||||
|
||||
public double calcUpdateDelta(double value) {
|
||||
return value / 1_000_000_000.0d * (double) updateDelta * value;
|
||||
}
|
||||
|
||||
public double calcRenderDelta(double value) {
|
||||
return value / 1_000_000_000.0d * (double) renderDelta * value;
|
||||
}
|
||||
|
||||
public void mainInputLoop() {
|
||||
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;
|
||||
} else if (Keyboard.pressedKeys[Keyboard.KEY_DOWN]) {
|
||||
Static72.pitchTarget -= vertical;
|
||||
}
|
||||
|
||||
double horizontal = calcRenderDelta(24.0d);
|
||||
if (Keyboard.pressedKeys[Keyboard.KEY_LEFT]) {
|
||||
Static57.yawTarget -= horizontal;
|
||||
} else if (Keyboard.pressedKeys[Keyboard.KEY_RIGHT]) {
|
||||
Static57.yawTarget += horizontal;
|
||||
}
|
||||
|
||||
Static87.clampCameraAngle();
|
||||
}
|
||||
}
|
||||
|
||||
@OriginalMember(owner = "client!rc", name = "run", descriptor = "()V")
|
||||
@Override
|
||||
public final void run() {
|
||||
|
|
@ -474,17 +506,21 @@ public abstract class GameShell extends Applet implements Runnable, FocusListene
|
|||
long lastUpdateTime = 0;
|
||||
long lastDrawTime = 0;
|
||||
while (killTime == 0L) {
|
||||
long currentTime = MonotonicClock.currentTimeMillis();
|
||||
if (GameShell.killTime > currentTime) {
|
||||
if (GameShell.killTime > MonotonicClock.currentTimeMillis()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentTime - lastUpdateTime >= FIXED_UPDATE_RATE) {
|
||||
long currentTime = System.nanoTime();
|
||||
|
||||
updateDelta = currentTime - lastUpdateTime;
|
||||
if (updateDelta >= FIXED_UPDATE_RATE * 1_000_000) {
|
||||
this.mainLoopWrapper();
|
||||
lastUpdateTime = currentTime;
|
||||
}
|
||||
|
||||
if (currentTime - lastDrawTime >= timePerFrame) {
|
||||
renderDelta = currentTime - lastDrawTime;
|
||||
if (renderDelta >= VARIABLE_RENDER_RATE * 1_000_000) {
|
||||
this.mainInputLoop();
|
||||
this.mainRedrawWrapper();
|
||||
lastDrawTime = currentTime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(Static57.yawTarget);
|
||||
Static6.outboundBuffer.p2((int)Static57.yawTarget);
|
||||
Static6.outboundBuffer.p1(57);
|
||||
Static6.outboundBuffer.p1(Static59.anInt1814);
|
||||
Static6.outboundBuffer.p1(Static273.anInt4130);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public final class Static115 {
|
|||
|
||||
@OriginalMember(owner = "client!ja", name = "a", descriptor = "(II)V")
|
||||
public static void method2312(@OriginalArg(0) int arg0) {
|
||||
GameShell.timePerFrame = 1000 / arg0;
|
||||
GameShell.VARIABLE_RENDER_RATE = 1000 / arg0;
|
||||
}
|
||||
|
||||
@OriginalMember(owner = "client!ja", name = "a", descriptor = "(IIIIIZ)V")
|
||||
|
|
|
|||
|
|
@ -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, 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, (int)Static57.yawTarget, 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, 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, (int)Static57.yawTarget, arg2.anIntArray37, arg2.anIntArray45);
|
||||
}
|
||||
Static31.aBooleanArray29[arg3] = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,33 +51,16 @@ 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 = Static72.pitchTarget + 47 & 0xFFFFFFF0;
|
||||
Static72.pitchTarget = (int)Static72.pitchTarget + 47 & 0xFFFFFFF0;
|
||||
} else if (code == Keyboard.KEY_DOWN) {
|
||||
Static72.pitchTarget = Static72.pitchTarget - 17 & 0xFFFFFFF0;
|
||||
Static72.pitchTarget = (int)Static72.pitchTarget - 17 & 0xFFFFFFF0;
|
||||
} else if (code == Keyboard.KEY_LEFT) {
|
||||
Static57.yawTarget = Static57.yawTarget - 65 & 0xFFFFFF80;
|
||||
Static57.yawTarget = (int)Static57.yawTarget - 65 & 0xFFFFFF80;
|
||||
} else if (code == Keyboard.KEY_RIGHT) {
|
||||
Static57.yawTarget = Static57.yawTarget + 191 & 0xFFFFFF80;
|
||||
Static57.yawTarget = (int)Static57.yawTarget + 191 & 0xFFFFFF80;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Keyboard.pressedKeys[Keyboard.KEY_UP]) {
|
||||
Static56.anInt1743 += (12 - Static56.anInt1743) / 2;
|
||||
} else if (Keyboard.pressedKeys[Keyboard.KEY_DOWN]) {
|
||||
Static56.anInt1743 += (-Static56.anInt1743 - 12) / 2;
|
||||
} else {
|
||||
Static56.anInt1743 /= 2;
|
||||
}
|
||||
if (Keyboard.pressedKeys[Keyboard.KEY_LEFT]) {
|
||||
Static38.anInt1203 += (-Static38.anInt1203 - 24) / 2;
|
||||
} else if (Keyboard.pressedKeys[Keyboard.KEY_RIGHT]) {
|
||||
Static38.anInt1203 += (24 - Static38.anInt1203) / 2;
|
||||
} else {
|
||||
Static38.anInt1203 /= 2;
|
||||
}
|
||||
Static72.pitchTarget += Static56.anInt1743 / 2;
|
||||
Static57.yawTarget += Static38.anInt1203 / 2;
|
||||
Static87.clampCameraAngle();
|
||||
}
|
||||
Static87.clampCameraAngle();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ public final class Static253 {
|
|||
@Pc(59) int local59;
|
||||
@Pc(57) int local57;
|
||||
if (Static227.cameraType == 1) {
|
||||
local57 = Static230.anInt5161 + Static57.yawTarget & 0x7FF;
|
||||
local59 = Static72.pitchTarget;
|
||||
local57 = Static230.anInt5161 + (int)Static57.yawTarget & 0x7FF;
|
||||
local59 = (int)Static72.pitchTarget;
|
||||
if (local59 < Static234.anInt5245 / 256) {
|
||||
local59 = Static234.anInt5245 / 256;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ public final class Static38 {
|
|||
public static int anInt1196 = 1;
|
||||
|
||||
@OriginalMember(owner = "client!cn", name = "L", descriptor = "I")
|
||||
public static int anInt1203 = 0;
|
||||
public static double yawAccel = 0;
|
||||
|
||||
@OriginalMember(owner = "client!cn", name = "a", descriptor = "(BIIIIIIII)V")
|
||||
public static void method959(@OriginalArg(1) int arg0, @OriginalArg(2) int arg1, @OriginalArg(3) int arg2, @OriginalArg(4) int arg3, @OriginalArg(5) int arg4, @OriginalArg(6) int arg5, @OriginalArg(7) int arg6, @OriginalArg(8) int arg7) {
|
||||
|
|
|
|||
|
|
@ -700,8 +700,8 @@ public final class Static4 {
|
|||
Static57.yawTarget = local133;
|
||||
Static72.pitchTarget = local864;
|
||||
if (Static227.cameraType == 2) {
|
||||
Static240.cameraPitch = Static72.pitchTarget;
|
||||
Static184.cameraYaw = Static57.yawTarget;
|
||||
Static240.cameraPitch = (int)Static72.pitchTarget;
|
||||
Static184.cameraYaw = (int)Static57.yawTarget;
|
||||
}
|
||||
Static87.clampCameraAngle();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 + Static57.yawTarget & 0x7FF;
|
||||
@Pc(48) int local48 = Static59.anInt1814 + (int)Static57.yawTarget & 0x7FF;
|
||||
@Pc(57) int local57 = Static173.self.anInt3412 / 32 + 48;
|
||||
@Pc(67) int local67 = 464 - Static173.self.anInt3421 / 32;
|
||||
if (GlRenderer.enabled) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public final class Static56 {
|
|||
public static final JagString aClass100_380 = Static28.parse("unzap");
|
||||
|
||||
@OriginalMember(owner = "client!ef", name = "i", descriptor = "I")
|
||||
public static int anInt1743 = 0;
|
||||
public static double pitchAccel = 0;
|
||||
|
||||
@OriginalMember(owner = "client!ef", name = "r", descriptor = "Lclient!be;")
|
||||
public static Component aClass13_12 = null;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public final class Static57 {
|
|||
public static int anInt1757;
|
||||
|
||||
@OriginalMember(owner = "client!eg", name = "d", descriptor = "I")
|
||||
public static int yawTarget = 0;
|
||||
public static double yawTarget = 0;
|
||||
|
||||
@OriginalMember(owner = "client!eg", name = "e", descriptor = "Lclient!i;")
|
||||
public static final Packet aClass3_Sub15_Sub1_3 = new Packet(65536);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public final class Static60 {
|
|||
return;
|
||||
}
|
||||
@Pc(21) int local21 = arg3 * arg3 + arg2 * arg2;
|
||||
@Pc(27) int local27 = Static59.anInt1814 + Static57.yawTarget & 0x7FF;
|
||||
@Pc(27) int local27 = Static59.anInt1814 + (int)Static57.yawTarget & 0x7FF;
|
||||
@Pc(39) int local39 = Math.max(arg0.anInt445 / 2, arg0.anInt459 / 2) + 10;
|
||||
if (local39 * local39 < local21) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public final class Static72 {
|
|||
public static int[][] regionsXteaKeys;
|
||||
|
||||
@OriginalMember(owner = "client!fl", name = "s", descriptor = "I")
|
||||
public static int pitchTarget = 128;
|
||||
public static double pitchTarget = 128;
|
||||
|
||||
@OriginalMember(owner = "client!fl", name = "B", descriptor = "I")
|
||||
public static int updatedVarcstrsWriterIndex = 0;
|
||||
|
|
|
|||
|
|
@ -243,8 +243,8 @@ public final class Static81 {
|
|||
Static16.anInt551 = 20;
|
||||
Static197.aBoolean228 = false;
|
||||
Static6.outboundBuffer.p1isaac(21);
|
||||
Static6.outboundBuffer.p2add(Static72.pitchTarget);
|
||||
Static6.outboundBuffer.p2le(Static57.yawTarget);
|
||||
Static6.outboundBuffer.p2add((int)Static72.pitchTarget);
|
||||
Static6.outboundBuffer.p2le((int)Static57.yawTarget);
|
||||
}
|
||||
if (GameShell.focus && !Static67.prevFocus) {
|
||||
Static67.prevFocus = true;
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ public final class Static87 {
|
|||
continue;
|
||||
}
|
||||
local276 -= local30.anInt459 / 2;
|
||||
local503 = Static57.yawTarget + Static59.anInt1814 & 0x7FF;
|
||||
local503 = (int)Static57.yawTarget + Static59.anInt1814 & 0x7FF;
|
||||
local270 -= local30.anInt445 / 2;
|
||||
local514 = MathUtils.anIntArray223[local503];
|
||||
local518 = MathUtils.anIntArray225[local503];
|
||||
|
|
@ -900,7 +900,7 @@ public final class Static87 {
|
|||
if (Static72.pitchTarget > 383) {
|
||||
Static72.pitchTarget = 383;
|
||||
}
|
||||
Static57.yawTarget &= 0x7FF;
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -3105,18 +3105,18 @@ public final class Static88 {
|
|||
Static72.pitchTarget = Static254.intStack[isp];
|
||||
Static57.yawTarget = Static254.intStack[isp + 1];
|
||||
if (Static227.cameraType == 2) {
|
||||
Static184.cameraYaw = Static57.yawTarget;
|
||||
Static240.cameraPitch = Static72.pitchTarget;
|
||||
Static184.cameraYaw = (int)Static57.yawTarget;
|
||||
Static240.cameraPitch = (int)Static72.pitchTarget;
|
||||
}
|
||||
Static87.clampCameraAngle();
|
||||
continue;
|
||||
}
|
||||
if (opcode == 5505) {
|
||||
Static254.intStack[isp++] = Static72.pitchTarget;
|
||||
Static254.intStack[isp++] = (int)Static72.pitchTarget;
|
||||
continue;
|
||||
}
|
||||
if (opcode == 5506) {
|
||||
Static254.intStack[isp++] = Static57.yawTarget;
|
||||
Static254.intStack[isp++] = (int)Static57.yawTarget;
|
||||
continue;
|
||||
}
|
||||
} else if (opcode < 5700) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public final class Static97 {
|
|||
return;
|
||||
}
|
||||
local30 -= 10;
|
||||
@Pc(58) int local58 = Static59.anInt1814 + Static57.yawTarget & 0x7FF;
|
||||
@Pc(58) int local58 = Static59.anInt1814 + (int)Static57.yawTarget & 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