changeset 195:8143bbade40d

fix
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Sun, 25 Jan 2009 17:44:17 +0900
parents 72dcf908ec52
children 932a05a7a1db
files TaskManager/Test/test_render/ChangeLog TaskManager/Test/test_render/Makefile.def TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/SceneGraph.h TaskManager/Test/test_render/cube_action.cpp TaskManager/Test/test_render/universe.cpp TaskManager/Test/test_render/viewer.cpp
diffstat 7 files changed, 230 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/ChangeLog	Tue Jan 20 14:50:41 2009 +0900
+++ b/TaskManager/Test/test_render/ChangeLog	Sun Jan 25 17:44:17 2009 +0900
@@ -1,3 +1,46 @@
+2009-01-25  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
+
+	* SceneGraph.cpp (SceneGraph::remove): add
+	User API。ここで削除するのではなく、まずはフラグを立てるだけ
+	ここですぐに消すと、allExecute() の走査で何気に困る
+
+	(SceneGraph::isRemoved): add
+	この SceneGraph 削除フラグが立っているかどうか
+	
+	(SceneGraph::realRemove): TODO
+	子を持つ SceneGraph が消された場合、
+	その子孫を全て削除するかどうか。まあ削除するのかな。
+
+	(SceneGraph::realRemove): add
+	Cerium System で呼ばれる。
+	remove flag の立った SceneGraph を削除する。
+	parentやbrother、next は繋ぎ直す。
+
+	* SceneGraphRoot.cpp (SceneGraphRoot::addNext): add
+	sg_available_list に追加していく
+	木の操作が要らないアクセスの際にはこっちの方がいい。
+
+	(SceneGraphRoot::setSceneData): add
+	Cerium に SceneGraph の tree を渡す。Cerium はこの tree を辿って
+	処理を行う
+	
+	(SceneGraphRoot::createFromXMLfile): add
+	xml file を指定して、そこから SceneGraph を生成し、
+	sg_src に格納する。ユーザはこの SceneGraph を直接は扱えない。
+	以下に示す createSceneGraph の、読み込み元データとして保存しておく。
+	
+	(SceneGraphRoot::createSceneGraph): add
+	オリジナルの SceneGraph を clone してユーザに返す。
+	この SceneGraph をユーザが操作する。
+	
+	* SceneGraphRoot.h (class SceneGraphRoot): new variables
+	sg_src, sg_exec_list, sg_draw_list, sg_available_list
+
+	* addfile (SceneGraphRoot.cpp)
+	SceneGraph を管理するクラス、ってところか。
+	Root ってのは SceneGraph という名前からすると
+	一番親と思われそうで微妙です。変えるかも。
+
 2009-01-12  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
 
 	* Joystick.cpp: TODO
--- a/TaskManager/Test/test_render/Makefile.def	Tue Jan 20 14:50:41 2009 +0900
+++ b/TaskManager/Test/test_render/Makefile.def	Sun Jan 25 17:44:17 2009 +0900
@@ -3,10 +3,10 @@
 # include/library path
 # ex: macosx
 #CERIUM = /Users/gongo/Source/Concurrency/Game_project/Cerium
-#CERIUM = /Users/gongo/Source/hg/Cerium
+CERIUM = /Users/gongo/Source/hg/Cerium
 
 # ex: linux/ps3
-CERIUM = /home/gongo/Cerium
+#CERIUM = /home/gongo/Cerium
 #CERIUM = /Users/tkaito/hg/Game/Cerium
 
 #CERIUM = ../../..
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Tue Jan 20 14:50:41 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Sun Jan 25 17:44:17 2009 +0900
@@ -12,6 +12,15 @@
 
 using namespace std;
 
+SceneGraphPtr scene_graph = NULL;
+SceneGraphPtr scene_graph_viewer = NULL;
+
+static TextureHash texture_hash;
+struct texture_list list[TABLE_SIZE];
+
+// TextureHash.cpp
+extern int id_count;
+
 extern int decode(char *cont, FILE *outfile);
 
 static void
