From bf5e12e9d3dd9e73bcea4fc3b935195b4eaf7b39 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 15 Dec 2018 14:03:32 -0500 Subject: [PATCH] v0.7.1: adjusted some specific elements of how the game handles time --- .../shatteredpixeldungeon/actors/Actor.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java index 92cea2d02..8575552f1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -59,11 +59,21 @@ public abstract class Actor implements Bundlable { protected void spend( float time ) { this.time += time; + //if time is very close to a whole number, round to a whole number to fix errors + float ex = Math.abs(this.time % 1f); + if (ex < .001f){ + this.time = Math.round(this.time); + } } protected void postpone( float time ) { if (this.time < now + time) { this.time = now + time; + //if time is very close to a whole number, round to a whole number to fix errors + float ex = Math.abs(this.time % 1f); + if (ex < .001f){ + this.time = Math.round(this.time); + } } } @@ -123,22 +133,26 @@ public abstract class Actor implements Bundlable { ids.clear(); } - + public static synchronized void fixTime() { - - if (Dungeon.hero != null && all.contains( Dungeon.hero )) { - Statistics.duration += now; - } - + float min = Float.MAX_VALUE; for (Actor a : all) { if (a.time < min) { min = a.time; } } + + //Only pull everything back by whole numbers + //So that turns always align with a whole number + min = (int)min; for (Actor a : all) { a.time -= min; } + + if (Dungeon.hero != null && all.contains( Dungeon.hero )) { + Statistics.duration += (int)now; + } now = 0; } @@ -320,8 +334,8 @@ public abstract class Actor implements Bundlable { } public static synchronized HashSet all() { - return new HashSet(all); + return new HashSet<>(all); } - public static synchronized HashSet chars() { return new HashSet(chars); } + public static synchronized HashSet chars() { return new HashSet<>(chars); } }