mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
fix: bogoflops counter being overestimated on M4 Mac due to Math.random() reliance
This commit is contained in:
@@ -343,7 +343,6 @@ public class App implements ApplicationListener {
|
|||||||
public static InputStrober inputStrober;
|
public static InputStrober inputStrober;
|
||||||
|
|
||||||
public static long bogoflops = 0L;
|
public static long bogoflops = 0L;
|
||||||
private static double bogoflopf = Math.random();
|
|
||||||
|
|
||||||
public static boolean hasUpdate = true;
|
public static boolean hasUpdate = true;
|
||||||
|
|
||||||
@@ -362,20 +361,33 @@ public class App implements ApplicationListener {
|
|||||||
|
|
||||||
public static long loadedTime_t;
|
public static long loadedTime_t;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void updateBogoflops(long iteration) {
|
||||||
loadedTime_t = getTIME_T();
|
long iters = 0;
|
||||||
|
double a = 1.000001;
|
||||||
|
double b = 1.000002;
|
||||||
|
double c = 1.000003;
|
||||||
|
|
||||||
long st = System.nanoTime();
|
long st = System.nanoTime();
|
||||||
long sc = st;
|
long sc = st;
|
||||||
while (sc - st < 100000000L) {
|
|
||||||
bogoflopf = Math.random() * bogoflopf;
|
while (sc - st < iteration) {
|
||||||
bogoflops++;
|
// burn ALU cycles
|
||||||
|
a = a * b + c;
|
||||||
|
b = b * c + a;
|
||||||
|
c = c * a + b;
|
||||||
|
|
||||||
|
iters += 3; // roughly count flops
|
||||||
sc = System.nanoTime();
|
sc = System.nanoTime();
|
||||||
}
|
}
|
||||||
bogoflops = Math.round((double)(bogoflops) * (1000000000.0 / (sc - st)));
|
|
||||||
// System.out.println(sc - st);
|
// divide by 4 to make it roughly match up with the old calibrated worldgen estimator
|
||||||
// System.out.println(bogoflops);
|
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
|
// if -ea flag is set, turn on all the debug prints
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -256,6 +256,42 @@ class WorldTime(initTime: Long = 0L) {
|
|||||||
TIME_T += t
|
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.toPositiveInt() = this.and(0x7FFFFFFF).toInt()
|
||||||
fun Long.abs() = Math.abs(this)
|
fun Long.abs() = Math.abs(this)
|
||||||
|
|
||||||
|
|||||||
@@ -254,18 +254,10 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
//loadDone = true
|
//loadDone = true
|
||||||
|
|
||||||
// measure bogoflops here
|
// measure bogoflops here
|
||||||
val st = System.nanoTime()
|
val bogoflopsOld = App.bogoflops
|
||||||
var sc = st
|
App.updateBogoflops(100_000_000L)
|
||||||
var bogoflopf = Math.random()
|
printdbg(this, "Bogoflops old: $bogoflopsOld new: ${App.bogoflops}")
|
||||||
var bogoflops = 0L
|
App.bogoflops = maxOf(App.bogoflops, bogoflopsOld)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
App.audioMixer.ambientTracks.forEach {
|
App.audioMixer.ambientTracks.forEach {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ Remember that 'variables' are contained within 'properties'
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
|DELAY|variable: float|Delay between frames, in seconds|
|
|DELAY|variable: float|Delay between frames, in seconds|
|
||||||
|ROW|variable: float|which row the animation goes in the spritesheet|
|
|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
|
#### Transforms
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user