Skip to content

Commit

Permalink
Merge pull request #39 from Skrelpoid/develop
Browse files Browse the repository at this point in the history
Fix errors on steam deck / with --imgui
  • Loading branch information
Skrelpoid authored Jan 14, 2023
2 parents ed651fa + daa67ab commit 1d34022
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/main/java/skrelpoid/superfastmode/SuperFastMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.backends.lwjgl.LwjglGraphics;
import com.badlogic.gdx.graphics.Color;
import com.evacipated.cardcrawl.modthespire.Loader;
import com.evacipated.cardcrawl.modthespire.lib.SpireConfig;
import com.evacipated.cardcrawl.modthespire.lib.SpireInitializer;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
Expand Down Expand Up @@ -43,6 +44,9 @@ public static void initialize() {
initConfig();
loadConfig();
deltaField = LwjglGraphics.class.getDeclaredField("deltaTime");
if (Loader.LWJGL3_ENABLED) {
deltaField = Class.forName("com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics").getDeclaredField("deltaTime");
}
deltaField.setAccessible(true);
} catch (Exception ex) {
logger.catching(ex);
Expand Down Expand Up @@ -94,6 +98,16 @@ public static float getDelta(float max) {
return Math.min(max, getDelta());
}

/**
* This is the so called Raw Delta Time, or delta time before multiplying.
* This is because we get the value from the deltaTime Field of the graphics object.
* We patch the getDeltaTime of Graphics to override that logic to always be multiplied.
* This method gets called by the game. The internal field is an implementation detail we use to
* have both the modified and the unmodified delta
*
* @param graphics The Graphics object to get the delta from
* @return the unmodified delta time
*/
public static float getDelta(Graphics graphics) {
float delta = 0.016f;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
public class LwjglGraphicsPatches {

@SpirePatch(clz = com.badlogic.gdx.backends.lwjgl.LwjglGraphics.class, method = "getDeltaTime")
// If --imgui is set or StS is started on a steam deck, lwjgl3 is loaded instead
@SpirePatch(cls = "com.badlogic.gdx.backends.lwjgl3.LwjglGraphics3", method = "getDeltaTime", optional = true)
public static class DeltaPatch {
public static ExprEditor Instrument() {
return new ExprEditor() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/ModTheSpire.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"name": "SuperFastMode",
"author_list": ["Skrelpoid"],
"description": "Artificially speeds up the Game. Ingame, go to Mods>SuperFastMode>Config to change Settings.",
"version": "1.0.7",
"sts_version": "01-23-2019",
"mts_version": "3.6.3",
"version": "1.0.8",
"sts_version": "12-18-2022",
"mts_version": "3.30.0",
"dependencies": ["basemod"],
"update_json": "https://api.github.com/repos/Skrelpoid/SuperFastMode/releases/latest"
}

0 comments on commit 1d34022

Please sign in to comment.