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
|
|
9 public Receiver position = ids.create(CommandType.PEEK);
|
|
10 String key;
|
119
|
11 float max = 3.3f;
|
|
12 float min = -1.3f;
|
|
13
|
133
|
14 public AutoIncrement(String key,int index){
|
111
|
15 this.key = key;
|
133
|
16 this.position.setKey("local", key,index);
|
119
|
17 }
|
111
|
18
|
|
19 @Override
|
132
|
20 public void run() {
|
|
21 FishPoint fp = this.position.asClass(FishPoint.class);
|
|
22 if (fp.getX()+0.01>max){
|
|
23 fp.setXY(min, fp.getY());
|
|
24 } else if (fp.getX()+0.01< min){
|
|
25 fp.setXY(max, fp.getY());
|
115
|
26 }
|
|
27 else {
|
132
|
28 fp.setXY(fp.getX()+0.01f, fp.getY());
|
115
|
29 }
|
|
30
|
132
|
31 ods.update("local", key, fp);
|
|
32 synchronized(this){
|
|
33 try {
|
|
34 // TODO
|
|
35 // Waiting should be done in Alice kernel
|
|
36 // ids.create(CommandType.WAIT);
|
|
37
|
|
38 wait(10);
|
|
39 } catch (InterruptedException e) {
|
|
40 e.printStackTrace();
|
|
41 }
|
|
42 }
|
115
|
43
|
133
|
44 new AutoIncrement(this.key,this.position.index);
|
111
|
45 }
|
|
46
|
|
47 }
|