Mercurial > hg > Members > kono > Cerium
comparison TaskManager/Test/test_render/Application/dynamic_create.cc @ 537:7014034b8d69
work dynamic_create
author | aaa |
---|---|
date | Wed, 21 Oct 2009 19:03:07 +0900 |
parents | 997d2a73a758 |
children | c5a411c19e7e 9f9d51b60062 |
comparison
equal
deleted
inserted
replaced
535:f8d56635efb8 | 537:7014034b8d69 |
---|---|
1 #include <stdlib.h> | 1 #include <stdlib.h> |
2 #include <stdio.h> | |
3 #include <string.h> | |
4 #include <fcntl.h> | |
5 #include <sys/types.h> | |
6 #include <sys/mman.h> | |
7 #include <sys/stat.h> | |
8 #include <unistd.h> | |
2 #include "SceneGraphRoot.h" | 9 #include "SceneGraphRoot.h" |
10 | |
11 /* | |
12 typedef struct { | |
13 caddr_t file_mmap; | |
14 off_t size; | |
15 } st_mmap_t; | |
16 */ | |
17 | |
18 int | |
19 fix_byte(int size,int fix_byte_size) | |
20 { | |
21 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; | |
22 | |
23 return size; | |
24 } | |
25 | |
26 st_mmap_t | |
27 my_mmap(char *filename) | |
28 { | |
29 int fd = -1; | |
30 int map = MAP_PRIVATE; | |
31 st_mmap_t st_mmap; | |
32 struct stat sb; | |
33 | |
34 if ((fd = open(filename, O_RDONLY, 0666)) == 0 ) { | |
35 fprintf(stderr, "Can't open %s\n", filename); | |
36 } | |
37 | |
38 if (fstat(fd, &sb)) { | |
39 fprintf(stderr, "Can't fstat %s\n", filename); | |
40 } | |
41 | |
42 printf("file size %d\n", (int)sb.st_size); | |
43 | |
44 st_mmap.size = fix_byte(sb.st_size, 4096); | |
45 | |
46 printf("fix 4096byte file size %d\n", (int)st_mmap.size); | |
47 | |
48 st_mmap.file_mmap = (char *)mmap(NULL, st_mmap.size, PROT_READ, map, fd, (off_t)0); | |
49 if (st_mmap.file_mmap == (caddr_t)-1) { | |
50 fprintf(stderr, "Can't mmap file\n"); | |
51 perror(NULL); | |
52 exit(0); | |
53 } | |
54 | |
55 return st_mmap; | |
56 } | |
3 | 57 |
4 static void | 58 static void |
5 earth_collision(SceneGraphPtr node, int screen_w, int screen_h, | 59 earth_collision(SceneGraphPtr node, int screen_w, int screen_h, |
6 SceneGraphPtr tree) | 60 SceneGraphPtr tree) |
7 { | 61 { |
38 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { | 92 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { |
39 node->stack_xyz[1] = -node->stack_xyz[1]; | 93 node->stack_xyz[1] = -node->stack_xyz[1]; |
40 } | 94 } |
41 | 95 |
42 Pad *pad = sgroot->getController(); | 96 Pad *pad = sgroot->getController(); |
97 | |
43 if (pad->right.isPush()) { | 98 if (pad->right.isPush()) { |
44 SceneGraphPtr earth; | 99 SceneGraphPtr earth; |
45 sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml"); | 100 |
101 st_mmap_t m = my_mmap("xml_file/universe.xml"); | |
102 | |
103 //sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml"); | |
104 sgroot->createFromXMLmemory(sgroot->tmanager, m); | |
46 earth = sgroot->createSceneGraph("Earth"); | 105 earth = sgroot->createSceneGraph("Earth"); |
47 earth->set_move_collision(moon_move, moon_collision); | 106 earth->set_move_collision(moon_move, moon_collision); |
48 node->addChild(earth); | 107 node->addChild(earth); |
49 } | 108 } |
50 } | 109 } |
51 | 110 |
111 /* | |
112 void | |
113 linda_init() | |
114 { | |
115 init_linda(); | |
116 tspace = open_linda_java("localhost", PORT); | |
117 printf("open"); | |
118 } | |
119 */ | |
120 | |
52 void | 121 void |
53 dynamic_init(TaskManager *manager) | 122 dynamic_init(TaskManager *manager) |
54 { | 123 { |
55 SceneGraphPtr earth; | 124 SceneGraphPtr earth; |
56 sgroot->tmanager = manager; | 125 sgroot->tmanager = manager; |
126 | |
127 | |
57 | 128 |
58 #if 0 | 129 #if 0 |
59 // テスト用に mmap したデータを第2引数に渡す | 130 // テスト用に mmap したデータを第2引数に渡す |
60 sgroot->createFromXMLmemory(manager, "xml_file/universe.xml"); | 131 sgroot->createFromXMLmemory(manager, "xml_file/universe.xml"); |
61 | 132 |