view src/main/java/alice/test/topology/aquarium/AutoIncrement.java @ 547:e91a574b69de dispose

remove index
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Tue, 18 Aug 2015 16:15:17 +0900
parents 15eeb439830c
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) {
        this.number.setKey("maxsize", this);
        this.position.setKey(key, this);
    }

    @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);
    }

}