changeset 347:ee3db22c03b9

error in SceneGraph.[cpp,h]
author e065746@localhost.localdomain
date Wed, 08 Jul 2009 15:04:03 +0900
parents 2972f0bdd18c
children d6338bb6db87
files TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/SceneGraph.h TaskManager/Test/test_render/polygon.h
diffstat 3 files changed, 84 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Wed Jul 08 14:21:46 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Wed Jul 08 15:04:03 2009 +0900
@@ -348,75 +348,81 @@
  */
 void
 SceneGraph::get_data(xmlNodePtr cur)
-{
-    char *cont;
+{    
     //char *image_name;
 
     for(;cur;cur=cur->next)
     {
 	if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate"))
         {
-	    cont = (char *)xmlNodeGetContent(cur);
+	    char *cont = (char *)xmlNodeGetContent(cur);
 	    pickup_coordinate(cont);
         }
 	else if(!xmlStrcmp(cur->name,(xmlChar*)"normal"))
         {
-	    cont = (char *)xmlNodeGetContent(cur);
+	    char *cont = (char *)xmlNodeGetContent(cur);
 	    pickup_normal(cont);
         }
 	else if(!xmlStrcmp(cur->name,(xmlChar*)"model"))
         {
-	    cont = (char *)xmlNodeGetContent(cur);
+	    char *cont = (char *)xmlNodeGetContent(cur);
 	    pickup_model(cont);
         }
 	else if(!xmlStrcmp(cur->name,(xmlChar*)"texture"))
         {
-	    cont = (char *)xmlNodeGetContent(cur);
+	    char *cont = (char *)xmlNodeGetContent(cur);
 	    pickup_texture(cont);
 	}
 	else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag"))
         {
-	  char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name");
-	  texture_hash.hash_regist(filename);
+	    char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name");
+	    texture_hash.hash_regist(filename);
 	}
 	else if(!xmlStrcmp(cur->name,(xmlChar*)"image"))
         {
-	    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, image_name);
-	    decode(cont, outfile);
-	    fclose(outfile);
+	    get_image();	    
+	}
+    }
+}
+
+SDL_Surface*
+SceneGraph::load_decode_image(char *image_name)
+{
+    int fd = mkstemp(image_name);
+    FILE *outfile = fdopen(fd, "wb");
+    
+    if (NULL == outfile) {
+	    cout << "error open file\n";
+	    return;
+    }
+    
+    char *cont = (char *)xmlNodeGetContent(cur);
+    //decode(cont, image_name);
+    decode(cont, outfile);
+    fclose(outfile);
+    
 
-	    /**
-	     * image_name を既に Load していれば何もしない
-	     */
-	    int tex_id = texture_hash.hash_regist(filename);
-	    if (tex_id < 0) {
+/**
+ * image を 32bit(RGBA) に変換する
+ */
+    SDL_Surface *texture_image = IMG_Load(image_name);
+    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;
+    }
+ 
+    return texture_image;
+}
 
-		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;
-		}
-
+int
+SceneGraph::makeTapestries(SDL_Surface *texture_image) {
 		uint32 *tapestry;
 		int scale = 1;
 		int tex_w = texture_image->w;
@@ -454,18 +460,38 @@
 		list[id_count-1].pixels = tapestry;
 		list[id_count-1].scale_max = scale;
 		
-		texture_id = id_count-1;
+		return id_count-1;
+    }
+
+void
+SceneGraph::get_image()
+{
+    char image_name[20] = "/tmp/image_XXXXXX";
+    char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name");
+
+    if (filename == NULL || filename[0] == 0) {
+	return;
+    }
 
-		if (unlink(image_name))
-		{
-		    cout << "unlink error\n";
-		}
-	    } else {
-		/**
-		 * 以前に Load されている Texture を共用
-		 */
-		texture_id = tex_id;
-	    }
+    /**
+     * image_name を既に Load していれば何もしない
+     */
+    int tex_id = texture_hash.hash_regist(filename);
+    if (tex_id < 0) {       
+
+	SDL_Sureface *texture_image = load_image();
+			        		
+	texture_id = makeTapestries(texture_image);
+		
+	if (unlink(image_name)) {
+	    cout << "unlink error\n";
+	}
+    } else {
+	/**
+	 * 以前に Load されている Texture を共用
+	 */
+	texture_id = tex_id;
+    }
  
 	    // こんなことすると list[] のいみあるのかなーと
 	    // 微妙に思う、自分で書き換えた感想 by gongo
@@ -474,8 +500,6 @@
 	    texture_info.pixels_orig = list[texture_id].pixels_orig;
 	    texture_info.pixels = list[texture_id].pixels;
 	    texture_info.scale_max = list[texture_id].scale_max;
-	}
-    }
 }
 
 
--- a/TaskManager/Test/test_render/SceneGraph.h	Wed Jul 08 14:21:46 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.h	Wed Jul 08 15:04:03 2009 +0900
@@ -94,6 +94,10 @@
     void print_member(void);
     void get_data(xmlNodePtr cur);
     void delete_data(void);
+
+    SDL_Surface* load_decode_image(char *image_name);
+    int makeTapestries(SDL_Surface *texture_image);
+    void get_image();
 };
 
 #endif
--- a/TaskManager/Test/test_render/polygon.h	Wed Jul 08 14:21:46 2009 +0900
+++ b/TaskManager/Test/test_render/polygon.h	Wed Jul 08 15:04:03 2009 +0900
@@ -37,7 +37,7 @@
     int texture_id; //texture id number
     struct texture_list texture_info;
     
-    static SDL_Surface* texture_image; // pointer of this surface's texture
+    
 
     Polygon(void);