changeset 760:24a37fe8419a

first of all commit, not work Rendering/Test/create_task
author hiroki
date Thu, 04 Feb 2010 14:46:09 +0900
parents bb47827c04c1
children be6e43d977d1
files Renderer/Engine/RenderingTasks.h Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraph.h Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/SceneGraphRoot.h Renderer/Engine/SgChange.cc Renderer/Engine/spe/Property.cc Renderer/Engine/task/RunMove.cc Renderer/Engine/task/task_init.cc Renderer/Engine/viewer.cc Renderer/Test/create_task.cc
diffstat 11 files changed, 196 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/RenderingTasks.h	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/RenderingTasks.h	Thu Feb 04 14:46:09 2010 +0900
@@ -19,6 +19,7 @@
 
      Move,
      RunMove,
+     ExecMove,
      Draw,
 
      // Dummy,
--- a/Renderer/Engine/SceneGraph.cc	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/SceneGraph.cc	Thu Feb 04 14:46:09 2010 +0900
@@ -535,6 +535,12 @@
     (*collision)(this, this->sgroot, w, h, tree);
 }
 
+void
+SceneGraph::create_sg_execute()
+{
+    (*create_sg)(this->sgroot, property, update_property);
+}
+
 
 void
 SceneGraph::set_move_collision(move_func new_move,
@@ -556,6 +562,15 @@
 }
 
 void
