566
|
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>
|
|
9 #include <arpa/inet.h>
|
|
10 #include "SceneGraphRoot.h"
|
|
11 #include "lindaapi.h"
|
|
12 #include "send_linda.h"
|
|
13
|
|
14 #define HOSTNAME "localhost"
|
|
15 #define PORT_NUM 10000
|
|
16 #define LISTEN_PORT 1
|
|
17 #define MULTI_NUM 10
|
|
18
|
|
19 void
|
|
20 root_move(SceneGraphPtr node, int w, int h)
|
|
21 {
|
|
22 Pad *pad = sgroot->getController();
|
|
23
|
|
24 if (pad->right.isHold() || pad->left.isHold()) {
|
586
|
25 if (pad->right.isHold()) {
|
|
26 node->xyz[0] += 5.0f;
|
|
27 } else if (pad->left.isHold()) {
|
|
28 node->xyz[0] -= 5.0f;
|
|
29 }
|
566
|
30 }
|
|
31
|
|
32 if (pad->down.isHold() || pad->up.isHold() ) {
|
586
|
33 if (pad->down.isHold()) {
|
|
34 node->xyz[1] += 5.0f;
|
|
35 } else if (pad->up.isHold()) {
|
|
36 node->xyz[1] -= 5.0f;
|
|
37 }
|
566
|
38 }
|
|
39
|
|
40 /*
|
|
41 ここでキー入力を向こうに送る
|
586
|
42 */
|
566
|
43
|
|
44 }
|
|
45
|
|
46 void
|
|
47 root_collision(SceneGraphPtr node, int w, int h, SceneGraphPtr tree)
|
|
48 {
|
|
49 }
|
|
50
|
|
51 void
|
|
52 move(SceneGraphPtr node, int w, int h)
|
|
53 {
|
|
54 }
|
|
55
|
|
56 void
|
|
57 collision(SceneGraphPtr node, int w, int h, SceneGraphPtr tree)
|
|
58 {
|
|
59 }
|
|
60
|
|
61 void *
|
|
62 file_map(const char *filename, int *size) {
|
|
63 int fd;
|
|
64 void *addr;
|
|
65 struct stat sb;
|
|
66
|
|
67 if ((fd = open(filename, O_RDONLY)) == -1) {
|
586
|
68 fprintf(stderr, "Can't open %s\n", filename);
|
|
69 perror(NULL);
|
566
|
70 }
|
|
71 if (fstat(fd, &sb) == -1) {
|
586
|
72 fprintf(stderr, "Can't fstat %s\n", filename);
|
|
73 perror(NULL);
|
566
|
74 }
|
|
75 *size = sb.st_size;
|
|
76 addr = mmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
77 if (addr == MAP_FAILED) {
|
586
|
78 perror("mmap error\n");
|
|
79 exit(EXIT_FAILURE);
|
566
|
80 }
|
|
81 close(fd);
|
|
82
|
|
83 return addr;
|
|
84 }
|
|
85
|
|
86
|
|
87
|
|
88 int get_serial_id(int fd) {
|
|
89 char *data;
|
|
90 int serial;
|
|
91 int seq;
|
|
92
|
|
93 seq = psx_in(fd, 65535);
|
|
94 psx_sync_n();
|
|
95 data = (char *)psx_reply(seq);
|
|
96 serial = atoi(data + LINDA_HEADER_SIZE);
|
|
97 psx_free(data);
|
|
98
|
|
99 return serial;
|
|
100 }
|
|
101
|
|
102
|
|
103 void
|
|
104 send_xml(int tspace, int xml_id, void *addr, int size) {
|
|
105 psx_out(tspace, xml_id, (unsigned char *)addr, size);
|
|
106 psx_sync_n();
|
|
107 }
|
|
108
|
|
109 /*
|
|
110 void
|
|
111 mainLoop(int tid, int write_id, int fd)
|
|
112 {
|
|
113 void *addr;
|
|
114 struct stat sb;
|
|
115
|
|
116 if (fstat(fd, &sb) == -1) {
|
|
117 perror("fstat");
|
|
118 exit(1);
|
|
119 }
|
|
120 addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
121 if (addr==NULL) {
|
|
122 perror("mmap");
|
|
123 exit(1);
|
|
124 }
|
|
125
|
|
126 printf("file size=%d\n", sb.st_size);
|
|
127
|
|
128 psx_out(tid, write_id, addr, sb.st_size);
|
|
129 psx_sync_n();
|
|
130
|
|
131 return;
|
|
132 }
|
|
133 */
|
|
134
|
|
135 static char *xml;
|
577
|
136 static char *linda = HOSTNAME;
|
566
|
137
|
|
138 MainLoopPtr
|
586
|
139 send_linda::init(Viewer *sgr, int screen_w, int screen_h)
|
566
|
140 {
|
|
141 void *addr;
|
|
142 int size;
|
|
143 int tspace;
|
|
144 int serial;
|
|
145 int xml_id;
|
|
146
|
|
147 SceneGraphPtr sgp;
|
|
148 SceneGraphPtr root;
|
586
|
149 root = sgr->createSceneGraph();
|
566
|
150 root->set_move_collision(root_move, root_collision);
|
586
|
151
|
|
152 addr = file_map(xml, &size);
|
|
153 sgp = sgr->createSceneGraph();
|
|
154 sgroot->createFromXMLmemory(sgroot->tmanager, sgp, xml, size);
|
566
|
155 sgp->set_move_collision(move, collision);
|
|
156
|
|
157 root->addChild(sgp);
|
586
|
158
|
|
159 tspace = open_linda_java(linda, PORT_NUM);
|
566
|
160 serial = get_serial_id(tspace);
|
|
161 xml_id = serial * 10;
|
|
162 send_xml(tspace, xml_id, addr, size);
|
|
163
|
|
164 int client_id = htonl(serial);
|
|
165 send_xml(tspace, LISTEN_PORT, (void *)client_id, sizeof(int));
|
|
166
|
586
|
167 sgr->setSceneData(root);
|
|
168 return sgr;
|
566
|
169 }
|
|
170
|
|
171 extern Application *
|
|
172 application() {
|
|
173 return new send_linda();
|
|
174 }
|
|
175
|
|
176
|
|
177 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
|
|
178
|
|
179 extern int init(TaskManager *manager, int argc, char *argv[]);
|
|
180 extern void task_initialize();
|
|
181 static void TMend(TaskManager *manager);
|
|
182
|
|
183 int
|
|
184 TMmain(TaskManager *manager, int argc, char *argv[])
|
|
185 {
|
|
186 task_initialize();
|
|
187 manager->set_TMend(TMend);
|
|
188
|
|
189 for(int i=0;i<argc;i++) {
|
|
190 if (strcmp(argv[i],"-xml") == 0 && i+1<=argc) {
|
|
191 xml = argv[i+1];
|
577
|
192 } else if (strcmp(argv[i],"-linda") == 0 && i+1<=argc) {
|
|
193 linda = argv[i+1];
|
566
|
194 }
|
|
195 }
|
|
196
|
577
|
197 if (xml==0) {
|
|
198 printf("-xml xml-file is required\n");
|
|
199 exit(0);
|
|
200 }
|
|
201
|
566
|
202 return init(manager, argc, argv);
|
|
203
|
|
204 }
|
|
205
|
|
206 void
|
|
207 TMend(TaskManager *manager)
|
|
208 {
|
|
209 printf("test_nogl end\n");
|
|
210 }
|
|
211
|
|
212 /* end */
|
|
213
|