comparison src/main/java/alice/test/topology/aquarium/AutoIncrement.java @ 419:aefbe41fcf12 dispose

change tab to space
author sugi
date Tue, 15 Jul 2014 16:00:22 +0900
parents 8f71c3e6f11d
children 15eeb439830c
comparison
equal deleted inserted replaced
418:a269a019f5f8 419:aefbe41fcf12
3 import alice.codesegment.CodeSegment; 3 import alice.codesegment.CodeSegment;
4 import alice.datasegment.CommandType; 4 import alice.datasegment.CommandType;
5 import alice.datasegment.Receiver; 5 import alice.datasegment.Receiver;
6 6
7 public class AutoIncrement extends CodeSegment { 7 public class AutoIncrement extends CodeSegment {
8
9 private Receiver position = ids.create(CommandType.PEEK);
10 private Receiver number = ids.create(CommandType.PEEK);
11 private static final float MIN = -1.3f;
12
13 public AutoIncrement(String key, int index) {
14 this.number.setKey("maxsize");
15 this.position.setKey(key, index);
16 }
17 8
18 @Override 9 private Receiver position = ids.create(CommandType.PEEK);
19 public void run() { 10 private Receiver number = ids.create(CommandType.PEEK);
20 float max = this.number.asInteger() * 2 - 1 + 0.3f; 11 private static final float MIN = -1.3f;
21 FishPoint fp = this.position.asClass(FishPoint.class); 12
22 if (fp.getX() + 0.01 > max) { 13 public AutoIncrement(String key, int index) {
23 fp.setXYZ(MIN, fp.getY(), fp.getZ()); 14 this.number.setKey("maxsize");
24 } else if (fp.getX() + 0.01 < MIN) { 15 this.position.setKey(key, index);
25 fp.setXYZ(max, fp.getY(), fp.getZ()); 16 }
26 } 17
27 else { 18 @Override
28 fp.setXYZ(fp.getX() + 0.01f, fp.getY(), fp.getZ()); 19 public void run() {
29 } 20 float max = this.number.asInteger() * 2 - 1 + 0.3f;
30 21 FishPoint fp = this.position.asClass(FishPoint.class);
31 ods.update(position.key, fp); 22 if (fp.getX() + 0.01 > max) {
32 synchronized (this) { 23 fp.setXYZ(MIN, fp.getY(), fp.getZ());
33 try { 24 } else if (fp.getX() + 0.01 < MIN) {
34 // TODO 25 fp.setXYZ(max, fp.getY(), fp.getZ());
35 // Waiting should be done in Alice kernel 26 }
36 // ids.create(CommandType.WAIT); 27 else {
37 28 fp.setXYZ(fp.getX() + 0.01f, fp.getY(), fp.getZ());
38 wait(20); 29 }
39 } catch (InterruptedException e) { 30
40 e.printStackTrace(); 31 ods.update(position.key, fp);
41 } 32 synchronized (this) {
42 } 33 try {
43 34 // TODO
44 new AutoIncrement(this.position.key, this.position.index); 35 // Waiting should be done in Alice kernel
45 } 36 // ids.create(CommandType.WAIT);
46 37
38 wait(20);
39 } catch (InterruptedException e) {
40 e.printStackTrace();
41 }
42 }
43
44 new AutoIncrement(this.position.key, this.position.index);
45 }
46
47 } 47 }