annotate src/alice/test/topology/aquarium/AutoIncrement.java @ 212:b5daccf36104 working

add Receiver state pattern
author one
date Wed, 27 Mar 2013 17:30:52 +0900
parents 1b532146b355
children fec0726bb126
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
53aff28cde6b change package
sugi
parents: 133
diff changeset
1 package alice.test.topology.aquarium;
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
2
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
3 import alice.codesegment.CodeSegment;
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
4 import alice.datasegment.CommandType;
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
5 import alice.datasegment.Receiver;
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
6
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
7 public class AutoIncrement extends CodeSegment {
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
8
138
87f1a30a8c82 change range automatic
sugi
parents: 134
diff changeset
9 private Receiver position = ids.create(CommandType.PEEK);
87f1a30a8c82 change range automatic
sugi
parents: 134
diff changeset
10 private Receiver number = ids.create(CommandType.PEEK);
87f1a30a8c82 change range automatic
sugi
parents: 134
diff changeset
11 private float min = -1.3f;
87f1a30a8c82 change range automatic
sugi
parents: 134
diff changeset
12 private float max;
119
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
13
133
26b4b18c51fa minor change
sugi
parents: 132
diff changeset
14 public AutoIncrement(String key,int index){
178
1b532146b355 minor change
e095732
parents: 171
diff changeset
15 this.number.setKey("local", "maxsize");
1b532146b355 minor change
e095732
parents: 171
diff changeset
16 this.position.setKey("local", key, index);
119
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
17 }
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
18
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
19 @Override
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
20 public void run() {
212
b5daccf36104 add Receiver state pattern
one
parents: 178
diff changeset
21 max = this.number.data.asInteger(this.number)*2-1+0.3f;
b5daccf36104 add Receiver state pattern
one
parents: 178
diff changeset
22 FishPoint fp = this.position.data.asClass(this.position, FishPoint.class);
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
23 if (fp.getX()+0.01>max){
143
0651fb36a369 demo for Open Source Conference
sugi
parents: 139
diff changeset
24 fp.setXYZ(min, fp.getY(), fp.getZ());
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
25 } else if (fp.getX()+0.01< min){
143
0651fb36a369 demo for Open Source Conference
sugi
parents: 139
diff changeset
26 fp.setXYZ(max, fp.getY(), fp.getZ());
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
27 }
9845b74063ec share max number
sugi
parents: 114
diff changeset
28 else {
143
0651fb36a369 demo for Open Source Conference
sugi
parents: 139
diff changeset
29 fp.setXYZ(fp.getX()+0.01f, fp.getY(), fp.getZ());
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
30 }
9845b74063ec share max number
sugi
parents: 114
diff changeset
31
212
b5daccf36104 add Receiver state pattern
one
parents: 178
diff changeset
32 ods.update("local", position.data.key, fp);
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
33 synchronized(this){
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
34 try {
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
35 // TODO
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
36 // Waiting should be done in Alice kernel
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
37 // ids.create(CommandType.WAIT);
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
38
143
0651fb36a369 demo for Open Source Conference
sugi
parents: 139
diff changeset
39 wait(20);
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
40 } catch (InterruptedException e) {
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
41 e.printStackTrace();
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
42 }
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
43 }
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
44
212
b5daccf36104 add Receiver state pattern
one
parents: 178
diff changeset
45 new AutoIncrement(this.position.data.key, this.position.data.index);
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
46 }
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
47
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
48 }