annotate TaskManager/Test/test_render/Application/dynamic_create.cc @ 525:27eea39f2ebb draft

merge
author aaa
date Wed, 21 Oct 2009 21:05:34 +0900
parents 638bd307cde1 74a8b7c97964
children 413667c70a1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
1 #include <stdlib.h>
518
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
2 #include <stdio.h>
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
3 #include <string.h>
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
4 #include <fcntl.h>
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
5 #include <sys/types.h>
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
6 #include <sys/mman.h>
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
7 #include <sys/stat.h>
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
8 #include <unistd.h>
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
9 #include "SceneGraphRoot.h"
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
10 #include "lindaapi/lindaapi.h"
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
11
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
12 #define PORT 10000
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
13
518
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
14 /*
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
15 typedef struct {
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
16 caddr_t file_mmap;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
17 off_t size;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
18 } st_mmap_t;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
19 */
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
20
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
21 typedef struct {
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
22 int tid;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
23 int read_id;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
24 SceneGraphPtr node;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
25 } callback_arg;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
26
518
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
27 int
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
28 fix_byte(int size,int fix_byte_size)
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
29 {
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
30 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
31
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
32 return size;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
33 }
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
34
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
35 st_mmap_t
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
36 my_mmap(char *filename)
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
37 {
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
38 int fd = -1;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
39 int map = MAP_PRIVATE;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
40 st_mmap_t st_mmap;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
41 struct stat sb;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
42
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
43 if ((fd = open(filename, O_RDONLY, 0666)) == 0 ) {
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
44 fprintf(stderr, "Can't open %s\n", filename);
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
45 }
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
46
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
47 if (fstat(fd, &sb)) {
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
48 fprintf(stderr, "Can't fstat %s\n", filename);
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
49 }
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
50
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
51 printf("file size %d\n", (int)sb.st_size);
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
52
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
53 st_mmap.size = fix_byte(sb.st_size, 4096);
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
54
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
55 printf("fix 4096byte file size %d\n", (int)st_mmap.size);
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
56
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
57 st_mmap.file_mmap = (char *)mmap(NULL, st_mmap.size, PROT_READ, map, fd, (off_t)0);
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
58 if (st_mmap.file_mmap == (caddr_t)-1) {
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
59 fprintf(stderr, "Can't mmap file\n");
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
60 perror(NULL);
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
61 exit(0);
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
62 }
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
63
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
64 return st_mmap;
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
65 }
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
66
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
67 static void
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
68 earth_collision(SceneGraphPtr node, int screen_w, int screen_h,
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
69 SceneGraphPtr tree)
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
70 {
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
71 }
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
72
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
73 static void
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
74 moon_collision(SceneGraphPtr node, int screen_w, int screen_h,
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
75 SceneGraphPtr tree)
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
76 {
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
77 }
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
78
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
79 static void
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
80 moon_move(SceneGraphPtr node, int screen_w, int screen_h)
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
81 {
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
82 node->angle[0] += 3.0f;
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
83 node->xyz[1] += 1.0f;
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
84 }
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
85
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
86
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
87 static void
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
88 earth_move(SceneGraphPtr node, int screen_w, int screen_h)
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
89 {
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
90 node->angle[1] += 1.0f;
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
91 if (node->angle[1] > 360.0f) {
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
92 node->angle[1] = 0.0f;
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
93 }
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
94
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
95 node->xyz[0] += node->stack_xyz[0];
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
96 if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
97 node->stack_xyz[0] = -node->stack_xyz[0];
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
98 }
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
99
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
100 node->xyz[1] += node->stack_xyz[1];
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
101 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
102 node->stack_xyz[1] = -node->stack_xyz[1];
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
103 }
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
104
525
aaa
parents: 524 521
diff changeset
105 <<<<<<< local
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
106 //Pad *pad = sgroot->getController();
525
aaa
parents: 524 521
diff changeset
107 =======
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
108 Pad *pad = sgroot->getController();
521
tkaito@henri.cr.ie.u-ryukyu.ac.jp
parents: 520 518
diff changeset
109 <<<<<<< local
520
8d86242337ba SGList isn't used
tkaito@henri.cr.ie.u-ryukyu.ac.jp
parents: 515
diff changeset
110 if (pad->circle.isPush()) {
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
111 SceneGraphPtr earth;
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
112 sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml");
521
tkaito@henri.cr.ie.u-ryukyu.ac.jp
parents: 520 518
diff changeset
113 =======
525
aaa
parents: 524 521
diff changeset
114 >>>>>>> other
518
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
115
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
116 /*
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
117 if (pad->right.isPush()) {
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
118 SceneGraphPtr earth;
518
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
119
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
120 st_mmap_t m = my_mmap("xml_file/universe.xml");
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
121
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
122 //sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml");
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
123 sgroot->createFromXMLmemory(sgroot->tmanager, m);
521
tkaito@henri.cr.ie.u-ryukyu.ac.jp
parents: 520 518
diff changeset
124 >>>>>>> other
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
125 earth = sgroot->createSceneGraph("Earth");
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
126 earth->set_move_collision(moon_move, moon_collision);
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
127 node->addChild(earth);
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
128 }
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
129 */
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
130
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
131 psx_sync_n();
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
132 }
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
133
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
134 void
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
135 create_sg(SceneGraphPtr node, unsigned char *data, int len)
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
136 {
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
137 SceneGraphPtr earth;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
138
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
139 //sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml");
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
140 const char *objname = sgroot->createFromXMLmemory(sgroot->tmanager, (char *)data, len);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
141 earth = sgroot->createSceneGraph(objname);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
142 earth->set_move_collision(moon_move, moon_collision);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
143 node->addChild(earth);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
144
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
145 }
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
146
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
147 static void
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
148 callbacker(unsigned char *tuple, void *arg) {
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
149 int len;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
150 unsigned char *data;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
151 callback_arg *carg = (callback_arg *)arg;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
152
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
153 len = psx_get_datalength(tuple);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
154 // 最初の4byteデータは使わない
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
155 data = tuple+LINDA_HEADER_SIZE;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
156
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
157 // ここで create
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
158 create_sg(carg->node, data, len);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
159
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
160 /* dataは'\0'で終わっている事を期待 (writerで保証する) */
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
161 //printf("get data[%d]: `%s'\n", len, data);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
162 free(tuple);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
163
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
164 psx_callback_wait_rd(carg->tid, carg->read_id, callbacker, arg);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
165 }
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
166
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
167
518
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
168 void
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
169 linda_init(TaskManager *manager, SceneGraphPtr node)
518
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
170 {
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
171 init_linda();
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
172 callback_arg *carg = (callback_arg *)manager->allocate(sizeof(callback_arg));
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
173 carg->tid = open_linda_java("cycas.cr.ie.u-ryukyu.ac.jp", PORT);
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
174 carg->read_id = 10;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
175 carg->node = node;
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
176 psx_callback_wait_rd(carg->tid, carg->read_id, callbacker, carg);
518
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
177 }
003fe4ee39e2 work dynamic_create
aaa
parents: 515
diff changeset
178
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
179 void
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
180 dynamic_init(TaskManager *manager)
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
181 {
520
8d86242337ba SGList isn't used
tkaito@henri.cr.ie.u-ryukyu.ac.jp
parents: 515
diff changeset
182 //SceneGraphPtr earth;
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
183 sgroot->tmanager = manager;
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
184
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
185 #if 0
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
186 // テスト用に mmap したデータを第2引数に渡す予定でした
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
187 sgroot->createFromXMLmemory(manager, "xml_file/universe.xml");
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
188
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
189 // sglist に登録されている name から sgid を引き、sg_src[sgid] からコピーして返す
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
190 earth = sgroot->createSceneGraph("Earth");
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
191 #else
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
192 SceneGraphPtr parent;
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
193 parent = sgroot->createSceneGraph();
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
194 parent->set_move_collision(earth_move, earth_collision);
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
195 #endif
524
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
196
638bd307cde1 complex lindaapi
aaa
parents: 518
diff changeset
197 linda_init(manager, parent);
515
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
198
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
199 // SceneGraphRoot に、使用する SceneGraph を設定する
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
200 // このとき、ユーザーが記述した SceneGraph の root を渡す。
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
201 sgroot->setSceneData(parent);
d2772feb34e3 add Application/dynamic_create.cc
aaa
parents:
diff changeset
202 }