From 20f49ac60031749978183f3104e125e50a37b37b Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 23 Aug 2019 18:58:50 -0400 Subject: [PATCH] v0.7.5: corrected some issues caused by LibGDX --- .../src/main/java/com/watabou/noosa/Game.java | 19 +++-------- .../java/com/watabou/utils/FileUtils.java | 12 ++++++- .../java/com/watabou/utils/SystemTime.java | 34 ------------------- .../shatteredpixeldungeon/Dungeon.java | 2 +- .../shatteredpixeldungeon/Rankings.java | 3 +- 5 files changed, 19 insertions(+), 51 deletions(-) delete mode 100644 SPD-classes/src/main/java/com/watabou/utils/SystemTime.java diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Game.java b/SPD-classes/src/main/java/com/watabou/noosa/Game.java index bf5b441ad..90323678d 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Game.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Game.java @@ -23,6 +23,7 @@ package com.watabou.noosa; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.utils.TimeUtils; import com.watabou.glscripts.Script; import com.watabou.gltextures.TextureCache; import com.watabou.glwrap.Blending; @@ -32,7 +33,6 @@ import com.watabou.input.KeyEvent; import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Sample; import com.watabou.utils.PlatformSupport; -import com.watabou.utils.SystemTime; import java.io.PrintWriter; import java.io.StringWriter; @@ -66,14 +66,10 @@ public class Game implements ApplicationListener { // New scene class protected static Class sceneClass; - // Current time in milliseconds - protected long now; - // Milliseconds passed since previous update - protected long step; - public static float timeScale = 1f; public static float elapsed = 0f; public static float timeTotal = 0f; + public static long realTime = 0; protected static InputHandler inputHandler; @@ -134,11 +130,6 @@ public class Game implements ApplicationListener { Gdx.gl.glFlush(); - SystemTime.tick(); - long rightNow = SystemTime.now; - step = (now == 0 ? 0 : rightNow - now); - now = rightNow; - step(); } @@ -156,8 +147,6 @@ public class Game implements ApplicationListener { @Override public void resume() { paused = false; - - now = 0; } public void finish(){ @@ -236,8 +225,10 @@ public class Game implements ApplicationListener { } protected void update() { - Game.elapsed = Game.timeScale * step * 0.001f; + Game.elapsed = Game.timeScale * Gdx.graphics.getDeltaTime(); Game.timeTotal += Game.elapsed; + + Game.realTime = TimeUtils.millis(); inputHandler.processAllEvents(); diff --git a/SPD-classes/src/main/java/com/watabou/utils/FileUtils.java b/SPD-classes/src/main/java/com/watabou/utils/FileUtils.java index 85909c50f..e06719829 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/FileUtils.java +++ b/SPD-classes/src/main/java/com/watabou/utils/FileUtils.java @@ -23,6 +23,7 @@ package com.watabou.utils; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.utils.GdxRuntimeException; import java.io.FileNotFoundException; import java.io.IOException; @@ -81,7 +82,16 @@ public class FileUtils { //only works for base path public static void bundleToFile( String fileName, Bundle bundle ) throws IOException{ - bundleToStream( Gdx.files.local(fileName).write(false), bundle); + try { + bundleToStream(Gdx.files.local(fileName).write(false), bundle); + } catch (GdxRuntimeException e){ + if (e.getCause() instanceof IOException){ + //we want to throw the underlying IOException, not the GdxRuntimeException + throw (IOException)e.getCause(); + } else { + throw e; + } + } } private static void bundleToStream( OutputStream output, Bundle bundle ) throws IOException{ diff --git a/SPD-classes/src/main/java/com/watabou/utils/SystemTime.java b/SPD-classes/src/main/java/com/watabou/utils/SystemTime.java deleted file mode 100644 index 410e52a6f..000000000 --- a/SPD-classes/src/main/java/com/watabou/utils/SystemTime.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Pixel Dungeon - * Copyright (C) 2012-2015 Oleg Dolya - * - * Shattered Pixel Dungeon - * Copyright (C) 2014-2019 Evan Debenham - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see - */ - -package com.watabou.utils; - -import com.badlogic.gdx.utils.TimeUtils; - -public class SystemTime { - - public static long now; - - public static void tick() { - now = TimeUtils.millis(); - } -} - diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 359665930..490ef932c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -474,7 +474,7 @@ public class Dungeon { private static final String QUESTS = "quests"; private static final String BADGES = "badges"; - public static void saveGame( int save ) throws IOException { + public static void saveGame( int save ) { try { Bundle bundle = new Bundle(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java index be402e2ec..cc5409322 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java @@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; +import com.watabou.noosa.Game; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; import com.watabou.utils.FileUtils; @@ -238,7 +239,7 @@ public enum Rankings { } catch (IOException e) { } } - + public static class Record implements Bundlable { private static final String CAUSE = "cause";