Mercurial > hg > Database > Alice
view src/alice/test/topology/aquarium/AutoIncrement.java @ 278:04c769f00be1
Follow coding rules.
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Oct 2013 01:57:43 +0900 |
parents | ba4eea27d70d |
children |
line wrap: on
line source
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); } }