@@ -21,15 +30,6 @@
 no_collision(SceneGraphPtr self, int screen_w, int screen_h,
 	     SceneGraphPtr tree) {}
 
-SceneGraphPtr scene_graph = NULL;
-SceneGraphPtr scene_graph_viewer = NULL;
-
-static TextureHash texture_hash;
-struct texture_list list[TABLE_SIZE];
-
-// TextureHash.cpp
-extern int id_count;
-
 /**
  * 事前に計算したテクスチャの最大縮小率 scale まで、
  * テクスチャを 1/2 縮小していく。
@@ -104,6 +104,7 @@
 SceneGraph::init(void)
 {
     next = NULL;
+    prev = NULL;
     last = NULL;
 
     parent = NULL;
@@ -122,6 +123,7 @@
     move = no_move;
     collision = no_collision;
 
+    flag_remove = 0;
     frame = 0;
 }
 
@@ -196,10 +198,10 @@
 }
 
 /* 子供を追加  */
-SceneGraph*
-SceneGraph::addChild(SceneGraph *child)
+SceneGraphPtr
+SceneGraph::addChild(SceneGraphPtr child)
 {
-    SceneGraph *tmp;
+    SceneGraphPtr tmp;
 
     /* childrenのリストの最後に加える (brother として)*/
     if (this->lastChild != NULL) {
@@ -219,8 +221,8 @@
 }
 
 /* 兄弟を追加  */
-SceneGraph*
-SceneGraph::addBrother(SceneGraph *bro)
+SceneGraphPtr
+SceneGraph::addBrother(SceneGraphPtr bro)
 {
     SceneGraphPtr sg = this->brother;
 
@@ -241,11 +243,11 @@
 }
 
 /* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL.  */
-SceneGraph*
+SceneGraphPtr
 SceneGraph::searchSceneGraph(char *name)
 {
-    SceneGraph* tmp;
-    SceneGraph* result;
+    SceneGraphPtr tmp;
+    SceneGraphPtr result;
 
     /* 本人か  */
     if( 0==strcmp(this->name, name) ) return this;
@@ -263,7 +265,7 @@
 void
 SceneGraph::tree_check(void)
 {
-    SceneGraph *t = this;
+    SceneGraphPtr t = this;
 
     while(t)
     {
@@ -481,7 +483,7 @@
 }
 
 void
-SceneGraph::collision_check(int w, int h, SceneGraph *tree)
+SceneGraph::collision_check(int w, int h, SceneGraphPtr tree)
 {
     (*collision)(this, w, h, tree);
 }
@@ -556,10 +558,75 @@
     this->last = next;
 }
 
-SceneGraph*
+SceneGraphPtr
 SceneGraph::clone(void) {
     SceneGraphPtr p = new SceneGraph;
+
     memcpy(p, this, sizeof(SceneGraph));
-    p->init();
+
+    // ポリゴンデータはとりあえずそのまま memcpy
+    p->data = new float[p->size*3*3];
+    memcpy(p->data, this->data, sizeof(float)*p->size*3*3);
+
     return p;
 }
+
+void
+SceneGraph::remove(void)
+{
+    this->flag_remove = 1;
+}
+
+void
+SceneGraph::realRemove(void)
+{
+    SceneGraphPtr node = this;
+
+    SceneGraphPtr prev = node->prev;
+    SceneGraphPtr next = node->next;
+    
+    if (prev) {
+	prev->next = next;
+    }
+    if (next) {
+	next->prev = prev;
+    }
+
+    SceneGraphPtr parent = node->parent;
+    SceneGraphPtr brother = parent->children;
+    SceneGraphPtr p, p1 = NULL;
+
+    p = brother;
+    if (p) {
+	if (p == node) {
+	    parent->children = NULL;
+	    parent->lastChild = NULL;
+	} else {
+	    p1 = p->next;
+
+	    while (p1 && p1 != node) {
+		p1 = p1->next;
+		p = p->next;
+	    }
+	    
+	    if (p1) {
+		p->next = p1->next;
+
+		// node が最後尾なら、lastChild を変更
+		if (parent->lastChild == p1) {
+		    parent->lastChild = p;
+		}
+	    } else {
+		// Can't find remove node
+	    }
+	}
+    }
+
+    delete node;
+}
+
+int
+SceneGraph::isRemoved(void)
+{
+    return flag_remove;
+}
--- a/TaskManager/Test/test_render/SceneGraph.h	Tue Jan 20 14:50:41 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.h	Sun Jan 25 17:44:17 2009 +0900
@@ -28,16 +28,18 @@
     float stack_angle[3];
 
     // xml ファイルから生成した時のオブジェクトリスト
-    SceneGraph* next;
-    SceneGraph* last;
+    SceneGraphPtr next;
+    SceneGraphPtr prev;
+    SceneGraphPtr last;
 
     // Tree Structure
-    SceneGraph *parent;
-    SceneGraph *brother;
-    SceneGraph *children;
-    SceneGraph *lastChild;
+    SceneGraphPtr parent;
+    SceneGraphPtr brother;
+    SceneGraphPtr children;
+    SceneGraphPtr lastChild;
 
-    Pad *controller;
+    // Tree から削除されていたら 1 をセット。default = 0
+    int flag_remove;
 
     // 関数ポインタ
     move_func move;
@@ -45,20 +47,25 @@
 
     void init(void);
     void move_execute(int screen_w, int screen_h);
-    void collision_check(int screen_w, int screen_h, SceneGraph *tree);
+    void collision_check(int screen_w, int screen_h, SceneGraphPtr tree);
     void all_execute(int screen_w, int screen_h);
 
-    void add_next(SceneGraph *next);
-    SceneGraph* addChild(SceneGraph *child);
-    SceneGraph* addBrother(SceneGraph *bro);
-    SceneGraph* clone(void);
-    SceneGraph* searchSceneGraph(char *name);
-    void set_move_collision(SceneGraph *node,
+    void add_next(SceneGraphPtr next);
+    SceneGraphPtr addChild(SceneGraphPtr child);
+    SceneGraphPtr addBrother(SceneGraphPtr bro);
+    SceneGraphPtr clone(void);
+    SceneGraphPtr searchSceneGraph(char *name);
+    void set_move_collision(SceneGraphPtr node,
 			    move_func new_move, collision_func new_collision);
     void set_move_collision(move_func new_move, collision_func new_collision);
+    void remove(void);
+    void realRemove(void);
+    int isRemoved(void);
+
 
 
     static void createFromXMLfile(const char *);
+    static SceneGraphPtr createSceneGraph(int id);
 
     void tree_check(void);
     void print_member(void);
--- a/TaskManager/Test/test_render/cube_action.cpp	Tue Jan 20 14:50:41 2009 +0900
+++ b/TaskManager/Test/test_render/cube_action.cpp	Sun Jan 25 17:44:17 2009 +0900
@@ -29,9 +29,9 @@
     node->angle[1] += 2.0f * node->stack_xyz[1];
     node->angle[2] += 2.0f * node->stack_xyz[2];
     
-    if (node->frame > 10 && scene_graph->controller->circle.push) {
-	cube_split(node);
-    }
+    //if (node->frame > 10 && scene_graph->controller->circle.push) {
+    //cube_split(node);
+    //}
 }
 
 static void
@@ -53,9 +53,9 @@
     node->angle[1] += 2.0f * node->stack_xyz[1];
     node->angle[2] += 2.0f * node->stack_xyz[2];
 
-    if (node->frame > 10 && scene_graph->controller->circle.push) {
-	cube_split(node);
-    }
+    //if (node->frame > 10 && scene_graph->controller->circle.push) {
+    //cube_split(node);
+    //}
 }
 
 static void
@@ -89,9 +89,9 @@
     node->xyz[1] = screen_h/2;
     node->xyz[2] = -300.0f;
 
-    if (scene_graph->controller->circle.push) {
-	cube_split(node);
-    }
+    //if (scene_graph->controller->circle.push) {
+    //cube_split(node);
+    //}
 }
 
 static void
