diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index d2f484760..eba223263 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -343,7 +343,6 @@ public class App implements ApplicationListener { public static InputStrober inputStrober; public static long bogoflops = 0L; - private static double bogoflopf = Math.random(); public static boolean hasUpdate = true; @@ -362,20 +361,33 @@ public class App implements ApplicationListener { public static long loadedTime_t; - public static void main(String[] args) { - loadedTime_t = getTIME_T(); - + public static void updateBogoflops(long iteration) { + long iters = 0; + double a = 1.000001; + double b = 1.000002; + double c = 1.000003; long st = System.nanoTime(); long sc = st; - while (sc - st < 100000000L) { - bogoflopf = Math.random() * bogoflopf; - bogoflops++; + + while (sc - st < iteration) { + // burn ALU cycles + a = a * b + c; + b = b * c + a; + c = c * a + b; + + iters += 3; // roughly count flops sc = System.nanoTime(); } - bogoflops = Math.round((double)(bogoflops) * (1000000000.0 / (sc - st))); -// System.out.println(sc - st); -// System.out.println(bogoflops); + + // divide by 4 to make it roughly match up with the old calibrated worldgen estimator + bogoflops = Math.round((iters * (1e9 / (sc - st))) / 4); + } + + public static void main(String[] args) { + loadedTime_t = getTIME_T(); + + updateBogoflops(100_000_000L); // if -ea flag is set, turn on all the debug prints try { diff --git a/src/net/torvald/terrarum/gameworld/WorldTime.kt b/src/net/torvald/terrarum/gameworld/WorldTime.kt index 7d5107c4d..bbe05b015 100644 --- a/src/net/torvald/terrarum/gameworld/WorldTime.kt +++ b/src/net/torvald/terrarum/gameworld/WorldTime.kt @@ -256,6 +256,42 @@ class WorldTime(initTime: Long = 0L) { TIME_T += t } + /** + * Sets the world time to a specific date and time. + * + * @param year The year (starting from EPOCH_YEAR = 1) + * @param month The month (1-4: Spring=1, Summer=2, Autumn=3, Winter=4) + * @param day The day of the month (1-30) + * @param hour The hour (0-23) + * @param minute The minute (0-59) + * @param second The second (0-59), defaults to 0 + */ + fun setTime( + year: Int, + month: Int, + day: Int, + hour: Int = 0, + minute: Int = 0, + second: Int = 0 + ) { + require(year >= EPOCH_YEAR) { "Year must be >= $EPOCH_YEAR" } + require(month in 1..4) { "Month must be 1-4 (Spring=1, Summer=2, Autumn=3, Winter=4)" } + require(day in 1..MONTH_LENGTH) { "Day must be 1-$MONTH_LENGTH" } + require(hour in 0 until HOURS_PER_DAY) { "Hour must be 0-${HOURS_PER_DAY - 1}" } + require(minute in 0 until HOUR_MIN) { "Minute must be 0-${HOUR_MIN - 1}" } + require(second in 0 until MINUTE_SEC) { "Second must be 0-${MINUTE_SEC - 1}" } + + val yearDays = (year - EPOCH_YEAR) * YEAR_DAYS + val monthDays = (month - 1) * MONTH_LENGTH + val dayOffset = day - 1 + val totalDays = yearDays + monthDays + dayOffset + + TIME_T = (totalDays.toLong() * DAY_LENGTH) + + (hour.toLong() * HOUR_SEC) + + (minute.toLong() * MINUTE_SEC) + + second.toLong() + } + fun Long.toPositiveInt() = this.and(0x7FFFFFFF).toInt() fun Long.abs() = Math.abs(this) diff --git a/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt b/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt index 2abccfe3c..90476b118 100644 --- a/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt +++ b/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt @@ -254,18 +254,10 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) { //loadDone = true // measure bogoflops here - val st = System.nanoTime() - var sc = st - var bogoflopf = Math.random() - var bogoflops = 0L - while (sc - st < 100000000L) { - bogoflopf *= Math.random() - bogoflops++ - sc = System.nanoTime() - } - bogoflops = Math.round(bogoflops.toDouble() * (1000000000.0 / (sc - st))) - printdbg(this, "Bogoflops old: ${App.bogoflops} new: $bogoflops") - App.bogoflops = maxOf(App.bogoflops, bogoflops) + val bogoflopsOld = App.bogoflops + App.updateBogoflops(100_000_000L) + printdbg(this, "Bogoflops old: $bogoflopsOld new: ${App.bogoflops}") + App.bogoflops = maxOf(App.bogoflops, bogoflopsOld) App.audioMixer.ambientTracks.forEach { diff --git a/src/net/torvald/terrarum/spriteassembler/ANIMATION_DESCRIPTION_LANGUAGE.md b/src/net/torvald/terrarum/spriteassembler/ANIMATION_DESCRIPTION_LANGUAGE.md index 6084cc07a..305f57e08 100644 --- a/src/net/torvald/terrarum/spriteassembler/ANIMATION_DESCRIPTION_LANGUAGE.md +++ b/src/net/torvald/terrarum/spriteassembler/ANIMATION_DESCRIPTION_LANGUAGE.md @@ -96,7 +96,7 @@ Remember that 'variables' are contained within 'properties' |---|---|---| |DELAY|variable: float|Delay between frames, in seconds| |ROW|variable: float|which row the animation goes in the spritesheet| -|SKELETON|variable: string_pair|Which skeleton this animation uses +|SKELETON|variable: string_pair|Which skeleton this animation uses| #### Transforms