changeset 111:ba64a9d76e70 working

Add AutoIncrement
author sugi
date Tue, 17 Jul 2012 17:23:55 +0900
parents aa9fc077c286
children 912aed91d05b
files src/alice/test/topology/fishmodel/alpha/AutoIncrement.java src/alice/test/topology/fishmodel/alpha/CheckFishLocation.java src/alice/test/topology/fishmodel/alpha/CheckMyName.java src/alice/test/topology/fishmodel/alpha/MakeFrame.java src/alice/test/topology/fishmodel/alpha/MakeObject.java src/alice/test/topology/fishmodel/alpha/SetLocation.java src/alice/test/topology/fishmodel/beta/AddRoutingTable.java src/alice/test/topology/fishmodel/beta/CheckMyName.java
diffstat 8 files changed, 99 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fishmodel/alpha/AutoIncrement.java	Tue Jul 17 17:23:55 2012 +0900
@@ -0,0 +1,34 @@
+package alice.test.topology.fishmodel.alpha;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class AutoIncrement extends CodeSegment {
+	
+	public Receiver position = ids.create(CommandType.PEEK);	
+	String key;
+	
+	public AutoIncrement(String key,int index){
+		
+		this.key = key;
+		this.position.setKey("local", key);
+		
+	}
+
+	@Override
+	public synchronized void run() {
+		FishPoint FP = this.position.asClass(FishPoint.class);
+		FP.setXY(FP.getX()+0.01f, FP.getY());
+		ods.update("local", key, FP);
+		try {
+			wait(100);
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		new AutoIncrement(this.key,this.position.index);
+		
+	}
+	
+}
--- a/src/alice/test/topology/fishmodel/alpha/CheckFishLocation.java	Sun Jul 15 21:32:48 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-package alice.test.topology.fishmodel.alpha;
-
-import alice.codesegment.CodeSegment;
-import alice.datasegment.CommandType;
-import alice.datasegment.Receiver;
-
-
-public class CheckFishLocation extends CodeSegment{
-	
-	private Receiver position = ids.create(CommandType.PEEK);
-	MakeObject obj;
-	String key;
-	int range;
-	
-	public CheckFishLocation(MakeObject MO ,String key,int index,int range){
-		this.obj = MO;
-		this.key = key;
-		this.range = range;
-		this.position.setKey("local",key,index);
-	}
-	
-	@Override
-	public void run(){
-		
-		FishPoint FP = this.position.asClass(FishPoint.class);
-		obj.setLocation(FP.getX(), FP.getY());
-		/*
-		float startX = 2*range - 1;
-		float endX = 2*range + 1;
-		if (startX <= FP.getX() && FP.getX() < endX)
-			obj.setLocation(FP.getX() - 2*range, FP.getY());
-		*/
-		new CheckFishLocation(this.obj,this.key,this.position.index,this.range);
-					
-	}
-	
-
-}
--- a/src/alice/test/topology/fishmodel/alpha/CheckMyName.java	Sun Jul 15 21:32:48 2012 +0900
+++ b/src/alice/test/topology/fishmodel/alpha/CheckMyName.java	Tue Jul 17 17:23:55 2012 +0900
@@ -31,7 +31,7 @@
 			
 			MakeObject obj3 = new MakeObject(frame);
 			frame.register(obj3);
-			new CheckFishLocation(obj3,key,0,num);
+			new SetLocation(obj3,key,0,num);
 			new CheckLocalIndex(key,0);
 			new CheckParentIndex(key,0);
 			/*
--- a/src/alice/test/topology/fishmodel/alpha/MakeFrame.java	Sun Jul 15 21:32:48 2012 +0900
+++ b/src/alice/test/topology/fishmodel/alpha/MakeFrame.java	Tue Jul 17 17:23:55 2012 +0900
@@ -95,9 +95,8 @@
 		this.universe.addBranchGraph(group);
 	}
 	
-	public void registerKObj(MakeObject obj){
-		BranchGroup group = obj.createKeyBranch();
-		this.universe.addBranchGraph(group);
+	public SimpleUniverse getUniverse(){
+		return this.universe;
 	}
 	
 	public Canvas3D getCanvas(){
--- a/src/alice/test/topology/fishmodel/alpha/MakeObject.java	Sun Jul 15 21:32:48 2012 +0900
+++ b/src/alice/test/topology/fishmodel/alpha/MakeObject.java	Tue Jul 17 17:23:55 2012 +0900
@@ -4,7 +4,6 @@
 import java.awt.MediaTracker;
 import java.awt.Toolkit;
 import java.io.FileNotFoundException;
-//import java.io.File;
 
 import javax.media.j3d.Appearance;
 import javax.media.j3d.BranchGroup;
@@ -12,40 +11,26 @@
 import javax.media.j3d.Texture;
 import javax.media.j3d.Transform3D;
 import javax.media.j3d.TransformGroup;
+import javax.vecmath.Vector3d;
 import javax.vecmath.Vector3f;
 
 import com.sun.j3d.loaders.IncorrectFormatException;
 import com.sun.j3d.loaders.ParsingErrorException;
 import com.sun.j3d.loaders.Scene;
 import com.sun.j3d.loaders.objectfile.ObjectFile;
-import com.sun.j3d.utils.geometry.Box;
+
 import com.sun.j3d.utils.image.TextureLoader;
 
 public class MakeObject {
 	
 	public Vector3f vector;
-	Transform3D transform;  
-	TransformGroup transform_group;
-	Canvas3D canvas;
-	KeyInput key;
-	KeyInputCodeSegment KIC; 
+	private Transform3D transform;  
+	private TransformGroup transform_group;
+	private Canvas3D canvas;
 	
 	public MakeObject(MakeFrame MF){
 		this.canvas = MF.getCanvas();
-		//this.key = MF.getKey();
-		this.KIC = MF.getKeySegment();
-	}
-	
-		
-	public BranchGroup createKeyBranch(){
-		BranchGroup scene = new BranchGroup();
-		Box box = new Box(0.1f,0.1f,0.0f,
-				Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());
-		key.transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
-		key.transformGroup.addChild(box);
-		scene.addChild(key.transformGroup);
-		return scene;
-		
+		MF.register(this);
 	}
 	
 	public BranchGroup createBranch(){
@@ -55,7 +40,7 @@
 		ObjectFile obj = new ObjectFile(ObjectFile.RESIZE);
 		Scene S = null;
 		try{
-			S = obj.load("../image/galleon.obj");
+			S = obj.load("../image/TUNA.OBJ");
 		} catch(FileNotFoundException e){
 			System.err.println(e);
 			System.exit(1);
@@ -74,7 +59,7 @@
 		return scene;		
 	}
 	
-	private Appearance createAppearance(){
+	public Appearance createAppearance(){
 		Appearance app = new Appearance();
 		Image image = null; 	
 		Toolkit toolkit = Toolkit.getDefaultToolkit();
@@ -100,6 +85,7 @@
 		transform = new Transform3D();
 		vector = new Vector3f(x,y,0.0f);
 		transform.setTranslation(vector);
+		transform.setScale(new Vector3d(0.5d, 0.5d, 0.5d));
 		transform_group.setTransform(transform);
 	}
 	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fishmodel/alpha/SetLocation.java	Tue Jul 17 17:23:55 2012 +0900
@@ -0,0 +1,39 @@
+package alice.test.topology.fishmodel.alpha;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+
+public class SetLocation extends CodeSegment{
+	
+	private Receiver position = ids.create(CommandType.PEEK);
+	MakeObject obj;
+	String key;
+	int range;
+	
+	public SetLocation(MakeObject MO ,String key,int index,int range){
+		this.obj = MO;
+		this.key = key;
+		this.range = range;
+		this.position.setKey("local",key,index);
+	}
+	
+	@Override
+	public void run(){
+		
+		FishPoint FP = this.position.asClass(FishPoint.class);
+		obj.setLocation(FP.getX() - 2*range, FP.getY());
+		/*
+		float startX = 2*range - 1;
+		float endX = 2*range + 1;
+		if (startX <= FP.getX() && FP.getX() < endX)
+			obj.setLocation(FP.getX() - 2*range, FP.getY());
+		System.out.println(this.position.key);
+		*/
+		new SetLocation(this.obj,this.key,this.position.index,this.range);
+					
+	}
+	
+
+}
--- a/src/alice/test/topology/fishmodel/beta/AddRoutingTable.java	Sun Jul 15 21:32:48 2012 +0900
+++ b/src/alice/test/topology/fishmodel/beta/AddRoutingTable.java	Tue Jul 17 17:23:55 2012 +0900
@@ -20,7 +20,7 @@
 		System.out.println("add "+this.mail.from);
 		routing.table.add(new Routing(this.mail.from));
 		
