project: Mixins

This commit is contained in:
Owain van Brakel
2021-11-17 17:08:54 +01:00
parent 28a0106acc
commit 76f8cdaef1
3 changed files with 73 additions and 8 deletions

View File

@@ -282,6 +282,9 @@ public abstract class RSClientMixin implements RSClient
@Inject
public long lastNanoTime;
@Inject
public long delayNanoTime;
@Inject
private List<String> outdatedScripts = new ArrayList<>();
@@ -2445,6 +2448,30 @@ public abstract class RSClientMixin implements RSClient
{
posToCameraAngle(client.getMapAngle(), client.getCameraPitch());
}
else
{
delayNanoTime = 0L;
}
}
@Inject
public void setUnlockedFpsTarget(int var1)
{
if (var1 <= 0)
{
delayNanoTime = 0L;
}
else
{
delayNanoTime = 1000000000L / (long) var1;
}
}
@Inject
@Override
public long getUnlockedFpsTarget()
{
return delayNanoTime;
}
@Inject

View File

@@ -25,6 +25,7 @@
package net.runelite.mixins;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.api.mixins.Shadow;
@@ -37,6 +38,9 @@ public abstract class RSNanoClockMixin implements RSNanoClock
@Shadow("client")
private static RSClient client;
@Inject
private long tmpNanoTime;
@Copy("wait")
@Replace("wait")
public int copy$wait(int cycleDurationMillis, int var2)
@@ -49,16 +53,42 @@ public abstract class RSNanoClockMixin implements RSNanoClock
{
long nanoTime = System.nanoTime();
if (nanoTime < getLastTimeNano())
if (nanoTime >= getLastTimeNano() && nanoTime >= tmpNanoTime)
{
setLastTimeNano(nanoTime);
long cycleDuration;
long diff;
return 1;
if (client.getUnlockedFpsTarget() > 0L)
{
cycleDuration = nanoTime - tmpNanoTime;
diff = client.getUnlockedFpsTarget() - cycleDuration;
diff /= 1000000L;
if (diff > 0L)
{
try
{
if (diff % 10L == 0L)
{
Thread.sleep(diff - 1L);
Thread.sleep(1L);
}
else
{
long cycleDuration = (long) cycleDurationMillis * 1000000L;
long diff = nanoTime - getLastTimeNano();
Thread.sleep(diff);
}
}
catch (InterruptedException var22)
{
}
nanoTime = System.nanoTime();
}
}
tmpNanoTime = nanoTime;
cycleDuration = (long) cycleDurationMillis * 1000000L;
diff = nanoTime - getLastTimeNano();
int cycles = (int) (diff / cycleDuration);
@@ -71,6 +101,12 @@ public abstract class RSNanoClockMixin implements RSNanoClock
return cycles;
}
else
{
setLastTimeNano(tmpNanoTime = nanoTime);
return 1;
}
}
}
}

View File

@@ -1477,6 +1477,8 @@ public interface RSClient extends RSGameEngine, Client
boolean isUnlockedFps();
long getUnlockedFpsTarget();
void posToCameraAngle(int var0, int var1);
@Import("objectSounds")