Mercurial > hg > Database > Alice
diff src/main/java/alice/test/topology/aquarium/AutoIncrement.java @ 345:8f71c3e6f11d
Change directory structure Maven standard
author | sugi |
---|---|
date | Wed, 16 Apr 2014 18:26:07 +0900 |
parents | |
children | aefbe41fcf12 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/AutoIncrement.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,47 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class AutoIncrement extends CodeSegment { + + private Receiver position = ids.create(CommandType.PEEK); + private Receiver number = ids.create(CommandType.PEEK); + private static final float MIN = -1.3f; + + public AutoIncrement(String key, int index) { + this.number.setKey("maxsize"); + this.position.setKey(key, index); + } + + @Override + public void run() { + float max = this.number.asInteger() * 2 - 1 + 0.3f; + FishPoint fp = this.position.asClass(FishPoint.class); + if (fp.getX() + 0.01 > max) { + fp.setXYZ(MIN, fp.getY(), fp.getZ()); + } else if (fp.getX() + 0.01 < MIN) { + fp.setXYZ(max, fp.getY(), fp.getZ()); + } + else { + fp.setXYZ(fp.getX() + 0.01f, fp.getY(), fp.getZ()); + } + + ods.update(position.key, fp); + synchronized (this) { + try { + // TODO + // Waiting should be done in Alice kernel + // ids.create(CommandType.WAIT); + + wait(20); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + new AutoIncrement(this.position.key, this.position.index); + } + +}