134
|
1 package alice.test.topology.aquarium;
|
111
|
2
|
|
3 import alice.codesegment.CodeSegment;
|
|
4 import alice.datasegment.CommandType;
|
|
5 import alice.datasegment.Receiver;
|
|
6
|
|
7 public class AutoIncrement extends CodeSegment {
|
|
8
|
138
|
9 private Receiver position = ids.create(CommandType.PEEK);
|
|
10 private Receiver number = ids.create(CommandType.PEEK);
|
|
11 private float min = -1.3f;
|
|
12 private float max;
|
119
|
13
|
133
|
14 public AutoIncrement(String key,int index){
|
178
|
15 this.number.setKey("local", "maxsize");
|
|
16 this.position.setKey("local", key, index);
|
119
|
17 }
|
111
|
18
|
|
19 @Override
|
132
|
20 public void run() {
|
212
|
21 max = this.number.data.asInteger(this.number)*2-1+0.3f;
|
|
22 FishPoint fp = this.position.data.asClass(this.position, FishPoint.class);
|
132
|
23 if (fp.getX()+0.01>max){
|
143
|
24 fp.setXYZ(min, fp.getY(), fp.getZ());
|
132
|
25 } else if (fp.getX()+0.01< min){
|
143
|
26 fp.setXYZ(max, fp.getY(), fp.getZ());
|
115
|
27 }
|
|
28 else {
|
143
|
29 fp.setXYZ(fp.getX()+0.01f, fp.getY(), fp.getZ());
|
115
|
30 }
|
|
31
|
212
|
32 ods.update("local", position.data.key, fp);
|
132
|
33 synchronized(this){
|
|
34 try {
|
|
35 // TODO
|
|
36 // Waiting should be done in Alice kernel
|
|
37 // ids.create(CommandType.WAIT);
|
|
38
|
143
|
39 wait(20);
|
132
|
40 } catch (InterruptedException e) {
|
|
41 e.printStackTrace();
|
|
42 }
|
|
43 }
|
115
|
44
|
212
|
45 new AutoIncrement(this.position.data.key, this.position.data.index);
|
111
|
46 }
|
|
47
|
|
48 }
|