--- a/TaskManager/Test/test_render/universe.cpp	Tue Jan 20 14:50:41 2009 +0900
+++ b/TaskManager/Test/test_render/universe.cpp	Sun Jan 25 17:44:17 2009 +0900
@@ -1,6 +1,9 @@
 #include <stdlib.h>
-#include "SceneGraph.h"
-#include "xml_file/universe.h"
+#include "SceneGraphRoot.h"
+#include "SGList.h"
+
+SceneGraphRootPtr sgroot;
+int moonrem = 0;
 
 static void
 cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
@@ -9,11 +12,36 @@
 }
 
 static void
-cube_move2(SceneGraphPtr node, int screen_w, int screen_h)
+moon_collision(SceneGraphPtr node, int screen_w, int screen_h,
+	       SceneGraphPtr tree)
+{
+}
+
+static void
+moon_move(SceneGraphPtr node, int screen_w, int screen_h)
+{
+    node->angle[0] += 3.0f;
+    printf("%f\n", node->angle[0]);
+    if (node->angle[0] > 360.0f) {
+	node->remove();
+	//node->angle[0] = 0.0f;
+	moonrem = 1;
+    }
+}
+
+
+static void
+cube_move(SceneGraphPtr node, int screen_w, int screen_h)
 {
     node->angle[1] += 1.0f;
     if (node->angle[1] > 360.0f) {
 	node->angle[1] = 0.0f;
+	if (moonrem) {
+	    SceneGraphPtr moon = sgroot->createSceneGraph(Moon);
+	    moon->set_move_collision(moon_move, moon_collision);
+	    node->addChild(moon);
+	    moonrem = 0;
+	}
     }
 
     node->xyz[0] += node->stack_xyz[0];
@@ -27,40 +55,30 @@
     }
 }
 
