diff TaskManager/Test/test_render/Application/Chain.cc @ 509:9f23e9d4973f draft

Application ander constructing
author game@henri.cr.ie.u-ryukyu.ac.jp
date Tue, 20 Oct 2009 23:25:22 +0900
parents 5d8e364027d5
children 8d86242337ba
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Application/Chain.cc	Mon Oct 12 11:27:13 2009 +0900
+++ b/TaskManager/Test/test_render/Application/Chain.cc	Tue Oct 20 23:25:22 2009 +0900
@@ -6,16 +6,17 @@
 #include "TaskManager.h"
 #include "Func.h"
 #include "Chain.h"
+#include "Application.h"
 #define FALSE 0
 #define TRUE !FALSE
 #define CHAIN_LEN 50
 
 static double chain_width = 10;
-
+static void post2propertyLoop(void *chain);
 
 /* SceneGraph の property */
-ChainPropertyPtr properties[2];
-ChainPropertyPtr property;
+//ChainPropertyPtr c_properties[2];
+//ChainPropertyPtr c_property;
 
 
 //void createSceneGraphFromProperty(ChainPropertyPtr p) ;
@@ -64,28 +65,26 @@
 #endif
 
 void
-Chain::chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h)
+Chain::chain_switch()
 {
-    int id = sg->id;
-    //ChainPropertyPtr p = (ChainPropertyPtr)sg->propertyptr;
     HTaskPtr chain_cal;
     ChainPropertyPtr output;
 
     // SceneGraph の切り替えもここでやる
     if (property == properties[0]) {
-      property = properties[1];
-      output   = properties[0];
+	property = (ChainPropertyPtr)properties[1];
+	output   = (ChainPropertyPtr)properties[0];
+
     }else{
-      property = properties[0];
-      output   = properties[1];
+	property = (ChainPropertyPtr)properties[0];
+	output   = (ChainPropertyPtr)properties[1];
     }
+
     chain_cal = manager->create_task(CHAINCAL_TASK);
     chain_cal->add_inData(property, sizeof(ChainProperty)*CHAIN_LEN);
-    chain_cal->add_param(id);
     chain_cal->add_outData(output, sizeof(ChainProperty)*CHAIN_LEN);
-    chain_cal->set_post(createSceneGraphFromProperty, (void*)id);
+    chain_cal->set_post(post2propertyLoop, (void *)sg_available_list);
     chain_cal->spawn();
-
 }
 
 void
@@ -117,19 +116,101 @@
     sgptr->angle[0] = cp->angle[0];
     sgptr->angle[1] = cp->angle[1];
     sgptr->angle[2] = cp->angle[2];
+    
+    cp->frame++;
+    sgptr->frame = cp->frame;
+}
 
-    sgptr->frame++;
+SceneGraphPtr
+Chain::scenegraph_factory(void *p)
+{
+    ChainPropertyPtr cp = (ChainPropertyPtr)p;
+    SceneGraphPtr sgptr =  (SceneGraphPtr)cp->scenegraph;
+    apply_property(p, sgptr);
+    
+    return sgptr;
 }
 
 void
