changeset 435:cf2704424cc0

ChainCal task fix
author game@henri.cr.ie.u-ryukyu.ac.jp
date Thu, 24 Sep 2009 22:35:46 +0900
parents 481089375622
children 8eac9bf116d8
files TaskManager/Test/test_render/Application.cc TaskManager/Test/test_render/Application.h TaskManager/Test/test_render/Application/chain.cc TaskManager/Test/test_render/Func.h TaskManager/Test/test_render/SceneGraphRoot.cc TaskManager/Test/test_render/spe/ChainCal.cc TaskManager/Test/test_render/viewer.cc TaskManager/Test/test_render/viewer.h
diffstat 8 files changed, 71 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Application.cc	Thu Sep 24 20:44:11 2009 +0900
+++ b/TaskManager/Test/test_render/Application.cc	Thu Sep 24 22:35:46 2009 +0900
@@ -14,6 +14,11 @@
 }
 
 void
+Application::set_move_taskid(int id) {
+    this->move_taskid = id;
+}
+
+void
 Application::apply_property(PropertyPtr p, SceneGraphPtr sgptr)
 {
     sgptr->xyz[0] = p->xyz[0];
--- a/TaskManager/Test/test_render/Application.h	Thu Sep 24 20:44:11 2009 +0900
+++ b/TaskManager/Test/test_render/Application.h	Thu Sep 24 22:35:46 2009 +0900
@@ -11,15 +11,17 @@
     Application();
     ~Application();
     
-    void* propertyPtr;
-
+    void *propertyPtr;
+    int property_size;
     void set_move_func(move_func move);
     void set_coll_func(coll_func coll);
+    void set_move_taskid(int id);
 //    SceneGraphPtr scenegraph_factory(PropertyPtr p);
 //    SceneGraphPtr scenegraph_connector(PropertyPtr p,SceneGraphPtr s);
     SceneGraphPtr scenegraph_factory(void *p, int size);
     SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s);
-
+    abstract void init(TaskManager *manager, int w, int h);
+    int move_taskid;
     move_func move;
     coll_func coll;
 };
--- a/TaskManager/Test/test_render/Application/chain.cc	Thu Sep 24 20:44:11 2009 +0900
+++ b/TaskManager/Test/test_render/Application/chain.cc	Thu Sep 24 22:35:46 2009 +0900
@@ -115,14 +115,14 @@
 }
 
 void
