Mercurial > hg > Members > tatsuki > Alice
changeset 97:df786bf8f036 working
add FishPoint.java and Test
author | sugi |
---|---|
date | Tue, 26 Jun 2012 16:48:09 +0900 |
parents | a5fce70380e8 |
children | 21e68300e205 |
files | src/alice/test/codesegment/local/StartCodeSegment.java src/alice/test/codesegment/local/TestCodeSegment.java src/alice/test/topology/movement/CheckFishLocation.java src/alice/test/topology/movement/CheckMyName.java src/alice/test/topology/movement/FishPoint.java src/alice/test/topology/movement/KeyInputCodeSegment.java src/alice/test/topology/movement/SendLocation.java src/alice/test/topology/share/CheckMyName.java src/alice/test/topology/share/RelayPoint.java |
diffstat | 9 files changed, 108 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/codesegment/local/StartCodeSegment.java Tue Jun 19 17:52:01 2012 +0900 +++ b/src/alice/test/codesegment/local/StartCodeSegment.java Tue Jun 26 16:48:09 2012 +0900 @@ -1,19 +1,23 @@ package alice.test.codesegment.local; import alice.codesegment.CodeSegment; +import alice.test.topology.movement.FishPoint; public class StartCodeSegment extends CodeSegment { @Override public void run() { System.out.println("run StartCodeSegment"); - + /* TestCodeSegment cs = new TestCodeSegment(); cs.arg1.setKey("key1"); // unbound datasegment key1 is created and connect to cs. - // cs is waiting for local.key1 + // cs is waiting for local.key1 + + */ + new TestCodeSegment(); System.out.println("create TestCodeSegment"); - ods.update("local", "key1", "String data"); // bind string data to datasegment local.key1 + ods.update("local", "key1", new FishPoint()); // bind string data to datasegment local.key1 // this startup TestCodeSegment. }
--- a/src/alice/test/codesegment/local/TestCodeSegment.java Tue Jun 19 17:52:01 2012 +0900 +++ b/src/alice/test/codesegment/local/TestCodeSegment.java Tue Jun 26 16:48:09 2012 +0900 @@ -3,28 +3,39 @@ import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; +import alice.test.topology.movement.FishPoint; public class TestCodeSegment extends CodeSegment { // create input datasegment arg1 Receiver arg1 = ids.create(CommandType.PEEK); + public TestCodeSegment(){ + arg1.setKey("key1"); + } + public TestCodeSegment(int index){ + arg1.setKey("key1",index); + } @Override public void run() { System.out.println("index = " + arg1.index); System.out.println("data = " + arg1.val); System.out.println(arg1.val.getType()); + FishPoint PD = this.arg1.asClass(FishPoint.class); + + PD.setXY(PD.getX()+1,PD.getY()+1); if (arg1.index == 10) { System.exit(0); return; } - + /* TestCodeSegment cs = new TestCodeSegment(); cs.arg1.setKey("key1", arg1.index); - + */ + new TestCodeSegment(arg1.index); // DataSegment.get("local").update - ods.update("local", "key1", "String data"); + ods.update("local", "key1", PD); } }
--- a/src/alice/test/topology/movement/CheckFishLocation.java Tue Jun 19 17:52:01 2012 +0900 +++ b/src/alice/test/topology/movement/CheckFishLocation.java Tue Jun 26 16:48:09 2012 +0900 @@ -10,16 +10,16 @@ public class CheckFishLocation extends CodeSegment{ - private Receiver nowX = ids.create(CommandType.PEEK); + private Receiver position = ids.create(CommandType.PEEK); private Receiver host = ids.create(CommandType.PEEK); MakeObject obj; Pattern pattern = Pattern.compile("^(cli)([0-9]+)$"); public CheckFishLocation(MakeObject MO ,String str){ this.obj = MO; - this.nowX.key = str; + this.position.key = str; this.host.setKey("local","host"); - this.nowX.setKey("parent",this.nowX.key,this.nowX.index); + this.position.setKey("parent",this.position.key,this.position.index); } @Override @@ -31,15 +31,16 @@ float startX = 2*num - 3.0f; float endX = 2*num -0.9f; - float x = (float)this.nowX.asInteger()/1000; - System.out.println(this.nowX.key+" :" + x); - if (startX <= x && x < endX){ - obj.setLocation(x - 2*(num-1), 0); - if(this.nowX.key!="fish3X") - ods.update("parent", this.nowX.key, this.nowX.asInteger()+1); + FishPoint FP = this.position.asClass(FishPoint.class); + System.out.println(this.position.key+" :" + FP.getX()); + + if (startX <= FP.getX() && FP.getX() < endX){ + obj.setLocation(FP.getX() - 2*(num-1), FP.getY()); + //if(this.position.key!="fish3X") + //ods.update("parent", this.position.key, this.position.asInteger()+1); } - new CheckFishLocation(this.obj,this.nowX.key); + new CheckFishLocation(this.obj,this.position.key);
--- a/src/alice/test/topology/movement/CheckMyName.java Tue Jun 19 17:52:01 2012 +0900 +++ b/src/alice/test/topology/movement/CheckMyName.java Tue Jun 26 16:48:09 2012 +0900 @@ -30,15 +30,16 @@ MakeObject obj3 = new MakeObject(frame); frame.register(obj3); new CheckFishLocation(obj3,"fish3X"); - + /* MakeObject obj = new MakeObject(frame); frame.register(obj); new CheckFishLocation(obj,"fish1X"); - + */ }else if(type.equals("node")){ System.out.println("node0"); - ods.update("local", "fish3X", 0); - ods.update("local", "fish1X", -1000); + + ods.update("local", "fish3X", new FishPoint(0.0f,0.0f)); + //ods.update("local", "fish1X", new FishPoint(-1.0f,0.0f)); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/topology/movement/FishPoint.java Tue Jun 26 16:48:09 2012 +0900 @@ -0,0 +1,40 @@ +package alice.test.topology.movement; + +import org.msgpack.annotation.Message; + +@Message +public class FishPoint { + // public fields are serialized. + public float x = 0; + public float y = 0; + + public FishPoint(){} + + public FishPoint(float x,float y){ + this.x = x; + this.y = y; + } + + public void setX(float x){ + this.x = x; + } + + public void setY(float y){ + this.y = y; + } + + public void setXY(float x,float y){ + this.x = x; + this.y = y; + } + public float getX(){ + return this.x; + } + + public float getY(){ + return this.y; + } + + + +}
--- a/src/alice/test/topology/movement/KeyInputCodeSegment.java Tue Jun 19 17:52:01 2012 +0900 +++ b/src/alice/test/topology/movement/KeyInputCodeSegment.java Tue Jun 26 16:48:09 2012 +0900 @@ -14,12 +14,20 @@ switch(KeyCode) { case 37: - cs = new SendLocation(-100); - cs.nowX.setKey("parent", "fish3X"); + cs = new SendLocation(-0.1f,0.0f); + cs.position.setKey("parent", "fish3X"); break; case 39: - cs = new SendLocation(100); - cs.nowX.setKey("parent", "fish3X"); + cs = new SendLocation(0.1f,0.0f); + cs.position.setKey("parent", "fish3X"); + break; + case 40: + cs = new SendLocation(0.0f,-0.1f); + cs.position.setKey("parent", "fish3X"); + break; + case 38: + cs = new SendLocation(0.0f,0.1f); + cs.position.setKey("parent", "fish3X"); break; } }
--- a/src/alice/test/topology/movement/SendLocation.java Tue Jun 19 17:52:01 2012 +0900 +++ b/src/alice/test/topology/movement/SendLocation.java Tue Jun 26 16:48:09 2012 +0900 @@ -7,17 +7,21 @@ public class SendLocation extends CodeSegment { - public Receiver nowX = ids.create(CommandType.PEEK); - int num; + public Receiver position = ids.create(CommandType.PEEK); + float x; + float y; - public SendLocation(int x){ - this.num = x; + public SendLocation(float x,float y){ + this.x = x; + this.y = y; } @Override public void run() { System.out.println("update"); - ods.update("parent", "fish3X", this.nowX.asInteger()+num); + FishPoint FP = this.position.asClass(FishPoint.class); + FP.setXY(FP.getX()+this.x, FP.getY()+this.y); + ods.update("parent", "fish3X", FP); }
--- a/src/alice/test/topology/share/CheckMyName.java Tue Jun 19 17:52:01 2012 +0900 +++ b/src/alice/test/topology/share/CheckMyName.java Tue Jun 26 16:48:09 2012 +0900 @@ -37,16 +37,16 @@ System.out.println("node"+cliNum); if (cliNum == 0){ - for (int i=0;i<20 ;i++){ - System.out.println("i = " +i); - ods.update("local", "fish", i); - try { - wait(500); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + for (int i = 0; i < 20; i++) { + System.out.println("i = " + i); + ods.update("local", "fish", i); + try { + wait(500); + } catch (InterruptedException e) { + + e.printStackTrace(); + } + } }else{ ods.update("local", "fish", 0); new RelayPoint("fish");
--- a/src/alice/test/topology/share/RelayPoint.java Tue Jun 19 17:52:01 2012 +0900 +++ b/src/alice/test/topology/share/RelayPoint.java Tue Jun 26 16:48:09 2012 +0900 @@ -12,7 +12,6 @@ public RelayPoint(String key){ this.key = key; this.name.setKey("parent", this.key, this.name.index); - System.out.println("setkey"); } @Override