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
No related branches found
No related tags found
1 merge request!4Exp rein
package fr.irit.smac.amak.examples.randomantsMultiUi;
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.VUI;
import fr.irit.smac.amak.ui.drawables.DrawableImage;
......@@ -46,8 +47,10 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample
@Override
protected void onRenderingInitialization() {
RunLaterHelper.runLater(() -> {
image = getAmas().getVUIMulti().createAndAddImage(dx, dy, "file:resources/ant.png");
image.setName("Ant "+getId());
});
}
/**
......@@ -81,6 +84,7 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample
@Override
public void onUpdateRender() {
RunLaterHelper.runLater(() -> {
image.move(dx, dy);
image.setAngle(angle);
image.setInfo("Ant "+getId()+"\nPosition "+dx+" "+dy+"\nAngle "+angle);
......@@ -88,5 +92,11 @@ public class AntExampleMutliUI extends Agent<AntHillExampleMultiUI, WorldExample
image.setFilename("file:Resources/ant_dead.png");
image.setInfo("Ant "+getId()+"\nPosition "+dx+" "+dy+"\nAngle "+angle+"\nDead");
}
});
}
}
......@@ -18,8 +18,10 @@ public class AntHillExampleMultiUI extends Amas<WorldExampleMultiUI> {
@Override
protected void onRenderingInitialization() {
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);
RunLaterHelper.runLater(() -> {
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
......
......@@ -44,27 +44,14 @@ public class AntsLaunchExampleMultiUI extends Application{
AntHillExampleMultiUI ants = new AntHillExampleMultiUI(window, new VUIMulti("Ants VUI 1"), env);
//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++) {
System.out.println(i);
ants.getScheduler().step();
ants.cycle();
}
}
......
......@@ -75,7 +75,7 @@ public class AmasMultiUIWindow extends Stage{
*/
public AmasMultiUIWindow(String title) {
RunLaterHelper.runLater(() -> {
VBox root = new VBox();
......@@ -123,7 +123,7 @@ public class AmasMultiUIWindow extends Stage{
this.show();
});
}
......@@ -232,8 +232,7 @@ public class AmasMultiUIWindow extends Stage{
*/
public void addTabbedPanel(String title, Node 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 {
*/
public VUIMulti(String titleValue) {
RunLaterHelper.runLater(() -> {
this.title = titleValue;
panel = new BorderPane();
......@@ -241,7 +243,7 @@ public class VUIMulti {
toolbar.getItems().add(veButton);
});
}
......
......@@ -55,7 +55,7 @@ public class AdvancedMain extends Application{
Configuration.multiUI = true;
VUIMulti amoebaVUI = VUIMulti.get("2D");
VUIMulti amoebaVUI = new VUIMulti("2D");
AmoebaMultiUIWindow amoebaUI = new AmoebaMultiUIWindow("ELLSA", amoebaVUI);
// Create an AMOEBA
......@@ -93,8 +93,9 @@ public class AdvancedMain extends Application{
amoeba.setRenderUpdate(true);
long start = System.currentTimeMillis();
// We run some learning cycles
int nbCycle = 1000;
int nbCycle = 100;
for (int i = 0; i < nbCycle; ++i) {
System.out.println(i);
studiedSystem.playOneStep();
amoeba.learn(studiedSystem.getOutput());
}
......@@ -140,6 +141,12 @@ public class AdvancedMain extends Application{
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