-Chain::chain_init(TaskManager *manager, int w, int h)
+Chain::init(TaskManager *manager, int w, int h)
 {
     SceneGraphPtr root_chain, chain;
     CHAIN_VARS rcv;
 
     HTaskPtr chain_init;
     
-    
+    set_move_taskid(CHAIN_CAL);
     sgroot->createFromXMLfile(manager, "xml_file/chain.xml");
 
     /* SPE に送る property の配列の領域確保 */
--- a/TaskManager/Test/test_render/Func.h	Thu Sep 24 20:44:11 2009 +0900
+++ b/TaskManager/Test/test_render/Func.h	Thu Sep 24 22:35:46 2009 +0900
@@ -22,6 +22,7 @@
      TASK_MOVE,
      TASK_DRAW,
      TASK_DUMMY,
+     TASK_SG_UPDATE,
 
      CHAINCAL_TASK,
      CHAININIT_TASK,
--- a/TaskManager/Test/test_render/SceneGraphRoot.cc	Thu Sep 24 20:44:11 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraphRoot.cc	Thu Sep 24 22:35:46 2009 +0900
@@ -198,7 +198,7 @@
     /*removeのflagをもとにtreeを形成*/
     /* spe から送り返されてきた property の配列を見て生成する for()*/
     
-    for (Property *t = property[0]; is_end(t); t++){
+    for (Property *t = property[0]; is_end(t); t++) {
 	SceneGraphPtr s = application->scenegraph_factory(t); // SceneGraphNode を作る
 	t->scenegraph = s; // property list には SceneGraphへのポインタが入っている
 	application->scenegraph_connector(property[0], s, sg_available_list); // add する
--- a/TaskManager/Test/test_render/spe/ChainCal.cc	Thu Sep 24 20:44:11 2009 +0900
+++ b/TaskManager/Test/test_render/spe/ChainCal.cc	Thu Sep 24 22:35:46 2009 +0900
@@ -31,61 +31,62 @@
 int
 ChainCal::run(void *rbuf, void *wbuf)
 {
+    CHAIN_VARS *property = (CHAIN_VARS*)get_input(rbuf, 0);
+    CHAIN_VARS *update_property = (CHAIN_VARS*)get_output(wbuf, 0);
+ 
     CHAIN_VARS* property = (CHAIN_VARS*)rbuf;
     int id = get_param(0);
     
-    //CHAIN_VARS* o_property = (CHAIN_VARS*)wbuf;
-    
     for(int cnt = 0; cnt < 600; cnt++) {
-		for(int i = 0; i < CHAIN_LEN; i++) {
-			if(property[i].can_move) {
-				double dx = property[i-1].x - property[i].x;
-				double dy = property[i-1].y - property[i].y;
-				double l = sqrt(dx * dx + dy * dy);
-				double a = k * (l - chain_width) / m;
-				double ax = a * dx / l;
-				double ay = a * dy / l;
-				if(i < CHAIN_LEN - 1) {
-					dx = property[i+1].x - property[i].x;
-					dy = property[i+1].y - property[i].y;
-					l = sqrt(dx * dx + dy * dy);
-					a = k * (l - chain_width) / m;
-					ax += a * dx / l;
-					ay += a * dy / l;
-				}
-				ay += g;
-				property[i].vx *= safe;
-				property[i].vy *= safe;
-				property[i].next_vx = property[i].vx + ax * dt;
-				property[i].next_vy = property[i].vy + ay * dt;
-				property[i].next_x = property[i].x + property[i].vx * dt;
-				property[i].next_y = property[i].y + property[i].vy * dt;
-			} else {
-				property[i].next_x = property[i].x;
-				property[i].next_y = property[i].y;
-			}
+	for(int i = 0; i < CHAIN_LEN; i++) {
+	    if(property[i].can_move) {
+		double dx = property[i-1].x - property[i].x;
+		double dy = property[i-1].y - property[i].y;
+		double l = sqrt(dx * dx + dy * dy);
+		double a = k * (l - chain_width) / m;
+		double ax = a * dx / l;
+		double ay = a * dy / l;
+		if(i < CHAIN_LEN - 1) {
+		    dx = property[i+1].x - property[i].x;
+		    dy = property[i+1].y - property[i].y;
+		    l = sqrt(dx * dx + dy * dy);
+		    a = k * (l - chain_width) / m;
+		    ax += a * dx / l;
+		    ay += a * dy / l;
 		}
-		for(int i = 0; i < CHAIN_LEN; i++) {
-			property[i].vx = property[i].next_vx;
-			property[i].vy = property[i].next_vy;
-			property[i].x = property[i].next_x;
-			property[i].y = property[i].next_y;
-		}
+		ay += g;
+		property[i].vx *= safe;
+		property[i].vy *= safe;
+		property[i].next_vx = property[i].vx + ax * dt;
+		property[i].next_vy = property[i].vy + ay * dt;
+		property[i].next_x = property[i].x + property[i].vx * dt;
+		property[i].next_y = property[i].y + property[i].vy * dt;
+	    } else {
+		property[i].next_x = property[i].x;
+		property[i].next_y = property[i].y;
+	    }
+	}
+	for(int i = 0; i < CHAIN_LEN; i++) {
+	    property[i].vx = property[i].next_vx;
+	    property[i].vy = property[i].next_vy;
+	    property[i].x = property[i].next_x;
+	    property[i].y = property[i].next_y;
+	}
     }
 	
     for (int j = 0; j < CHAIN_LEN; j++) {
-		int p, n;
-		id = property[j].id;
-		p = n = id;
-		if(p != 0) {
-			p--;
-		}
-		if(n != CHAIN_LEN - 1) {
-			n++;
-		}
-		property[j].angle[2-(id%2)*2]
-			= 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI;
+	int p, n;
+	id = property[j].id;
+	p = n = id;
+	if(p != 0) {
+	    p--;
+	}
+	if(n != CHAIN_LEN - 1) {
+	    n++;
+	}
+	property[j].angle[2-(id%2)*2]
+	    = 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI;
     }
-    
+    memcpy((void*)update_property, (void*)property, sizeof(CHAIN_VARS) * CHAIN_LEN);
     return 0;
 }
--- a/TaskManager/Test/test_render/viewer.cc	Thu Sep 24 20:44:11 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.cc	Thu Sep 24 22:35:46 2009 +0900
@@ -108,7 +108,6 @@
 void
 Viewer::run_init(TaskManager *manager, const char *xml, int sg_number)
 {
-    Application application;
     this->manager = manager;
 
     start_time = get_ticks();
@@ -165,7 +164,7 @@
     case 16:
         //chain_init(manager, this->width, this-> height);
 	application = new Chain();
-	application->chain_init(manager, this->width, this->height);
+	application->init(manager, this->width, this->height);
 	speInit();
 	return;
         break;
@@ -311,14 +310,17 @@
     update_key->spawn();
 
     /* TASK_MOVE は外から引数で取ってくるべき */
-    //HTaskPtr move_task = viewer->manager->create_task(viewer->move_taskid);    
-    HTaskPtr move_task = viewer->manager->create_task(TASK_MOVE);
-    move_task->add_param(sgroot_2);
+    //HTaskPtr move_task = viewer->manager->create_task(viewer->move_taskid);
+    HTaskPtr move_task = viewer->manager->create_task(application->move_taskid);
+    move_task->add_inData(application->propertyPtr, application->property_size);
+    move_task->add_outData(application->propertyPtr, application->property_size);
+
+    HTaskPtr sg_update_task = viewer->manager->create_task(TASK_SG_UPDATE);
 
     HTaskPtr draw_task = viewer->manager->create_task(TASK_DRAW);
     move_task->add_param(sgroot);
 
-    HTaskPtr switch_task = viewer->manager->create_task(TASK_SWITCH);
+    HTaskPtr switch_task = viewer->manager->create_task(                                TASK_SWITCH);
 
     switch_task->wait_for(move_task);
     switch_task->wait_for(draw_task);
--- a/TaskManager/Test/test_render/viewer.h	Thu Sep 24 20:44:11 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.h	Thu Sep 24 22:35:46 2009 +0900
@@ -14,7 +14,7 @@
 
     virtual ~Viewer(void) {}
 
-    //Application *application;
+    Application *application;
 
     TaskManager *manager;
     key_stat *keyPtr;