comparison Renderer/Test/aquarium.cc @ 881:c81744aaa3ef

cannot load xml of 3rd screen bug fix (include init bug yet)
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Fri, 09 Jul 2010 14:33:31 +0900
parents f4bdf2b0d7da
children fb23a3cce848
comparison
equal deleted inserted replaced
880:f4bdf2b0d7da 881:c81744aaa3ef
10 #include "aquarium.h" 10 #include "aquarium.h"
11 #include "aquarium.pb.h" 11 #include "aquarium.pb.h"
12 12
13 #define GET_SERIAL_ID 65535 13 #define GET_SERIAL_ID 65535
14 14
15 int aquarium::last_player_id = 1; 15 int aquarium::last_player_id = 0;
16 16
17 Viewer *aquarium::sgroot; 17 Viewer *aquarium::sgroot;
18 SceneGraphPtr aquarium::parent;
19 linda_t aquarium::linda_addr = { "localhost", 10000 }; 18 linda_t aquarium::linda_addr = { "localhost", 10000 };
20 int aquarium::linda; 19 int aquarium::linda;
21 int aquarium::serial_id; 20 int aquarium::serial_id;
22 int aquarium::width; 21 int aquarium::width;
23 int aquarium::start_x; 22 int aquarium::start_x;
41 null_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree) 40 null_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree)
42 { 41 {
43 } 42 }
44 43
45 void 44 void
45 aquarium::update_last_player_id() {
46 last_player_id++;
47 if (last_player_id == serial_id)
48 last_player_id++;
49 }
50
51 void
46 aquarium::set_position(SceneGraphPtr node, unsigned char *reply) { 52 aquarium::set_position(SceneGraphPtr node, unsigned char *reply) {
47 aqua::Position *pos = new aqua::Position(); 53 aqua::Position *pos = new aqua::Position();
48 pos->ParseFromArray(reply + LINDA_HEADER_SIZE, psx_get_datalength(reply)); 54 pos->ParseFromArray(reply + LINDA_HEADER_SIZE, psx_get_datalength(reply));
49 node->xyz[0] = pos->x() - start_x; 55 node->stack_xyz[0] = node->xyz[0] = pos->x() - start_x;
50 node->xyz[1] = pos->y(); 56 node->stack_xyz[1] = node->xyz[1] = pos->y();
51 printf("xyz: %f, %f\n", node->xyz[0], node->xyz[1]);
52 57
53 delete pos; 58 delete pos;
54 } 59 }
55 60
56 static void 61 static void
57 update_position_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) 62 update_position_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
58 { 63 {
59 printf("move_xyz: %f, %f\n", node->xyz[0], node->xyz[1]);
60 // LindaServerから座標データを取得してオブジェクトに反映させる。 64 // LindaServerから座標データを取得してオブジェクトに反映させる。
61 if (!node->resend_flag || node->seq_rd != node->seq) { 65 if (!node->resend_flag || node->seq_rd != node->seq) {
62 unsigned char *reply_rd = psx_reply(node->seq_rd); 66 unsigned char *reply_rd = psx_reply(node->seq_rd);
63 if (reply_rd != NULL) { 67 if (reply_rd != NULL) {
64 aquarium::set_position(node, reply_rd); 68 aquarium::set_position(node, reply_rd);
77 node->resend_flag = false; 81 node->resend_flag = false;
78 } 82 }
79 } 83 }
80 84
81 SceneGraphPtr 85 SceneGraphPtr
82 create_sg(Viewer *viewer, SceneGraphPtr parent, unsigned char *data, int len, int serial_id) 86 create_sg(Viewer *viewer, SceneGraphPtr par, unsigned char *data, int len, int serial_id)
83 { 87 {
84 SceneGraphPtr child = viewer->sgroot->createSceneGraph(); 88 SceneGraphPtr child = viewer->sgroot->createSceneGraph();
85 viewer->sgroot->createFromXMLmemory(viewer->sgroot->tmanager, child, (char *)data, len); 89 viewer->sgroot->createFromXMLmemory(viewer->sgroot->tmanager, child, (char *)data, len);
86 child->set_move_collision(update_position_move, null_collision); 90 child->set_move_collision(update_position_move, null_collision);
87 child->id = serial_id; 91 child->id = serial_id;
88 child->seq = psx_wait_rd(aquarium::linda, serial_id * 10 + 1); 92 child->seq = psx_wait_rd(aquarium::linda, serial_id * 10 + 1);
89 child->seq_rd = psx_rd(aquarium::linda, serial_id * 10 + 1); 93 child->seq_rd = psx_rd(aquarium::linda, serial_id * 10 + 1);
90 child->resend_flag = false; 94 child->resend_flag = false;
91 parent->addChild(child); 95 par->addChild(child);
92 return child; 96 return child;
93 } 97 }
94 98
95 static void 99 static void
96 check_new_player_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) 100 check_new_player_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
99 if (reply_rd != NULL) { 103 if (reply_rd != NULL) {
100 unsigned char *xml_data = reply_rd + LINDA_HEADER_SIZE; 104 unsigned char *xml_data = reply_rd + LINDA_HEADER_SIZE;
101 int xml_len = psx_get_datalength(reply_rd); 105 int xml_len = psx_get_datalength(reply_rd);
102 create_sg(aquarium::sgroot, node, xml_data, xml_len, aquarium::last_player_id); 106 create_sg(aquarium::sgroot, node, xml_data, xml_len, aquarium::last_player_id);
103 psx_free(reply_rd); 107 psx_free(reply_rd);
104 aquarium::last_player_id++; 108 aquarium::update_last_player_id();
105 int tuple_id = aquarium::last_player_id * 10; 109 int tuple_id = aquarium::last_player_id * 10;
106 aquarium::parent->seq_rd = psx_rd(aquarium::linda, tuple_id); 110 node->seq_rd = psx_rd(aquarium::linda, tuple_id);
107 } 111 }
108 // printf("rd id: %d\n", aquarium::last_player_id); 112 // printf("rd id: %d\n", aquarium::last_player_id);
109 } 113 }
110 114
111 void * 115 void *
182 aquarium::send_position(node); 186 aquarium::send_position(node);
183 } 187 }
184 } 188 }
185 189
186 void 190 void
187 aquarium::create_my_sg(Viewer *viewer, SceneGraphPtr parent, int screen_w, int screen_h) 191 aquarium::create_my_sg(Viewer *viewer, SceneGraphPtr par, int screen_w, int screen_h)
188 { 192 {
189 int size; 193 int size;
190 void *addr = file_map(xml_file_name, &size); 194 void *addr = file_map(xml_file_name, &size);
191 SceneGraphPtr sgp = viewer->createSceneGraph(); 195 SceneGraphPtr sgp = viewer->createSceneGraph();
192 viewer->createFromXMLmemory(sgp, (char *)addr, size); 196 viewer->createFromXMLmemory(sgp, (char *)addr, size);
193 sgp->set_move_collision(my_move, null_collision); 197 sgp->set_move_collision(my_move, null_collision);
194 198
195 parent->addChild(sgp); 199 par->addChild(sgp);
196 200
197 int xml_id = serial_id * 10; 201 int xml_id = serial_id * 10;
198 psx_out(linda, xml_id, (unsigned char *)addr, size); 202 psx_out(linda, xml_id, (unsigned char *)addr, size);
199 int pos_id = serial_id * 10 + 1; 203 int pos_id = serial_id * 10 + 1;
200 204
214 { 218 {
215 this->sgroot = sgroot; 219 this->sgroot = sgroot;
216 width = screen_w; 220 width = screen_w;
217 linda_connect(); // 接続に合わせて serial_id も取得 221 linda_connect(); // 接続に合わせて serial_id も取得
218 update_screen_scope(); 222 update_screen_scope();
219 parent = sgroot->createSceneGraph(); 223 SceneGraphPtr parent = sgroot->createSceneGraph();
220 parent->set_move_collision(check_new_player_move, null_collision); 224 parent->set_move_collision(check_new_player_move, null_collision);
221 225
222 create_my_sg(sgroot, parent, screen_w, screen_h); 226 create_my_sg(sgroot, parent, screen_w, screen_h);
223 if (serial_id == last_player_id) 227 update_last_player_id();
224 last_player_id++; 228
225 int tuple_id = aquarium::last_player_id * 10; 229 int tuple_id = aquarium::last_player_id * 10;
226 parent->seq_rd = psx_rd(linda, tuple_id); 230 parent->seq_rd = psx_rd(linda, tuple_id);
227 sgroot->setSceneData(parent); 231 sgroot->setSceneData(parent);
228 return sgroot; 232 return sgroot;
229 } 233 }