Added jbvm arguments to build.xml + Rewrite.java now an utility class + optimized imports

This commit is contained in:
Quentin Legot 2021-03-09 18:21:13 +01:00
parent 399b7e0fe1
commit dcb4ad767b
6 changed files with 19 additions and 26 deletions

View File

@ -20,6 +20,8 @@
<target name="run" description="execution" depends="compile"> <target name="run" description="execution" depends="compile">
<java classname="lsystem.Main" fork="true"> <java classname="lsystem.Main" fork="true">
<jvmarg value="-ea"/> <jvmarg value="-ea"/>
<jvmarg value="-XX:+UseG1GC"/>
<jvmarg value="-XX:+ParallelRefProcEnabled"/>
<classpath refid="project.classpath"/> <classpath refid="project.classpath"/>
</java> </java>
</target> </target>

View File

@ -79,7 +79,7 @@ public class Parser {
} }
/** /**
* Used by {@link Rewrite#rewrite()} * Used by {@link Rewrite#rewrite(String, List, int)} )}
* @return a list of rules with the left and right sides separated by a {@link lsystem.utils.Pair Pair} * @return a list of rules with the left and right sides separated by a {@link lsystem.utils.Pair Pair}
*/ */
public List<Pair<String, String>> parseRules() { public List<Pair<String, String>> parseRules() {

View File

@ -6,18 +6,8 @@ import java.util.List;
public class Rewrite { public class Rewrite {
private final String axiom;
private final List<Pair<String, String >> rules;
private final int recurrences;
public Rewrite(String axiom, List<Pair<String, String>> rules, int recurrences) { private static String replaceRulesByID(final String rewritten, List<Pair<String, String>> rules) {
this.axiom = axiom;
this.rules = rules;
this.recurrences = recurrences;
}
private String replaceRulesByID(final String rewritten) {
String toRewrite = rewritten; String toRewrite = rewritten;
for(int j = 0; j < rules.size(); ++j){ for(int j = 0; j < rules.size(); ++j){
Pair<String, String> pair = rules.get(j); Pair<String, String> pair = rules.get(j);
@ -26,7 +16,7 @@ public class Rewrite {
return toRewrite; return toRewrite;
} }
private String replaceIDByRuleApplication(final String toRewrite) { private static String replaceIDByRuleApplication(final String toRewrite, List<Pair<String, String>> rules) {
String rewritten = toRewrite; String rewritten = toRewrite;
for(int j = 0; j < rules.size(); ++j){ for(int j = 0; j < rules.size(); ++j){
rewritten = rewritten.replace("${" + j + "}", rules.get(j).getRight()); rewritten = rewritten.replace("${" + j + "}", rules.get(j).getRight());
@ -34,11 +24,12 @@ public class Rewrite {
return rewritten; return rewritten;
} }
public String rewrite() { public static String rewrite(String axiom, List<Pair<String, String>> rules, int recurrences) {
String rewritten = axiom; String rewritten = axiom;
for(int i = 0; i < recurrences; ++i) { for(int i = 0; i < recurrences; ++i) {
String toRewrite = replaceRulesByID(rewritten); String toRewrite = replaceRulesByID(rewritten, rules);
rewritten = replaceIDByRuleApplication(toRewrite); rewritten = replaceIDByRuleApplication(toRewrite, rules);
System.out.println(i + " / " + recurrences + " : " + rewritten.length());
} }
return rewritten.replace("[", "Y["); return rewritten.replace("[", "Y[");
} }

View File

@ -36,6 +36,7 @@ public abstract class AbstractCanvas {
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
frame.dispose(); frame.dispose();
setVisible(false);
} }
}); });
frame.getContentPane().add(glCanvas, BorderLayout.CENTER); frame.getContentPane().add(glCanvas, BorderLayout.CENTER);

View File

@ -1,6 +1,5 @@
package lsystem.screen.main; package lsystem.screen.main;
import lsystem.engine.Element;
import lsystem.engine.Parser; import lsystem.engine.Parser;
import lsystem.engine.Rewrite; import lsystem.engine.Rewrite;
import lsystem.screen.gl3d.GLCanvas; import lsystem.screen.gl3d.GLCanvas;
@ -53,14 +52,14 @@ public class Listener implements ActionListener, KeyListener {
JOptionPane.showMessageDialog(null, "Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer"); JOptionPane.showMessageDialog(null, "Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
new Listener(null, index, "Clear",tab); new Listener(null, index, "Clear",tab);
} else { } else {
new Thread(() -> { Thread thread = new Thread(() -> {
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), tab.getNbIterations()); GLCanvas canvas = new GLCanvas(
final String word = rewriter.rewrite(); Parser.parse(Rewrite.rewrite(axiom, parser.parseRules(), tab.getNbIterations()))
System.out.println(word); );
final Element parsed = Parser.parse(word);
GLCanvas canvas = new GLCanvas(parsed);
canvas.setVisible(true); canvas.setVisible(true);
}).start(); });
thread.setDaemon(true);
thread.start();
} }
break; break;

View File

@ -29,7 +29,7 @@ public class Tab extends JPanel{
nbIterations.setModel(new SpinnerNumberModel(1, 1, 15, 1)); nbIterations.setModel(new SpinnerNumberModel(1, 1, 15, 1));
JLabel itLabel = new JLabel("Nombre d'itérations : "); JLabel itLabel = new JLabel("Nombre d'itérations : ");
itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 15, 1)); itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1));
((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false); ((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false);
JLabel axiome = new JLabel("Axiome :"); JLabel axiome = new JLabel("Axiome :");