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