-static void
-cube_move(SceneGraphPtr node, int screen_w, int screen_h)
+void
+universe_init(SceneGraphRootPtr _sgroot)
 {
-    node->angle[1] += 1.0f;
-    if (node->angle[1] > 360.0f) {
-	node->angle[1] = 0.0f;
-    }
+    SceneGraphPtr earth;
+    SceneGraphPtr moon;
 
-    node->xyz[0] += node->stack_xyz[0];
-    if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
-	node->stack_xyz[0] = -node->stack_xyz[0];
-    }
+    sgroot = _sgroot;
+
+    sgroot->createFromXMLfile("xml_file/universe.xml");
 
-    node->xyz[1] += node->stack_xyz[1];
-    if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
-	node->stack_xyz[1] = -node->stack_xyz[1];
-    }
-}
+    // SGList.h にある SceneGraph ID から SceneGraph を生成する
+    earth = sgroot->createSceneGraph(Earth);
+    moon = sgroot->createSceneGraph(Moon);
 
-static void
-moon_move(SceneGraphPtr node, int screen_w, int screen_h)
-{
-    node->angle[1] += 1.0f;
-    if (node->angle[0] > 360.0f) {
-      node->angle[0] = 0.0f;
-    }
-}
+    // SceneGraph の move と collision を設定
+    earth->set_move_collision(cube_move, cube_collision);
+    earth->stack_xyz[0] = 3.0f;
+    earth->stack_xyz[1] = 3.0f;
+    moon->set_move_collision(moon_move, moon_collision);
 