-Chain::init(TaskManager *manager, int w, int h)
+Chain::scenegraph_connector(void *p, SceneGraphPtr sg)
+{
+    ChainPropertyPtr cp = (ChainPropertyPtr)p;
+    SceneGraphPtr last = sg_available_list;
+
+    if (!last) {
+	sg_available_list = sg;
+    } else {
+	while (last->next) {
+	    last = last->next;
+	}
+	last->next = sg;
+	sg->prev = last;
+    }
+
+    ChainPropertyPtr p_curent = (ChainPropertyPtr)sg->propertyptr;
+
+    // parent_id が 0 , NULL だったらどうすんだ?
+    // そこで試合終了じゃね?
+    // if ( p_curent_id->parent_id == 0) return -1;
+    ChainProperty p_parent = cp[p_curent->parent_id];
+    SceneGraphPtr s_parent = (SceneGraphPtr)p_parent.scenegraph;
+
+    /* childrenのリストの最後に加える (brother として)*/
+    if (s_parent->lastChild != NULL) {
+        SceneGraphPtr last_child = s_parent->lastChild;
+        last_child->brother = sg;
+    }
+
+    s_parent->lastChild = sg;
+
+    if (s_parent->children == NULL) {
+        s_parent->children = sg;
+    }
+
+    sg->parent = s_parent;
+}
+
+int
+is_end(ChainPropertyPtr t)
+{
+    // どうやって終了させよう?
+    // property の個数を保持する必要がある?
+    // or for文ではなくて、条件にする 
+
+    return 0;
+}
+
+void
+Chain::property_loop()
+{
+    for (ChainPropertyPtr t = &property[0]; is_end(t); t++){
+	SceneGraphPtr sg = scenegraph_factory(t); // SceneGraphNode を作る
+	t->scenegraph = (void *)sg; // property list には SceneGraphへのポインタが入っている
+	scenegraph_connector((void *)properties[0], sg); // add する
+    }
+}
+
+void
+post2propertyLoop(void *chain_)
+{
+    Application *chain = (Application *)chain_;
+    //chain->property_loop(chain->sg_available_list);
+    chain->property_loop();
+}
+
+void
+Chain::property_ope(SceneGraphPtr sg_available_list_)
+{
+    sg_available_list = sg_available_list_;
+    chain_switch();
+}
+
+void
+Chain::init(TaskManager *manager_, int w, int h)
 {
     SceneGraphPtr root_chain, chain;
-    ChainPropertyPtr rcv;
-	ChainProperty r;
-    HTaskPtr chain_init;
-
-	rcv = &r;    
+    ChainProperty r;
+    manager = manager_;
     
     sgroot->createFromXMLfile(manager, "xml_file/chain.xml");
 
@@ -139,41 +220,31 @@
     property = properties[0];
 
     root_chain = sgroot->createSceneGraph(CHAIN);
-    // set_move_collision()ではだめ
-//    root_chain->set_move_collision(chain_move_ope, chain_collision);
-	init_chain_vars(rcv);
-    rcv->next_x = w / 2;
-    rcv->next_y = 0.0;
-    rcv->angle[0] = 0;
-    rcv->angle[1] = 0;
-    rcv->angle[2] = 0;
+    init_chain_vars(&property[0]);
+    property[0].next_x = w / 2;
+    property[0].next_y = 0.0;
+    property[0].angle[0] = 0;
+    property[0].angle[1] = 0;
+    property[0].angle[2] = 0;
 
-    set_vector(rcv, root_chain);
+    set_vector(&property[0], root_chain);
 
-    for(int i = 0; i < CHAIN_LEN; i++) {
+    for(int i = 1; i < CHAIN_LEN; i++) {
         chain = sgroot->createSceneGraph(CHAIN);
-        property[i].id = i;
+	property[i].id = i;
         init_chain_vars(&property[i]);
         property[i].x = 0;
         property[i].y = chain_width * i;
         set_vector(&property[i], chain);
-        property->angle[1] = -90 * (i % 2);
-        //chain->set_move_collision(chain_move, chain_collision);
-		chain->propertyptr = &property[i];
-		chain->property_size = sizeof(ChainProperty);
+        property[i].angle[1] = -90 * (i % 2);        
+	chain->propertyptr = &property[i];
+	chain->property_size = sizeof(ChainProperty);
         root_chain->addChild(chain);
-		property[i].parent = root_chain;
+	property[i].parent = root_chain;
+	property[i].parent_id = 0;
     }
     property[0].can_move = FALSE;
 
-    // property を SPU の共有領域へコピーする
-    chain_init = manager->create_task(CHAININIT_TASK);
-    chain_init->add_inData(property, sizeof(ChainProperty)*CHAIN_LEN);
-    chain_init->add_param(CHAIN_LEN);
-    chain_init->set_cpu(SPE_0);
-    chain_init->set_post(createSceneGraphFromProperty, (void*)property);
-    chain_init->spawn();
-
     sgroot->setSceneData(root_chain);
 }