-		ods.update("local", "list", routing);
+		ods.update("local", "list", this.routing);
 		new AddRoutingTable(this.routing,this.mail.index);
 		
 	}
--- a/src/alice/test/topology/fishmodel/beta/CheckMyName.java	Sun Jul 15 21:32:48 2012 +0900
+++ b/src/alice/test/topology/fishmodel/beta/CheckMyName.java	Tue Jul 17 17:23:55 2012 +0900
@@ -6,7 +6,8 @@
 import alice.codesegment.CodeSegment;
 import alice.datasegment.CommandType;
 import alice.datasegment.Receiver;
-import alice.test.topology.fishmodel.alpha.CheckFishLocation;
+import alice.test.topology.fishmodel.alpha.AutoIncrement;
+import alice.test.topology.fishmodel.alpha.SetLocation;
 import alice.test.topology.fishmodel.alpha.FishPoint;
 import alice.test.topology.fishmodel.alpha.MakeFrame;
 import alice.test.topology.fishmodel.alpha.MakeObject;
@@ -27,8 +28,10 @@
 		String type = matcher.group(1);
 		int num = new Integer(matcher.group(2));
 		
+		MakeFrame frame =  new MakeFrame(name);
 		RoutingTable routing = new RoutingTable();
-		ods.update("local", key, new FishPoint(0.0f,0.0f));
+		
+		
 		
 		if (type.equals("cli")){
 			System.out.println("cli"+num);
@@ -44,19 +47,20 @@
 				routing.table.add(new Routing("parent"));
 				ods.put("parent", "member", name);
 				
-				
 			}
 			ods.put("local", "list", routing);
 			new AddRoutingTable(routing,0);
 			
 		}
 		
-		MakeFrame frame =  new MakeFrame(name);
+		ods.update("local", key, new FishPoint(0.0f,0.0f));
+		new SetLocation(new MakeObject(frame),key,0,num);
+		new CheckLocalIndex(key,1);
+		key = "fish1";
+		if (num == 0) new AutoIncrement(key,0);
+		ods.update("local", key, new FishPoint(0.0f,0.0f));
+		new SetLocation(new MakeObject(frame),key,0,num);
+		new CheckLocalIndex(key,1);
 		
-		MakeObject obj3 = new MakeObject(frame);
-		frame.register(obj3);
-		new CheckFishLocation(obj3,key,0,num);
-		
-		new CheckLocalIndex(key,1);
 	}
 }