Mercurial > hg > Game > Cerium
annotate Renderer/Test/dynamic_create.cc @ 843:de64695a7f02 draft
cleanup unused variables and fix warning.
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 02 Jun 2010 02:03:40 +0900 |
parents | 8d702fc5d77a |
children | ba9e10f636eb |
rev | line source |
---|---|
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> | |
610
d38d9896dfa4
change htonl to xdr_float (checked working on mac)
kazz@kazzone.st.ie.u-ryukyu.ac.jp
parents:
601
diff
changeset
|
10 #include <rpc/types.h> |
d38d9896dfa4
change htonl to xdr_float (checked working on mac)
kazz@kazzone.st.ie.u-ryukyu.ac.jp
parents:
601
diff
changeset
|
11 #include <rpc/xdr.h> |
566 | 12 #include "SceneGraphRoot.h" |
13 #include "lindaapi.h" | |
14 #include "dynamic_create.h" | |
15 | |
16 #define PORT 10000 | |
17 | |
18 #define SERIAL_REGIST_TUPLE_NO 1 | |
19 | |
610
d38d9896dfa4
change htonl to xdr_float (checked working on mac)
kazz@kazzone.st.ie.u-ryukyu.ac.jp
parents:
601
diff
changeset
|
20 #define RECV_DATA_SIZE sizeof(float) * 6 |
d38d9896dfa4
change htonl to xdr_float (checked working on mac)
kazz@kazzone.st.ie.u-ryukyu.ac.jp
parents:
601
diff
changeset
|
21 |
566 | 22 typedef struct client_ { |
23 int id; | |
24 SceneGraphPtr sgp; | |
25 struct client_ *next; | |
26 } client_t; | |
27 | |
28 typedef struct { | |
29 int tid; | |
30 int sid; | |
31 int read_id; | |
32 SceneGraphPtr node; | |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
33 SceneGraphRoot *sgroot; |
566 | 34 TaskManager *manager; |
35 client_t *clist; | |
36 } callback_arg; | |
37 | |
38 | |
39 void | |
40 client_list_init(TaskManager* manager, client_t *clist) | |
41 { | |
42 clist->id = -1; | |
43 clist->next = clist; | |
44 } | |
45 | |
46 void | |
47 client_list_update(TaskManager *manager, client_t *clist, int id, SceneGraphPtr sgp) | |
48 { | |
49 } | |
50 | |
51 void | |
52 client_list_delete(TaskManager *manager, client_t *clist, int id) | |
53 { | |
54 client_t *c, *prev; | |
55 for (c = clist->next, prev = clist; c->next != clist; c = c->next) { | |
56 if (c->id == id) { | |
57 prev->next = c->next; | |
58 return; | |
59 } | |
60 prev = clist; | |
61 } | |
62 if (c->id == id) { | |
591 | 63 prev->next = c->next; |
64 return; | |
566 | 65 } |
66 } | |
67 | |
68 | |
69 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
642
diff
changeset
|
70 earth_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
566 | 71 SceneGraphPtr tree) |
72 { | |
73 } | |
74 | |
75 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
642
diff
changeset
|
76 moon_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
566 | 77 SceneGraphPtr tree) |
78 { | |
79 } | |
80 | |
81 static void | |
841
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
82 set_position(SceneGraphPtr node, unsigned char *reply) { |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
83 char *data = (char *)(reply + LINDA_HEADER_SIZE); |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
84 // XDRの準備 |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
85 XDR xdrs; |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
86 xdrmem_create(&xdrs, data, RECV_DATA_SIZE, XDR_DECODE); |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
87 for (int i = 0; i < 3; i++) { |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
88 xdr_float(&xdrs, &node->xyz[i]); |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
89 } |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
90 } |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
91 |
8d702fc5d77a
dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
92 static void |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
642
diff
changeset
|
93 moon_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
566 | 94 { |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
642
diff
changeset
|
95 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
591 | 96 // LindaServerから座標データを取得してオブジェクトに反映させる。 |
843
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
841
diff
changeset
|
97 unsigned char *reply = psx_reply(node->seq); |
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
841
diff
changeset
|
98 if (reply != NULL) { |
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
841
diff
changeset
|
99 set_position(node, reply); |
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
841
diff
changeset
|
100 free(reply); |
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
841
diff
changeset
|
101 node->seq = psx_wait_rd(sgroot->tid, node->id * 10 + 1); |
591 | 102 } |
566 | 103 } |
104 | |
105 static void | |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
106 earth_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
566 | 107 { |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
574
diff
changeset
|
108 // psx_sync_n(); in viewer::MainLoop |
566 | 109 } |
110 | |
111 SceneGraphPtr | |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
112 create_sg(TaskManager *manager, SceneGraphRoot *sgroot, SceneGraphPtr parent, unsigned char *data, |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
642
diff
changeset
|
113 int len, int serial_id) |
566 | 114 { |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
579
diff
changeset
|
115 SceneGraphPtr child = sgroot->createSceneGraph(); |
581 | 116 parent->addChild(child); |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
579
diff
changeset
|
117 // 読み込んだオブジェクトは、すべて、child の child になる。 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
579
diff
changeset
|
118 sgroot->createFromXMLmemory(sgroot->tmanager, child, (char *)data, len); |
581 | 119 child->set_move_collision(moon_move, moon_collision); |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
120 child->id = serial_id; |
843
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
841
diff
changeset
|
121 child->seq = psx_wait_rd(sgroot->tid, serial_id * 10 + 1); |
593
75c78f8fba24
sending and moving of multi xml work (linda)
kazz@kazzone.st.ie.u-ryukyu.ac.jp
parents:
592
diff
changeset
|
122 |
581 | 123 return child; |
566 | 124 } |
125 | |
126 | |
127 static void | |
128 callback_get_xml(unsigned char *xml_tuple, void *arg) { | |
129 int xml_len = psx_get_datalength(xml_tuple); | |
130 callback_arg *carg = (callback_arg *)arg; | |
591 | 131 unsigned char *xml_data = xml_tuple + LINDA_HEADER_SIZE; |
566 | 132 SceneGraphPtr sgp; |
133 // ここで create | |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
134 sgp = create_sg(carg->manager, carg->sgroot, carg->node, xml_data, xml_len, carg->sid); |
581 | 135 printf("%s size %d loaded\n", sgp->children->name, xml_len); |
566 | 136 client_list_update(carg->manager, carg->clist, carg->sid, sgp); |
137 free(arg); | |
138 free(xml_tuple); | |
139 } | |
140 | |
141 static void | |
591 | 142 callbacker(unsigned char *taple, void *arg) { |
566 | 143 int serial_id, xml_id; |
144 | |
145 unsigned char *data; | |
146 callback_arg *carg = (callback_arg *)arg; | |
147 | |
148 // 最初の4byteデータは使わない | |
601 | 149 data = taple + LINDA_HEADER_SIZE; |
566 | 150 // clientのSerialIDを取得 |
151 serial_id = ntohl(*(int *)data); | |
610
d38d9896dfa4
change htonl to xdr_float (checked working on mac)
kazz@kazzone.st.ie.u-ryukyu.ac.jp
parents:
601
diff
changeset
|
152 printf("serial id = %d\n", serial_id); // タプルを解放 |
566 | 153 |
154 // xml fileを取得する もうすでにxml fileが送信済みである事を期待 | |
155 // つまり、送信者がserial_idを送る前にxml fileを送信していなくてはならない | |
156 xml_id = serial_id * 10; | |
157 callback_arg *copy_arg = (callback_arg *)carg->manager->allocate(sizeof(callback_arg)); | |
158 *copy_arg = *carg; | |
159 copy_arg->sid = serial_id; | |
160 psx_callback_in(carg->tid, xml_id, callback_get_xml, (void *)copy_arg); | |
161 | |
162 /* dataは'\0'で終わっている事を期待 (writerで保証する) */ | |
591 | 163 free(taple); |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
164 |
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
165 // arg は使い回すらしい。 |
574 | 166 psx_callback_in(carg->tid, carg->read_id, callbacker, arg); |
566 | 167 } |
168 | |
843
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
841
diff
changeset
|
169 static const char *linda = "localhost"; |
577 | 170 |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
171 static void |
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
172 linda_init(TaskManager *manager, SceneGraphRoot *sgroot, client_t *clist, SceneGraphPtr node) |
566 | 173 { |
174 init_linda(); | |
175 callback_arg *carg = (callback_arg *)manager->allocate(sizeof(callback_arg)); | |
176 | |
579 | 177 carg->tid = open_linda_java(linda, PORT); |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
178 carg->sgroot = sgroot; |
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
179 carg->sgroot->tid = carg->tid; |
566 | 180 carg->read_id = SERIAL_REGIST_TUPLE_NO; |
181 carg->node = node; | |
182 carg->manager = manager; | |
183 carg->clist = clist; | |
574 | 184 psx_callback_in(carg->tid, carg->read_id, callbacker, carg); |
566 | 185 } |
186 | |
593
75c78f8fba24
sending and moving of multi xml work (linda)
kazz@kazzone.st.ie.u-ryukyu.ac.jp
parents:
592
diff
changeset
|
187 MainLoopPtr |
566 | 188 dynamic_create::init(Viewer *sgroot, int screen_w, int screen_h) |
189 { | |
190 client_t *clist; | |
191 clist = (client_t *)sgroot->manager->allocate(sizeof(client_t)); | |
192 | |
193 client_list_init(sgroot->manager, clist); | |
194 | |
195 SceneGraphPtr parent; | |
196 parent = sgroot->createSceneGraph(); | |
197 parent->set_move_collision(earth_move, earth_collision); | |
671
7761ebf9c62a
fix several Renderer/Test with (void*)sgroot.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
198 linda_init(sgroot->manager, sgroot->sgroot, clist, parent); |
566 | 199 |
200 // SceneGraphRoot に、使用する SceneGraph を設定する | |
201 // このとき、ユーザーが記述した SceneGraph の root を渡す。 | |
202 sgroot->setSceneData(parent); | |
203 return sgroot; | |
204 } | |
205 | |
206 extern Application * | |
207 application() { | |
208 return new dynamic_create(); | |
209 } | |
210 | |
211 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
212 | |
213 extern int init(TaskManager *manager, int argc, char *argv[]); | |
214 extern void task_initialize(); | |
215 static void TMend(TaskManager *manager); | |
216 | |
217 int | |
218 TMmain(TaskManager *manager, int argc, char *argv[]) | |
219 { | |
220 task_initialize(); | |
221 manager->set_TMend(TMend); | |
577 | 222 |
223 for(int i=0;i<argc;i++) { | |
224 if (strcmp(argv[i],"-linda") == 0 && i+1<=argc) { | |
225 linda = argv[i+1]; | |
226 } | |
227 } | |
228 | |
566 | 229 return init(manager, argc, argv); |
230 } | |
231 | |
232 void | |
233 TMend(TaskManager *manager) | |
234 { | |
235 printf("test_nogl end\n"); | |
236 } | |
237 | |
238 /* end */ |