Added JIT warp-up phase

This commit is contained in:
Andrea Cavalli 2017-12-23 15:20:42 +01:00
parent e6949aed92
commit d5d34394db
3 changed files with 35 additions and 1 deletions

View File

@ -25,6 +25,9 @@ public class Main {
beforeStart();
new DisplayManager(screen);
afterStart();
if (screen instanceof LoadingScreen) {
((LoadingScreen) screen).loaded = true;
}
DisplayManager.INSTANCE.waitForExit();
Utils.out.println(1, "Shutdown...");
beforeShutdown();
@ -82,6 +85,7 @@ public class Main {
public void afterStart() {
DisplayManager.INSTANCE.setBrightness(0.2f);
RulesManager.initialize();
RulesManager.warmUp();
}
public void beforeShutdown() {

View File

@ -10,6 +10,7 @@ public class LoadingScreen extends Screen {
public float endLoading;
boolean mustRefresh = true;
public float loadingTextTranslation = 0.0f;
public boolean loaded = false;
public LoadingScreen() {
super();
@ -29,7 +30,7 @@ public class LoadingScreen extends Screen {
loadingTextTranslation = GraphicUtils.sinDeg(endLoading * 90f) * 10f;
endLoading += dt;
if (StaticVars.debugOn || endLoading >= 5f) {
if (loaded && (StaticVars.debugOn || endLoading >= 3.5f)) {
DisplayManager.INSTANCE.setScreen(new MathInputScreen());
}
mustRefresh = true;

View File

@ -24,9 +24,13 @@ import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.warp.picalculator.Error;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.MathSolver;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.SumSubtraction;
@ -74,6 +78,31 @@ public class RulesManager {
}
}
public static void warmUp() {
ObjectArrayList<Function> uselessResult = null;
boolean uselessVariable;
for (RuleType val : RuleType.values()) {
final ObjectArrayList<Rule> ruleList = rules[val.ordinal()];
for (final Rule rule : ruleList) {
ObjectArrayList<Function> uselessResult2 = rule.execute(generateUselessExpression());
uselessVariable = (uselessResult == null ? new ObjectArrayList<>() : uselessResult).equals(uselessResult2);
uselessResult = uselessResult2;
}
}
try {
new MathSolver(generateUselessExpression()).solveAllSteps();
} catch (InterruptedException | Error e) {
e.printStackTrace();
}
}
private static Expression generateUselessExpression() {
MathContext mc = new MathContext();
Expression expr = new Expression(mc);
expr = (Expression) expr.setParameter(new Variable(mc, 'x', V_TYPE.VARIABLE));
return expr;
}
public static void addRule(Rule rule) {
rules[rule.getRuleType().ordinal()].add(rule);
Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "Loaded rule " + rule.getRuleName());