v0.7.1: adjusted some specific elements of how the game handles time

This commit is contained in:
Evan Debenham 2018-12-15 14:03:32 -05:00 committed by Evan Debenham
parent 738a0e91e3
commit bf5e12e9d3

View File

@ -59,11 +59,21 @@ public abstract class Actor implements Bundlable {
protected void spend( float time ) { protected void spend( float time ) {
this.time += 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 ) { protected void postpone( float time ) {
if (this.time < now + time) { if (this.time < now + time) {
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(); ids.clear();
} }
public static synchronized void fixTime() { public static synchronized void fixTime() {
if (Dungeon.hero != null && all.contains( Dungeon.hero )) {
Statistics.duration += now;
}
float min = Float.MAX_VALUE; float min = Float.MAX_VALUE;
for (Actor a : all) { for (Actor a : all) {
if (a.time < min) { if (a.time < min) {
min = a.time; 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) { for (Actor a : all) {
a.time -= min; a.time -= min;
} }
if (Dungeon.hero != null && all.contains( Dungeon.hero )) {
Statistics.duration += (int)now;
}
now = 0; now = 0;
} }
@ -320,8 +334,8 @@ public abstract class Actor implements Bundlable {
} }
public static synchronized HashSet<Actor> all() { public static synchronized HashSet<Actor> all() {
return new HashSet<Actor>(all); return new HashSet<>(all);
} }
public static synchronized HashSet<Char> chars() { return new HashSet<Char>(chars); } public static synchronized HashSet<Char> chars() { return new HashSet<>(chars); }
} }