changeset 346:2972f0bdd18c

remove SceneGraph::createFromXMLfile
author e065746@localhost.localdomain
date Wed, 08 Jul 2009 14:21:46 +0900
parents fffbfbfc9e34
children ee3db22c03b9
files TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/SceneGraph.h TaskManager/Test/test_render/node.cpp example/scenegraph/xml/xml.cpp
diffstat 4 files changed, 6 insertions(+), 169 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Wed Jul 08 14:04:34 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Wed Jul 08 14:21:46 2009 +0900
@@ -217,167 +217,6 @@
 {
 }
 
-/* XMLファイルからポリゴンを作成  */
-void
-SceneGraph::createFromXMLfile(const char *xmlfile)
-{
-    xmlDocPtr doc;
-    xmlNodePtr cur;
-    SceneGraphPtr root = NULL, tmp = NULL, parent;
-    
-    /* パース DOM生成 */
-    doc = xmlParseFile(xmlfile);
-    cur = xmlDocGetRootElement(doc);
-
-    /* ??  */
-    xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
-
-    /* XMLのノードを一つずつ解析  */
-    for (cur=cur->children; cur; cur=cur->next) {
-	/* 扱うのはsurfaceオンリー  */
-	//if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) {
-	//    continue;
-	//}
-      if (!xmlStrcmp(cur->name,(xmlChar*)"surface")) {
-	/* ポリゴン(SceneGraph)生成  */
-	tmp = new SceneGraph(cur);
-	if ( tmp->parent_name==NULL || 0==strcmp(tmp->parent_name, "NULL")) {
-	    /* このsurfaceがroot  */
-	    root = tmp;
-	    scene_graph = tmp;
-	} else {
-	    /* 親はこのsurfaceより前に定義されているものとする (していい?)  */
-	    //  ここで parent_name を用いるのは間違っていて、
-	    //   *cur->properties->children から探すべきらしい kono
-	    parent = root->searchSceneGraph(tmp->parent_name);
-	    if (parent==NULL) {
-		fprintf(stderr, "[%s] No such parent %s\n",
-			tmp->name, tmp->parent_name);
-		root->addChild(tmp);
-	    } else {
-		parent->addChild(tmp);
-	    }
-
-	    scene_graph->add_next(tmp);
-	}
-      }else if (!xmlStrcmp(cur->name,(xmlChar*)"image")) {
-	
-	char *cont;
-	char image_name[20] = "/tmp/image_XXXXXX";
-	char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name");
-	int fd = mkstemp(image_name);
-	FILE *outfile = fdopen(fd, "wb");
-	if(NULL == outfile)
-	  {
-	    cout << "error open file\n";
-	  }
-	cont = (char *)xmlNodeGetContent(cur);
-	decode(cont, outfile);
-	fclose(outfile);
-		
-	int tex_id = texture_hash.hash_regist(filename);
-	if (tex_id < 0) 
-	  {
-	    
-	    texture_image = IMG_Load(image_name);
-	    
-	    /**
-	     * image を 32bit(RGBA) に変換する
-	     */
-	    
-	    SDL_Surface *tmpImage
-	      = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w,
-				     texture_image->h, 32, redMask,
-				     greenMask, blueMask, alphaMask);
-	    SDL_Surface *converted;
-	    converted = SDL_ConvertSurface(texture_image, tmpImage->format,
-					   SDL_HWSURFACE);
-	    if (converted != NULL) {
-	      SDL_FreeSurface(texture_image);
-	      texture_image = converted;
-	    }
-	    
-	    uint32 *tapestry;
-	    int scale = 1;
-	    int tex_w = texture_image->w;
-	    int tex_h = texture_image->h;
-	    int all_pixel_num = 0;
-	    
-	    /**
-	     * テクスチャの w or h が 8 pixel で分割できる間、
-	     * 1/2 の縮小画像を作る。
-	     * ここでは、最大の scale (1/scale) を見つける
-	     *
-	     * (ex)
-	     *  (128,128) => 64,64 : 32,32: 16,16 : 8,8
-	     *     scale = 16
-	     *  (128, 64) => 64,32 : 32,16: 16,8
-	     *     scale = 8
-	     */
-	    
-	    while (tex_w % TEXTURE_SPLIT_PIXEL == 0 &&
-		   tex_h % TEXTURE_SPLIT_PIXEL == 0) {
-	      all_pixel_num += tex_w*tex_h;
-	      tex_w >>= 1; /* tex_w /= 2 */
-	      
-	      tex_h >>= 1;
-	      scale <<= 1; /* scale *= 2 */
-	      
-	    }
-	    
-	    scale >>= 1;
-	    
-	    tapestry = makeTapestry(texture_image->w, texture_image->h,
-				    (uint32*)texture_image->pixels,
-				    all_pixel_num,
-				    scale);
-	    
-	    list[id_count-1].t_w = texture_image->w;
-	    list[id_count-1].t_h = texture_image->h;
-	    list[id_count-1].pixels_orig = (Uint32*)texture_image->pixels;
-	    list[id_count-1].pixels = tapestry;
-	    list[id_count-1].scale_max = scale;
-	    
-	    tmp->texture_id = id_count-1;
-	    tmp->texture_info.t_w = texture_image->w;
-	    tmp->texture_info.t_h = texture_image->h;
-	    tmp->texture_info.pixels_orig = (Uint32*)texture_image->pixels;
-	    tmp->texture_info.pixels = tapestry;
-	    tmp->texture_info.scale_max = scale;
-
-	    if (unlink(image_name))
-	      {
-		cout << "unlink error\n";
-	      }
-	    
-	  } else {
-	  /**
-	   * 以前に Load されている Texture を共用
-	   */
-	  
-	  tmp->texture_id = tex_id;
-	  
-	  // こんなことすると list[] のいみあるのかなーと
-	  // 微妙に思う、自分で書き換えた感想 by gongo
-	  
-	  tmp->texture_info.t_w = list[tex_id].t_w;
-	  tmp->texture_info.t_h = list[tex_id].t_h;;
-	  tmp->texture_info.pixels_orig = list[tex_id].pixels_orig;
-	  tmp->texture_info.pixels = list[tex_id].pixels;
-	  tmp->texture_info.scale_max = list[tex_id].scale_max;
-	  
-	}
-      }else {
-	continue;
-      }
-    }
-  
-    xmlFreeDoc(doc);
-
-    //return root;
-    scene_graph_viewer = root;
-}
-
 
 /**
  * add Children
--- a/TaskManager/Test/test_render/SceneGraph.h	Wed Jul 08 14:04:34 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.h	Wed Jul 08 14:21:46 2009 +0900
@@ -81,8 +81,7 @@
     SceneGraphPtr realRemoveFromTree(SceneGraphPtr tree);
     SceneGraphPtr realRemoveFromList(SceneGraphPtr list);
     int isRemoved(void);
-
-    static void createFromXMLfile(const char *);
+  
     static SceneGraphPtr createSceneGraph(int id);
 
     void translate(float x, float y, float z);
--- a/TaskManager/Test/test_render/node.cpp	Wed Jul 08 14:04:34 2009 +0900
+++ b/TaskManager/Test/test_render/node.cpp	Wed Jul 08 14:21:46 2009 +0900
@@ -1,4 +1,5 @@
 #include <stdlib.h>
+#include "SceneGraphRoot.h"
 #include "SceneGraph.h"
 #include "xml_file/cube.h"
 
@@ -63,7 +64,7 @@
 void
 node_init(void)
 {
-    SceneGraph::createFromXMLfile("xml_file/cube.xml");
+    sgroot->createFromXMLfile("xml_file/cube.xml");
     Cube->set_move_collision(cube_move, cube_collision);
     Cube->stack_xyz[0] = 2.0f;
     Cube->stack_xyz[1] = 2.0f;
--- a/example/scenegraph/xml/xml.cpp	Wed Jul 08 14:04:34 2009 +0900
+++ b/example/scenegraph/xml/xml.cpp	Wed Jul 08 14:21:46 2009 +0900
@@ -47,12 +47,10 @@
   if (init(argc, argv) < 0) {
     return -1;
   }
-  SceneGraphPtr sgroot = new SceneGraphRoot(this->width, this->height);
-  SceneGraphPtr sgobj1 = sgroot->createSceneGraph(Cube);
-  SceneGraphPtr sgobj2 = sgroot->createSceneGraph(Cone);
+  SceneGraphRootPtr sgroot = new SceneGraphRoot(this->width, this->height);
 
-  sgobj1->createFromXMLfile("sg/sg-test.xml");
-  sgobj2->createFromXMLfile("sg/sg-test2.xml");
+  sgroot->createFromXMLfile("sg/sg-test.xml");
+  sgroot->createFromXMLfile("sg/sg-test2.xml");
 
   st_time = getTime();
   manager->set_TMend(TMend);