diff TaskManager/Test/test_render/SceneGraph.cpp @ 140:861271089c43

add Controller
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Fri, 28 Nov 2008 15:24:55 +0900
parents c948f4ebde62
children fc314f28b66e
line wrap: on
line diff
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Fri Nov 28 13:51:54 2008 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Fri Nov 28 15:24:55 2008 +0900
@@ -18,8 +18,19 @@
 no_collision(SceneGraphPtr self, int screen_w, int screen_h,
 	     SceneGraphPtr tree) {}
 
+SceneGraphPtr scene_graph = NULL;
+SceneGraphPtr scene_graph_viewer = NULL;
+
+
 SceneGraph::SceneGraph(void)
 {
+    init();
+}
+
+
+void
+SceneGraph::init(void)
+{
     next = NULL;
     last = NULL;
 
@@ -39,23 +50,10 @@
     collision = no_collision;
 }
 
-
 /* construct polygon from xmlNode.  */
 SceneGraph::SceneGraph(xmlNodePtr surface)
 {
-#if 1
-    next = NULL;
-    last = NULL;
-    parent = NULL;
-    brother = NULL;
-    children = NULL;
-    lastChild = NULL;
-    move = no_move;
-    collision = no_collision;
-#else
-    // こうしたいんだけどなー
-    this->SceneGraph();
-#endif
+    init();
 
     size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size"));
     name = (char *)xmlGetProp(surface,(xmlChar *)"name");
@@ -66,15 +64,19 @@
     get_data(surface->children);
 }
 
+SceneGraph::~SceneGraph(void)
+{
+    delete [] data;
+}
 
 /* XMLファイルからポリゴンを作成  */
-SceneGraph*
+void
 SceneGraph::createFromXMLfile(char *xmlfile)
 {
     xmlDocPtr doc;
     xmlNodePtr cur;
-    SceneGraph *root = NULL, *tmp, *parent;
-
+    SceneGraphPtr root = NULL, tmp, parent;
+    
     /* パース DOM生成 */
     doc = xmlParseFile(xmlfile);
     cur = xmlDocGetRootElement(doc);
@@ -94,6 +96,7 @@
 	if ( tmp->parent_name==NULL || 0==strcmp(tmp->parent_name, "NULL")) {
 	    /* このsurfaceがroot  */
 	    root = tmp;
+	    scene_graph = tmp;
 	} else {
 	    /* 親はこのsurfaceより前に定義されているものとする (していい?)  */
 	    //  ここで parent_name を用いるのは間違っていて、
@@ -106,12 +109,15 @@
 	    } else {
 		parent->addChild(tmp);
 	    }
-	    root->add_next(tmp);
+
+	    scene_graph->add_next(tmp);
 	}
     }
   
     xmlFreeDoc(doc);
-    return root;
+
+    //return root;
+    scene_graph_viewer = root;
 }
 
 /* 子供を追加  */
@@ -313,18 +319,16 @@
 void
 SceneGraph::delete_data(void)
 {
-    SceneGraph *n,*m;
+    SceneGraphPtr n = this->next, m;
 
-    n = this;
-    delete [] n->data;
+    //n = this;
+    //delete [] n->data;
 
-    if (next)
-    {
-	for(n = this->next; n; n=m)
-	{
+    if (next) {
+	while (n) {
 	    m = n->next;
-	    delete [] n->data;
 	    delete n;
+	    n = m;
 	}
     }
 }
@@ -405,25 +409,6 @@
 SceneGraph::clone(void) {
     SceneGraphPtr p = new SceneGraph;
     memcpy(p, this, sizeof(SceneGraph));
-
-
-    // どっかで関数にまとめるか
-    p->next = NULL;
-    p->last = NULL;
-
-    p->parent = NULL;
-    p->brother = NULL;
-    p->children = NULL;
-    p->lastChild = NULL;
-    p->move = no_move;
-    p->collision = no_collision;
-
-    p->stack_xyz[0] = 0.0f;
-    p->stack_xyz[2] = 0.0f;
-    p->stack_xyz[1] = 0.0f;
-    p->stack_angle[0] = 0.0f;
-    p->stack_angle[1] = 0.0f;
-    p->stack_angle[2] = 0.0f;
-    
+    p->init();
     return p;
 }