changeset 383:878d397904da multicast

draw same Scene
author sugi
date Tue, 10 Jun 2014 19:36:46 +0900
parents 75411d4dc9f9
children 56d4f93a3921
files src/main/java/alice/test/topology/aquarium/fx/AddObject.java src/main/java/alice/test/topology/aquarium/fx/Aquarium.java src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java src/main/java/alice/test/topology/aquarium/fx/CreateObject.java src/main/java/alice/test/topology/aquarium/fx/FishInfo.java src/main/java/alice/test/topology/aquarium/fx/SendDataOthers.java src/main/java/alice/test/topology/aquarium/fx/SetTranslate.java
diffstat 7 files changed, 46 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/alice/test/topology/aquarium/fx/AddObject.java	Tue Jun 10 17:02:53 2014 +0900
+++ b/src/main/java/alice/test/topology/aquarium/fx/AddObject.java	Tue Jun 10 19:36:46 2014 +0900
@@ -9,7 +9,7 @@
 
 public class AddObject extends CodeSegment {
 	// add Object on javaFx Scene
-	private Receiver info = ids.create(CommandType.TAKE);
+	private Receiver info = ids.create(CommandType.PEEK);
 	private Receiver info1 = ids.create(CommandType.TAKE);
 	private boolean executed = false;
 	
@@ -37,6 +37,7 @@
 				root.getChildren().add(obj);
 			}
 			ods.put(obj.getId()+"Fish", obj);
+			new AddObject();
 		}	
 	}
 	
--- a/src/main/java/alice/test/topology/aquarium/fx/Aquarium.java	Tue Jun 10 17:02:53 2014 +0900
+++ b/src/main/java/alice/test/topology/aquarium/fx/Aquarium.java	Tue Jun 10 19:36:46 2014 +0900
@@ -37,7 +37,6 @@
 		Scene scene = new Scene(createContent());
 		scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
 		    public void handle(KeyEvent t) {
-		    	System.out.println(t.getCode());
 		    	switch (t.getCode()) {
 		    	case RIGHT:
 		    		ods.update(myName+"FishPosition", new FishInfo(0.1,0,0));
--- a/src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java	Tue Jun 10 17:02:53 2014 +0900
+++ b/src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java	Tue Jun 10 19:36:46 2014 +0900
@@ -32,6 +32,7 @@
 		
 		new CreateObject();
 		new AddObject();
+		
 		String[] args = {name};
 		Aquarium.main(args);
 	}
--- a/src/main/java/alice/test/topology/aquarium/fx/CreateObject.java	Tue Jun 10 17:02:53 2014 +0900
+++ b/src/main/java/alice/test/topology/aquarium/fx/CreateObject.java	Tue Jun 10 19:36:46 2014 +0900
@@ -23,6 +23,7 @@
 	
 	@Override
 	public void run() {
+		System.out.println("receive data " +info.from);
 		FishInfo fishInfo = info.asClass(FishInfo.class);
 		
 		BooleanProperty showWireframe = new SimpleBooleanProperty(false);
@@ -44,6 +45,9 @@
 		
 		new SetTranslate(fishInfo.name+"Fish");
 		ods.put("addOffer", obj);
+		ods.put("register", fishInfo);
+		new SendDataOthers(info, "fishData");
+		new CreateObject();
 	}
 	
 
--- a/src/main/java/alice/test/topology/aquarium/fx/FishInfo.java	Tue Jun 10 17:02:53 2014 +0900
+++ b/src/main/java/alice/test/topology/aquarium/fx/FishInfo.java	Tue Jun 10 19:36:46 2014 +0900
@@ -12,6 +12,10 @@
 	public int size = 1;
 	public String type = "defalut"; // use select object type. after implement may be...
 	
+	public FishInfo(){
+		// this constructor is nothing to do, but need for serializing with MessagePack
+	}
+	
 	public FishInfo(double x,double y,double z){
 		this.x = x;
 		this.y = y;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/alice/test/topology/aquarium/fx/SendDataOthers.java	Tue Jun 10 19:36:46 2014 +0900
@@ -0,0 +1,33 @@
+package alice.test.topology.aquarium.fx;
+
+import java.util.List;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class SendDataOthers extends CodeSegment {
+	
+	private Receiver info = ids.create(CommandType.PEEK);
+	private Receiver info1; // should use dataSegment
+	private String key;     // should use dataSegment
+	
+	public SendDataOthers(Receiver r, String key){
+		this.key = key;
+		info1 = r;
+		info.setKey("_CLIST");
+	}
+	
+	@Override
+	public void run() {
+		System.out.println(key);
+		@SuppressWarnings("unchecked")
+		List<String> nodes = info.asClass(List.class);
+		for (String node : nodes) {
+			System.out.println(node);
+			if (!info1.from.equals(node))
+				ods.put(node, key, info1.getVal());
+		}
+	}
+
+}
--- a/src/main/java/alice/test/topology/aquarium/fx/SetTranslate.java	Tue Jun 10 17:02:53 2014 +0900
+++ b/src/main/java/alice/test/topology/aquarium/fx/SetTranslate.java	Tue Jun 10 19:36:46 2014 +0900
@@ -20,6 +20,7 @@
 	public void run() {
 		if (!executed) {
 			executed = true;
+			new SendDataOthers(info1, info1.key);
 			// javafx's Scene can be accessed only FX application thread.
 			Platform.runLater(this);
 		} else {
@@ -30,6 +31,7 @@
         	fish.setTranslateY(fish.getTranslateY()+fp.getY());
         	fish.setTranslateZ(fish.getTranslateZ()+fp.getZ());
         	ods.flip(info);
+        	executed = false;
     		new SetTranslate(info.key);
 		}		
 	}