view src/alice/test/topology/aquarium/AutoIncrement.java @ 217:b5c642ba998e working

change as** method and remove "local" key in TEST
author sugi
date Wed, 27 Mar 2013 20:02:38 +0900 (2013-03-27)
parents 21bd8af1cf26
children ccce30f84380
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 float min = -1.3f;
	private float max;
	
	public AutoIncrement(String key,int index){
		this.number.setKey("maxsize");
		this.position.setKey(key, index);
	}

	@Override
	public void run() {
		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);
	}
	
}