+SceneGraph::set_move_collision(move_func new_move,
+                               collision_func new_collision, create_sg_func new_create_sg)
+{
+    this->move = new_move;
+    this->collision = new_collision;
+    this->create_sg = new_create_sg;
+}
+
+void
 SceneGraph::add_next(SceneGraphPtr next)
 {
     /* next のリストの最後に加える */
--- a/Renderer/Engine/SceneGraph.h	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/SceneGraph.h	Thu Feb 04 14:46:09 2010 +0900
@@ -12,6 +12,7 @@
 //                               SceneGraph* tree);
 typedef void (*collision_func)(SceneGraph* node, void *sgroot, int screen_w, int screen_h,
                                SceneGraph* tree);
+typedef void (*create_sg_func)(void *sgroot, void *property, void *update_property);
 typedef SceneGraph* SceneGraphPtr;
 
 class SceneGraph : public Polygon {
@@ -34,7 +35,9 @@
 	int seq;
 	
     int property_size;
-    void* propertyptr;
+    void *propertyptr;
+    void *property;
+    void *update_property;
 
     // xml ファイルから生成した時のオブジェクトリスト
     SceneGraphPtr next;
@@ -65,6 +68,7 @@
     // 関数ポインタ
     move_func move;
     collision_func collision;
+    create_sg_func create_sg;
 
     // desutroctor で呼ばれる
     void (SceneGraph::*finalize)(void);
@@ -74,6 +78,7 @@
     void finalize_copy(void);
     void move_execute(int screen_w, int screen_h);
     void collision_check(int screen_w, int screen_h, SceneGraphPtr tree);
+    void create_sg_execute();
     void all_execute(int screen_w, int screen_h);
 
     void add_next(SceneGraphPtr next);
@@ -84,6 +89,7 @@
     SceneGraphPtr searchSceneGraph(const char *name);
     void set_move_collision(move_func new_move, collision_func new_collision);
     void set_move_collision(move_func new_move, collision_func new_collision, void *sgroot);
+    void set_move_collision(move_func new_move, collision_func new_collision, create_sg_func new_create_sg);
     void remove(void);
     SceneGraphPtr realRemoveFromTree(SceneGraphPtr tree);
     SceneGraphPtr realRemoveFromList(SceneGraphPtr list);
--- a/Renderer/Engine/SceneGraphRoot.cc	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Thu Feb 04 14:46:09 2010 +0900
@@ -36,6 +36,8 @@
 
     sgroot = this;
 
+    screen_w = (int)w;
+    screen_h = (int)h;
     //int size = 4;
     //light_vector = (float*)malloc(sizeof(float)*size);
 
@@ -43,7 +45,7 @@
     light->xyz[1] = 0;
     light->xyz[2] = 0;
 
-
+    move_finish_flag = 0;
     // TODO
     //   今はとりあえず camera を Root にしています
     //   今はそれすらもしてません
@@ -483,8 +485,8 @@
 SceneGraphRoot::oneExecute(int screen_w, int screen_h)
 {
     SceneGraphPtr list = sg_available_list;
-    SceneGraphPtr t = sg_exec_tree;
-    SceneGraphPtr cur_parent = camera;
+    //SceneGraphPtr t = sg_exec_tree;
+    //SceneGraphPtr cur_parent = camera;
 
     // 前フレームで描画した SceneGraph は削除
     allRemove(sg_remove_list);
@@ -506,6 +508,12 @@
 
     /* ここから */
     list->move_execute(screen_w, screen_h);
+    // ここで move_execute から実行される move_task の処理が終わるまで待ちたい
+    //while(move_finish_flag == 0) {}
+    //move_finish_flag = 0;
+
+    list->create_sg_execute();
+    
     list->collision_check(screen_w, screen_h, list);	
     /* ここまで exec_task にする */
     
@@ -531,16 +539,55 @@
     }
 }
 
+/*
+  ExecMove task の post func として呼んでやる
+ */
+void
+SceneGraphRoot::move_finish()
+{    
+    list->collision_check(screen_w, screen_h, list);	
+
+    list->frame++; 
+    //list = list->next;
+    
+    get_matrix(light->matrix, light->angle, light->xyz, camera->matrix);
+
+    light_vector[0] = 0.0f;
+    light_vector[1] = 0.0f;
+    light_vector[2] = 0.0f;
+    light_vector[3] = 1.0f;
+
+    ApplyMatrix(light_vector, light->matrix);
+
+    light_vector[0] /= light_vector[2];
+    light_vector[1] /= light_vector[2];
+    
+    //sgchange->viewer->light_xyz_stock = getLightVector();
+}
+
+
+void
+SceneGraphRoot::appTaskRegist(regist_func new_register)
+{
+    this->regist = new_register;
+}
+
+void
+SceneGraphRoot::regist_execute()
+{
+    (*regist)(this);
+}
+
 void
 SceneGraphRoot::allRemove(SceneGraphPtr list)
 {
     SceneGraphPtr p = list;
-
+    
     while (p) {
-		SceneGraphPtr p1 = p->next;
-		delete p;
-		p = p1;
-		cnt--;
+	SceneGraphPtr p1 = p->next;
+	delete p;
+	p = p1;
+	cnt--;
     }
 }
 
@@ -549,15 +596,15 @@
 {
     SceneGraphPtr p = sg_available_list;
     SceneGraphPtr p1;
-
+    
     while (p) {
-		p1 = p->next;
-		if (p->isRemoved()) {
-			sg_exec_tree = p->realRemoveFromTree(sg_exec_tree);
-			sg_available_list = p->realRemoveFromList(sg_available_list);
-		}
-		delete p;
-		p = p1;
+	p1 = p->next;
+	if (p->isRemoved()) {
+	    sg_exec_tree = p->realRemoveFromTree(sg_exec_tree);
+	    sg_available_list = p->realRemoveFromList(sg_available_list);
+	}
+	delete p;
+	p = p1;
     }
 }
 
--- a/Renderer/Engine/SceneGraphRoot.h	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.h	Thu Feb 04 14:46:09 2010 +0900
@@ -14,6 +14,9 @@
 
 class Application;
 
+class SceneGraphRoot;
+typedef void (*regist_func)(SceneGraphRoot *sgroot);
+
 class SceneGraphRoot {
 public:
     /* Constructor, Destructor */
@@ -27,6 +30,7 @@
     // Static Singleton
     // SceneGraphPtr *sg_src;
     // int sg_src_length;
+    SceneGraphPtr list;
 
     // move, collision 用の SceneGraph (tree)
     SceneGraphPtr sg_exec_tree;
@@ -62,6 +66,19 @@
     // fd of Linda taple space
     int tid;
 
+    // move task test flag
+    int move_finish_flag;
+
+    // 関数ポインタ
+    regist_func regist;
+    // application で実行する task
+    HTaskPtr move_exec_task;
+
+    // とりあえず
+    int screen_w;
+    int screen_h;
+
+
     /**
      * Functions
      */
@@ -72,6 +89,7 @@
     SceneGraphPtr createSceneGraph();
     SceneGraphPtr createSceneGraph(const char *name);
     int getSgid(const char *name);
+    void appTaskRegist(regist_func new_regist);
 
     void setSceneData(SceneGraphPtr sg);
     Pad *getController();
@@ -88,6 +106,8 @@
     SceneGraphPtr getExecuteSceneGraph();
     SceneGraphPtr getDrawSceneGraph();
     void updateControllerState();
+    void regist_execute();
+    void move_finish();
 
     void speExecute(int screen_w, int screen_h);
     void speExecute(int screen_w, int screen_h, Application *app);
--- a/Renderer/Engine/SgChange.cc	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/SgChange.cc	Thu Feb 04 14:46:09 2010 +0900
@@ -75,6 +75,7 @@
 {
     SgChange *sgchange = (SgChange*)sgchange_;
     HTaskPtr task_next = sgchange->manager->create_task(Dummy);
+    sgchange->viewer->light_xyz_stock = sgchange->sgroot_A->getLightVector();
     sgchange->pass_draw_tree();
     sgchange->run_loop(task_next);
 
@@ -106,6 +107,7 @@
         spackList[i-1].reinit(i*split_screen_h);
     }
 
+    sgroot_A->updateControllerState();
     /*
     sgroot_A->updateControllerState();
     sgroot_A->allExecute(viewer->width, viewer->height);
@@ -117,18 +119,37 @@
 
     HTaskPtr draw_task  = manager->create_task(Dummy);
     draw_task->set_post(post2rendering, (void *)this, 0);
-    
-    HTaskPtr move_task  = manager->create_task(RunMove);
+
+    /*
+      application 側で sgroot に task を生成登録する
+      引数を渡したりは後でやる。
+    */
+    sgroot_A->regist_execute();
+
+    //HTaskPtr move_task  = manager->create_task(RunMove);
+    HTaskPtr move_task  = manager->create_task(ExecMove);
     move_task->set_param(0, (memaddr)this);
     move_task->set_param(1, viewer->width);
     move_task->set_param(2, viewer->height);
 
+    /*
+      TTaskPtr move_finish = manager->create_task(Dummy);
+      loop_task->wait_for(move_finish);
+
+      move_finish は app の move_task の post_func で実行させてやる
+    */
+
     HTaskPtr dummy_task = manager->create_task(Dummy);
 
     draw_finish = dummy_task;
 
     loop_task->wait_for(draw_finish);
-    loop_task->wait_for(move_task);
+    // move_task に wait_for ではなく sgroot_A->move_exec_task に wait_for するべき
+    // どこかで move_exec_task->spawn() しないとな
+    loop_task->wait_for(sgroot_A->move_exec_task);
+
+    //loop_task->wait_for(move_task);
+    
 
     draw_task->spawn();
     // この時点で app の task_id を知っていないとダメか
--- a/Renderer/Engine/spe/Property.cc	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/spe/Property.cc	Thu Feb 04 14:46:09 2010 +0900
@@ -18,11 +18,13 @@
 {
     PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
     PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
+    int *move_finish_flag = (int *)s->get_param(0);
 
     property->xyz[0] += 1.0f;
     property->xyz[1] += 1.0f;
     property->xyz[2] += 1.0f;
 
     memcpy((void*)update_property, (void*)property, sizeof(Property));
+    *move_finish_flag = 1;
     return 0;
 }
--- a/Renderer/Engine/task/RunMove.cc	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/task/RunMove.cc	Thu Feb 04 14:46:09 2010 +0900
@@ -12,10 +12,9 @@
     SgChange *sgchange = (SgChange *)smanager->get_param(0);
     int width  = (int)smanager->get_param(1);
     int height = (int)smanager->get_param(2);
-
     SceneGraphRoot *sgroot = sgchange->sgroot_A;
     sgroot->updateControllerState();
-    sgroot->allExecute(width, height);
+    sgroot->oneExecute(width, height);
     sgchange->viewer->light_xyz_stock = sgroot->getLightVector();
 
     return 0;
--- a/Renderer/Engine/task/task_init.cc	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/task/task_init.cc	Thu Feb 04 14:46:09 2010 +0900
@@ -31,6 +31,7 @@
 SchedExternTask(RunMove);
 
 SchedExternTask(PropertyTask);
+SchedExternTask(ExecMove);
 
 
 /**
@@ -67,5 +68,6 @@
     SchedRegister( ChainMove);
     SchedRegister( RunMove);
     SchedRegister( PropertyTask);
+    SchedRegister( ExecMove);
 
 }
--- a/Renderer/Engine/viewer.cc	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Thu Feb 04 14:46:09 2010 +0900
@@ -107,6 +107,7 @@
     
     int size = sizeof(float)*4;
 
+    light_xyz_stock = (float *)manager->allocate(size);
     light_xyz = (float *)manager->allocate(size);
     light_xyz[0] = 0.0f;
     light_xyz[1] = 0.0f;
--- a/Renderer/Test/create_task.cc	Mon Feb 01 17:08:36 2010 +0900
+++ b/Renderer/Test/create_task.cc	Thu Feb 04 14:46:09 2010 +0900
@@ -10,21 +10,29 @@
 Property *property, *update_property;
 
 // prototype
+static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
 static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
-static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
 static void createSceneGraphFromProperty(SchedTask *s, void *sgroot, void *arg1);
+//static void createSceneGraphFromProperty(void *sgroot, void *property_, void *update_property_);
+static void set_property(Property *p, SceneGraphPtr sg);
+static void regist_task(SceneGraphRoot *sgroot);
 
 static void
 move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
 {
     SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
-    TaskManager *manager = sgroot->tmanager;
-    HTaskPtr property_task = manager->create_task(PropertyTask);
+    //TaskManager *manager = sgroot->tmanager;
+    //HTaskPtr property_task = manager->create_task(PropertyTask);
+    HTaskPtr property_task = sgroot->move_exec_task;
 
     property_task->add_inData(property, sizeof(Property));
     property_task->add_outData(update_property, sizeof(Property));
+
+    //property_task->add_inData((Property *)node->property, sizeof(Property));
+    //property_task->add_outData((Property *)node->update_property, sizeof(Property));
+    //property_task->set_param(0, (memaddr)sgroot->move_finish_flag);
     property_task->set_cpu(SPE_ANY);
-
+    
     property_task->set_post(createSceneGraphFromProperty, (void *)sgroot, 0);
     property_task->spawn();
 }
@@ -35,6 +43,7 @@
 {
 }
 
+#if 1
 static void
 createSceneGraphFromProperty(SchedTask *s, void *sgroot_, void *arg1)
 {
@@ -52,8 +61,44 @@
     Property *tmp = property;
     property = update_property;
     update_property = tmp;
-    
+
+    sgroot->move_finish();
 }
+#else
+static void
+createSceneGraphFromProperty(void *sgroot_, void *property_, void *update_property_)
+{
+    SceneGraphPtr node;
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    Property *property = (Property *)property_;
+    Property *update_property = (Property *)update_property_;
+
+    node = sgroot->createSceneGraph(update_property->name);
+    //node = sgroot->createSceneGraph("Ball");
+    //node->set_move_collision(move, collision);
+    node->set_move_collision(move, collision, createSceneGraphFromProperty);
+    node->xyz[0] = update_property->xyz[0];
+    node->xyz[1] = update_property->xyz[1];
+    node->xyz[2] = update_property->xyz[2];
+    sgroot->setSceneData(node);
+
+    Property *tmp = property;
+    property = update_property;
+    update_property = tmp;    
+}
+#endif
+
+
+static void
+regist_task(SceneGraphRoot *sgroot)
+{
+    TaskManager *manager = sgroot->tmanager;
+    HTaskPtr property_task = manager->create_task(PropertyTask);
+    sgroot->move_exec_task = property_task;
+}
+
+
+
 
 static void
 set_property(Property *p, SceneGraphPtr sg)
@@ -70,9 +115,14 @@
     // SgChange を使うための2行
     SgChange *sgroot = new SgChange(viewer);
     sgroot->run_init();
+    sgroot->sgroot_A->appTaskRegist(regist_task);
 
     property        = (Property *)sgroot->manager->allocate(sizeof(Property));
     update_property = (Property *)sgroot->manager->allocate(sizeof(Property));
+    /*
+    Property *property        = (Property *)sgroot->manager->allocate(sizeof(Property));
+    Property *update_property = (Property *)sgroot->manager->allocate(sizeof(Property));
+    */
 
     SceneGraphPtr ball;
 
@@ -80,11 +130,16 @@
 
     ball = sgroot->createSceneGraph("Ball");
     ball->set_move_collision(move, collision);
+    //ball->set_move_collision(move, collision, createSceneGraphFromProperty);
 
     ball->xyz[0] = screen_w/2;
     ball->xyz[1] = screen_h/2;
     ball->xyz[2] = 30.0f;
 
+    //SceneGraph に property を持たせておく
+    ball->property = (void *)property;
+    ball->update_property = (void *)update_property;
+
     set_property(property, ball);
     
     sgroot->setSceneData(ball);