Skip to content
Snippets Groups Projects
Commit af2ef834 authored by BrunoDatoMeneses's avatar BrunoDatoMeneses
Browse files

ADD: try fix UI freezing adding RunLaterHelper

parent 50e7066e
Branches
No related tags found
1 merge request!4Exp rein
package fr.irit.smac.amak.examples.randomantsMultiUi; package fr.irit.smac.amak.examples.randomantsMultiUi;
import fr.irit.smac.amak.Agent; import fr.irit.smac.amak.Agent;
import fr.irit.smac.amak.tools.RunLaterHelper;
import fr.irit.smac.amak.ui.AmasMultiUIWindow; import fr.irit.smac.amak.ui.AmasMultiUIWindow;
import fr.irit.smac.amak.ui.VUI; import fr.irit.smac.amak.ui.VUI;
import fr.irit.smac.amak.ui.drawables.DrawableImage; import fr.irit.smac.amak.ui.drawables.DrawableImage;
...@@ -46,8 +47,10 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample ...@@ -46,8 +47,10 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample
@Override @Override
protected void onRenderingInitialization() { protected void onRenderingInitialization() {
RunLaterHelper.runLater(() -> {
image = getAmas().getVUIMulti().createAndAddImage(dx, dy, "file:resources/ant.png"); image = getAmas().getVUIMulti().createAndAddImage(dx, dy, "file:resources/ant.png");
image.setName("Ant "+getId()); image.setName("Ant "+getId());
});
} }
/** /**
...@@ -81,6 +84,7 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample ...@@ -81,6 +84,7 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample
@Override @Override
public void onUpdateRender() { public void onUpdateRender() {
RunLaterHelper.runLater(() -> {
image.move(dx, dy); image.move(dx, dy);
image.setAngle(angle); image.setAngle(angle);
image.setInfo("Ant "+getId()+"\nPosition "+dx+" "+dy+"\nAngle "+angle); image.setInfo("Ant "+getId()+"\nPosition "+dx+" "+dy+"\nAngle "+angle);
...@@ -88,5 +92,11 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample ...@@ -88,5 +92,11 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample
image.setFilename("file:Resources/ant_dead.png"); image.setFilename("file:Resources/ant_dead.png");
image.setInfo("Ant "+getId()+"\nPosition "+dx+" "+dy+"\nAngle "+angle+"\nDead"); image.setInfo("Ant "+getId()+"\nPosition "+dx+" "+dy+"\nAngle "+angle+"\nDead");
} }
});
} }
} }
...@@ -18,8 +18,10 @@ public class AntHillExampleMultiUI extends Amas<WorldExampleMultiUI> { ...@@ -18,8 +18,10 @@ public class AntHillExampleMultiUI extends Amas<WorldExampleMultiUI> {
@Override @Override
protected void onRenderingInitialization() { protected void onRenderingInitialization() {
vuiMulti.createAndAddImage(20, 20, "file:Resources/ant.png").setFixed().setLayer(10).setShowInExplorer(false); RunLaterHelper.runLater(() -> {
antsCountLabel = (DrawableString) vuiMulti.createAndAddString(45, 25, "Ants count").setFixed().setLayer(10).setShowInExplorer(false); vuiMulti.createAndAddImage(20, 20, "file:Resources/ant.png").setFixed().setLayer(10).setShowInExplorer(false);
antsCountLabel = (DrawableString) vuiMulti.createAndAddString(45, 25, "Ants count").setFixed().setLayer(10).setShowInExplorer(false);
});
} }
@Override @Override
......
...@@ -44,27 +44,14 @@ public class AntsLaunchExampleMultiUI extends Application{ ...@@ -44,27 +44,14 @@ public class AntsLaunchExampleMultiUI extends Application{
AntHillExampleMultiUI ants = new AntHillExampleMultiUI(window, new VUIMulti("Ants VUI 1"), env); AntHillExampleMultiUI ants = new AntHillExampleMultiUI(window, new VUIMulti("Ants VUI 1"), env);
//new AntHillExampleMultiUI(window2, VUIMulti.get("Ants VUI 2"), env2); //new AntHillExampleMultiUI(window2, VUIMulti.get("Ants VUI 2"), env2);
Button btn = new Button();
btn.setText("GO");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
for(int i=0;i<10000;i++) {
System.out.println(i);
ants.cycle();
}
}
});
window.addToolbar(btn);
for(int i=0;i<10000;i++) { for(int i=0;i<10000;i++) {
System.out.println(i); System.out.println(i);
ants.getScheduler().step(); ants.cycle();
} }
} }
......
...@@ -75,7 +75,7 @@ public class AmasMultiUIWindow extends Stage{ ...@@ -75,7 +75,7 @@ public class AmasMultiUIWindow extends Stage{
*/ */
public AmasMultiUIWindow(String title) { public AmasMultiUIWindow(String title) {
RunLaterHelper.runLater(() -> {
VBox root = new VBox(); VBox root = new VBox();
...@@ -123,7 +123,7 @@ public class AmasMultiUIWindow extends Stage{ ...@@ -123,7 +123,7 @@ public class AmasMultiUIWindow extends Stage{
this.show(); this.show();
});
} }
...@@ -232,8 +232,7 @@ public class AmasMultiUIWindow extends Stage{ ...@@ -232,8 +232,7 @@ public class AmasMultiUIWindow extends Stage{
*/ */
public void addTabbedPanel(String title, Node panel) { public void addTabbedPanel(String title, Node panel) {
Tab t = new DraggableTab(title, panel); Tab t = new DraggableTab(title, panel);
tabbedPanel.getTabs().add(t); RunLaterHelper.runLater(() -> tabbedPanel.getTabs().add(t));
//RunLaterHelper.runLater(() -> tabbedPanel.getTabs().add(t));
} }
/** /**
......
...@@ -146,6 +146,8 @@ public class VUIMulti { ...@@ -146,6 +146,8 @@ public class VUIMulti {
*/ */
public VUIMulti(String titleValue) { public VUIMulti(String titleValue) {
RunLaterHelper.runLater(() -> {
this.title = titleValue; this.title = titleValue;
panel = new BorderPane(); panel = new BorderPane();
...@@ -241,7 +243,7 @@ public class VUIMulti { ...@@ -241,7 +243,7 @@ public class VUIMulti {
toolbar.getItems().add(veButton); toolbar.getItems().add(veButton);
});
} }
......
...@@ -55,7 +55,7 @@ public class AdvancedMain extends Application{ ...@@ -55,7 +55,7 @@ public class AdvancedMain extends Application{
Configuration.multiUI = true; Configuration.multiUI = true;
VUIMulti amoebaVUI = VUIMulti.get("2D"); VUIMulti amoebaVUI = new VUIMulti("2D");
AmoebaMultiUIWindow amoebaUI = new AmoebaMultiUIWindow("ELLSA", amoebaVUI); AmoebaMultiUIWindow amoebaUI = new AmoebaMultiUIWindow("ELLSA", amoebaVUI);
// Create an AMOEBA // Create an AMOEBA
...@@ -93,8 +93,9 @@ public class AdvancedMain extends Application{ ...@@ -93,8 +93,9 @@ public class AdvancedMain extends Application{
amoeba.setRenderUpdate(true); amoeba.setRenderUpdate(true);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
// We run some learning cycles // We run some learning cycles
int nbCycle = 1000; int nbCycle = 100;
for (int i = 0; i < nbCycle; ++i) { for (int i = 0; i < nbCycle; ++i) {
System.out.println(i);
studiedSystem.playOneStep(); studiedSystem.playOneStep();
amoeba.learn(studiedSystem.getOutput()); amoeba.learn(studiedSystem.getOutput());
} }
...@@ -140,6 +141,12 @@ public class AdvancedMain extends Application{ ...@@ -140,6 +141,12 @@ public class AdvancedMain extends Application{
System.out.println("End main"); System.out.println("End main");
} }
@Override
public void stop() throws Exception {
super.stop();
System.exit(0);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment