Mercurial > hg > Game > Cerium
changeset 518:003fe4ee39e2 draft
work dynamic_create
author | aaa |
---|---|
date | Wed, 21 Oct 2009 19:03:07 +0900 |
parents | d3bc594204c2 |
children | 30db22b46f7b |
files | TaskManager/Test/test_render/Application/dynamic_create.cc TaskManager/Test/test_render/SceneGraphRoot.cc TaskManager/Test/test_render/SceneGraphRoot.h TaskManager/Test/test_render/xml_file/universe.xml |
diffstat | 4 files changed, 88 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Application/dynamic_create.cc Wed Oct 21 16:56:13 2009 +0900 +++ b/TaskManager/Test/test_render/Application/dynamic_create.cc Wed Oct 21 19:03:07 2009 +0900 @@ -1,6 +1,60 @@ #include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <unistd.h> #include "SceneGraphRoot.h" +/* +typedef struct { + caddr_t file_mmap; + off_t size; +} st_mmap_t; +*/ + +int +fix_byte(int size,int fix_byte_size) +{ + size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; + + return size; +} + +st_mmap_t +my_mmap(char *filename) +{ + int fd = -1; + int map = MAP_PRIVATE; + st_mmap_t st_mmap; + struct stat sb; + + if ((fd = open(filename, O_RDONLY, 0666)) == 0 ) { + fprintf(stderr, "Can't open %s\n", filename); + } + + if (fstat(fd, &sb)) { + fprintf(stderr, "Can't fstat %s\n", filename); + } + + printf("file size %d\n", (int)sb.st_size); + + st_mmap.size = fix_byte(sb.st_size, 4096); + + printf("fix 4096byte file size %d\n", (int)st_mmap.size); + + st_mmap.file_mmap = (char *)mmap(NULL, st_mmap.size, PROT_READ, map, fd, (off_t)0); + if (st_mmap.file_mmap == (caddr_t)-1) { + fprintf(stderr, "Can't mmap file\n"); + perror(NULL); + exit(0); + } + + return st_mmap; +} + static void earth_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree) @@ -40,21 +94,38 @@ } Pad *pad = sgroot->getController(); + if (pad->right.isPush()) { - SceneGraphPtr earth; - sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml"); + SceneGraphPtr earth; + + st_mmap_t m = my_mmap("xml_file/universe.xml"); + + //sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml"); + sgroot->createFromXMLmemory(sgroot->tmanager, m); earth = sgroot->createSceneGraph("Earth"); earth->set_move_collision(moon_move, moon_collision); node->addChild(earth); } } +/* +void +linda_init() +{ + init_linda(); + tspace = open_linda_java("localhost", PORT); + printf("open"); +} +*/ + void dynamic_init(TaskManager *manager) { SceneGraphPtr earth; sgroot->tmanager = manager; + + #if 0 // テスト用に mmap したデータを第2引数に渡す sgroot->createFromXMLmemory(manager, "xml_file/universe.xml");
--- a/TaskManager/Test/test_render/SceneGraphRoot.cc Wed Oct 21 16:56:13 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraphRoot.cc Wed Oct 21 19:03:07 2009 +0900 @@ -172,17 +172,19 @@ } void -SceneGraphRoot::createFromXMLmemory(TaskManager *manager, const char *xmlfile) +//SceneGraphRoot::createFromXMLmemory(TaskManager *manager, const char *xmlfile) +SceneGraphRoot::createFromXMLmemory(TaskManager *manager, st_mmap_t mmap_t) { xmlDocPtr doc; xmlNodePtr cur; SceneGraphPtr tmp; // size は取れるはず、テスト用に mmap したデータを使う - int size = 10; /* パース DOM生成 */ - doc = xmlParseFile(xmlfile); - //doc = xmlParseMemory(xmlfile, size); + //doc = xmlParseFile(xmlfile); + int size = (int)mmap_t.size; + char *xmldata = (char *)mmap_t.file_mmap; + doc = xmlParseMemory(xmldata, size); cur = xmlDocGetRootElement(doc); /* ?? */
--- a/TaskManager/Test/test_render/SceneGraphRoot.h Wed Oct 21 16:56:13 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraphRoot.h Wed Oct 21 19:03:07 2009 +0900 @@ -9,6 +9,12 @@ #include "SceneGraphList.h" #include "SgStruct.h" #include "TaskManager.h" +#include <sys/types.h> + +typedef struct { + caddr_t file_mmap; + off_t size; +} st_mmap_t; class SceneGraphRoot { public: @@ -56,7 +62,8 @@ */ /* User API */ void createFromXMLfile(TaskManager *manager, const char *); - void createFromXMLmemory(TaskManager *manager, const char *xml); + //void createFromXMLmemory(TaskManager *manager, const char *xml); + void createFromXMLmemory(TaskManager *manager, st_mmap_t mmap_t); SceneGraphPtr createSceneGraph(int id); SceneGraphPtr createSceneGraph(void); SceneGraphPtr createSceneGraph(char *name);
--- a/TaskManager/Test/test_render/xml_file/universe.xml Wed Oct 21 16:56:13 2009 +0900 +++ b/TaskManager/Test/test_render/xml_file/universe.xml Wed Oct 21 19:03:07 2009 +0900 @@ -28871,4 +28871,4 @@ oFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoP/Z </image> </surface> -</OBJECT-3D> \ No newline at end of file +</OBJECT-3D>