skunkworks/com/danitheskunk/skunkworks/Util.java

38 lines
842 B
Java

package com.danitheskunk.skunkworks;
import org.lwjgl.glfw.GLFW;
public class Util {
public static String nullTerminatedCharArrayToString(char[] chars) {
int len = chars.length;
for(int i = 0; i < chars.length; ++i) {
if(chars[i] == '\0') {
len = i;
break;
}
}
return new String(chars, 0, len);
}
public static double tweenDouble(double a, double b, double amount) {
return (b - a) * amount + a;
}
public static int tweenInt(int a, int b, double amount) {
return (int) ((b - a) * amount + a);
}
public static void time(Runnable run) {
time(run, 1);
}
public static void time(Runnable run, int times) {
double now = GLFW.glfwGetTime();
for(int i = 0; i < times; ++i) {
run.run();
}
double end = GLFW.glfwGetTime();
System.out.printf("%f seconds per iteration.\n", (end-now)/times);
}
}