-void
-universe_init(void)
-{
-    SceneGraph::createFromXMLfile("xml_file/universe.xml");
-    Earth->set_move_collision(cube_move, cube_collision);
-    Earth->stack_xyz[0] = 3.0f;
-    Earth->stack_xyz[1] = 3.0f;
-    Moon->set_move_collision(moon_move, cube_collision);
+    // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon)
+    earth->addChild(moon);
+
+    // SceneGraphRoot に、使用する SceneGraph を設定する
+    // このとき、ユーザーが記述した SceneGraph の root を渡す。
+    sgroot->setSceneData(earth);
 }
--- a/TaskManager/Test/test_render/viewer.cpp	Tue Jan 20 14:50:41 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.cpp	Sun Jan 25 17:44:17 2009 +0900
@@ -2,6 +2,7 @@
 #include "viewer.h"
 #include "viewer_types.h"
 #include "SceneGraph.h"
+#include "SceneGraphRoot.h"
 #include "scene_graph_pack.h"
 #include "sys.h"
 #include "Func.h"
@@ -18,8 +19,7 @@
 int this_time;
 int frames;
 
-extern SceneGraphPtr scene_graph;
-extern SceneGraphPtr scene_graph_viewer;
+static SceneGraphRootPtr sgroot;
 
 /* Data Pack sent to Other CPUs (ex. SPE) */
 SceneGraphPack *sgpack;
@@ -108,7 +108,7 @@
 extern void node_init(void);
 extern void create_cube_split(int);
 extern void create_snake_bg(int);
-extern void universe_init(void);
+extern void universe_init(SceneGraphRootPtr);
 
 void
 Viewer::run_init(const char *xml, int sg_number)
@@ -120,14 +120,8 @@
     this_time  = 0;
     frames     = 0;
 
-    //scene_graph = SceneGraph::createFromXMLfile(xml);
-    /**
-     * これを実行すると、
-     * scene_graph にオリジナルの SceneGraph Object のリストが、
-     * scene_graph_viewer に描画用の SceneGraph が生成される
-     */
-    //SceneGraph::createFromXMLfile(xml);
-    //polygon->viewer  = this;
+    sgroot = new SceneGraphRoot;
+    //sgroot->createFromXMLFile(xml);
 
     switch (sg_number) {
     case 0:
@@ -140,7 +134,7 @@
 	create_snake_bg(sg_number);
 	break;
     case 5:
-	universe_init();
+	universe_init(sgroot);
 	break;
     case 6:
 	node_init();
@@ -150,7 +144,7 @@
 	break;
     }
 
-    scene_graph->controller = create_controller();
+    sgroot->controller = create_controller();
 
     sgpack = (SceneGraphPack*)manager->malloc(sizeof(SceneGraphPack));
     sgpack->init();
@@ -243,8 +237,9 @@
     task_next->wait_for(task_update_sgp);
     task_update_sgp->spawn();
 #else
-    scene_graph->controller->check();
-    scene_graph_viewer->all_execute(width, height);
+    sgroot->updateControllerState();
+    sgroot->allExecute(width, height);
+    sgroot->checkRemove();
 #endif
 
 #if 0
@@ -255,7 +250,8 @@
 #else
     // SceneGraph(木構造) -> PolygonPack
     task_create_pp = manager->create_task(TASK_CREATE_PP2);
-    task_create_pp->add_param((uint32)scene_graph_viewer);
+    //task_create_pp->add_param((uint32)scene_graph_viewer);
+    task_create_pp->add_param((uint32)sgroot->getDrawSceneGraph());
     task_create_pp->add_param((uint32)ppack);
 #endif
     task_next->wait_for(task_create_pp);
@@ -371,9 +367,9 @@
 	printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0);
     }
 
-    scene_graph->delete_data();
-    scene_graph->controller->close();
-    delete scene_graph;
+    //scene_graph->delete_data();
+    //scene_graph->controller->close();
+    //delete scene_graph;
 
     quit();
 }