Mercurial > hg > Members > kono > Cerium
changeset 580:da82a47ece92
add all object in file in dynamic_create
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 24 Oct 2009 16:32:29 +0900 |
parents | 6c1a627303b2 |
children | 58cdb81f7f96 |
files | Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/SceneGraphRoot.h Renderer/Test/Makefile Renderer/Test/dynamic_create.cc |
diffstat | 5 files changed, 46 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraph.cc Sat Oct 24 16:11:08 2009 +0900 +++ b/Renderer/Engine/SceneGraph.cc Sat Oct 24 16:32:29 2009 +0900 @@ -403,6 +403,7 @@ * image を 32bit(RGBA) に変換する */ SDL_Surface *texture_image = IMG_Load(image_name); + if (!texture_image) return 0; SDL_Surface *tmpImage = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, texture_image->h, 32, redMask, @@ -477,6 +478,10 @@ if (!texture_hash.hash_regist(filename, tex_id)) { SDL_Surface *texture_image = load_decode_image(image_name, cur); + if (texture_image==0) { + printf("Can't load image %s\n",filename); + exit(0); + } texture_id = makeTapestries(manager, texture_image, tex_id);
--- a/Renderer/Engine/SceneGraphRoot.cc Sat Oct 24 16:11:08 2009 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Sat Oct 24 16:32:29 2009 +0900 @@ -84,8 +84,8 @@ sg_src_size *= 2; sg_src = (SceneGraphPtr*)realloc(sg_src, sg_src_size); } - sg->id = ++sg_src_id; - sg_src[sg->id] = sg; + sg->sgid = ++sg_src_id; + sg_src[sg->sgid] = sg; } void @@ -130,12 +130,39 @@ /* ポリゴン(SceneGraph)生成 */ tmp = new SceneGraph(manager, cur); - registSceneGraph(tmp); } - xmlFreeDoc(doc); +} +void +SceneGraphRoot::createFromXMLmemory(TaskManager *manager, SceneGraph *node, char *data, int len) +{ + xmlDocPtr doc; + xmlNodePtr cur; + + // size は取れるはず、テスト用に mmap したデータを使う + /* パース DOM生成 */ + + doc = xmlParseMemory(data, len); + 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; + } + /* ポリゴン(SceneGraph)生成 */ + SceneGraphPtr original = new SceneGraph(manager, cur); + registSceneGraph(original); + SceneGraphPtr clone = createSceneGraph(original->sgid); + node->addChild(clone); + } + xmlFreeDoc(doc); } SceneGraphPtr @@ -160,36 +187,6 @@ } -void -SceneGraphRoot::createFromXMLmemory(TaskManager *manager, char *data, int len) -{ - xmlDocPtr doc; - xmlNodePtr cur; - - // size は取れるはず、テスト用に mmap したデータを使う - /* パース DOM生成 */ - - doc = xmlParseMemory(data, len); - 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; - } - - /* ポリゴン(SceneGraph)生成 */ - SceneGraphPtr tmp = new SceneGraph(manager, cur); - - registSceneGraph(tmp); - } - - xmlFreeDoc(doc); -} SceneGraphPtr @@ -228,7 +225,7 @@ SceneGraphRoot::getLast() { if (sg_src_id>=0) - return sg_src[sg_src_id]->id; + return sg_src[sg_src_id]->sgid; return -1; }
--- a/Renderer/Engine/SceneGraphRoot.h Sat Oct 24 16:11:08 2009 +0900 +++ b/Renderer/Engine/SceneGraphRoot.h Sat Oct 24 16:32:29 2009 +0900 @@ -59,9 +59,7 @@ */ /* User API */ void createFromXMLfile(TaskManager *manager, const char *); - //void createFromXMLmemory(TaskManager *manager, const char *xml); - //void createFromXMLmemory(TaskManager *manager, st_mmap_t mmap_t); - void createFromXMLmemory(TaskManager *manager, char *data, int len); + void createFromXMLmemory(TaskManager *manager, SceneGraph * node, char *data, int len); SceneGraphPtr createSceneGraph(int id); SceneGraphPtr createSceneGraph(); SceneGraphPtr createSceneGraph(const char *name);
--- a/Renderer/Test/Makefile Sat Oct 24 16:11:08 2009 +0900 +++ b/Renderer/Test/Makefile Sat Oct 24 16:32:29 2009 +0900 @@ -1,6 +1,6 @@ -all: cell - #make -f Makefile.macosx +all: + make -f Makefile.macosx cell: make -f Makefile.cell
--- a/Renderer/Test/dynamic_create.cc Sat Oct 24 16:11:08 2009 +0900 +++ b/Renderer/Test/dynamic_create.cc Sat Oct 24 16:32:29 2009 +0900 @@ -48,18 +48,6 @@ void client_list_update(TaskManager *manager, client_t *clist, int id, SceneGraphPtr sgp) { - //client_t *c; - // for (c = clist->next; c != clist; c = c->next) { - // if (c->id == id) { - // c->sgp = sgp; - // return; - // } - // } - - // c->next = (client_t *)manager->allocate(sizeof(client_t)); - // c->next->id = id; - // c->next->sgp = sgp; - // c->next->next = clist; } void @@ -109,28 +97,14 @@ SceneGraphPtr create_sg(TaskManager *manager, SceneGraphPtr node, unsigned char *data, int len, int serial_id) { - SceneGraphPtr object; - - sgroot->createFromXMLmemory(sgroot->tmanager, (char *)data, len); - object = sgroot->createSceneGraph(sgroot->getLast()); - object->id = serial_id; - object->set_move_collision(moon_move, moon_collision); - node->addChild(object); - - return object; + SceneGraphPtr child = sgroot->createSceneGraph(); + node->addChild(child); + child->set_move_collision(moon_move, moon_collision); + // 読み込んだオブジェクトは、すべて、child の child になる。 + sgroot->createFromXMLmemory(sgroot->tmanager, child, (char *)data, len); + return node; } -// void -// del_callback(unsigned char *data, void *arg) -// { -// free(data); -// } - -// void -// psx_del(int t, int id) -// { -// psx_callback_in(t, id, del_callback, NULL); -// } static void callback_get_xml(unsigned char *xml_tuple, void *arg) {