view src/alice/test/topology/aquarium/fx/PositionController.java @ 14:e027d228c455

user fish has problem
author e095732
date Wed, 30 Jan 2013 18:20:48 +0900
parents 75f7a75bec83
children 9bacc8b30c4b
line wrap: on
line source

package alice.test.topology.aquarium.fx;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;

public class PositionController extends CodeSegment{
	
	private Receiver data = ids.create(CommandType.PEEK);
	double max = 1600;
	
	public PositionController(String key){
		this.data.setKey(key);
	}
	
	public PositionController(String key ,int index){
		this.data.setKey(key, index);
	}

	@Override
	public void run() {
		//System.out.println(data.val);
		synchronized(this){
			try {
				// TODO
				// Waiting should be done in Alice kernel
				// ids.create(CommandType.WAIT);
			 
				wait(20);
		
		FishData fd = data.asClass(FishData.class);
		if(fd.getX()+2.0>max){
			System.out.println("over "+this.data.key);
			fd.SetXYZ(0, fd.getY(), fd.getZ());
			
		} else {
			
			fd.SetXYZ(fd.getX()+3.0, fd.getY(), fd.getZ());
		}

		new PositionController(data.key, data.index);
		ods.update("local", data.key, fd);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}