0
|
1 /*
|
17
|
2 * $Id$
|
0
|
3 */
|
|
4 #include <stdio.h>
|
|
5 #include <stdlib.h>
|
|
6 #include <math.h>
|
46
|
7 #include <arpa/inet.h>
|
0
|
8 #include <libps2.h>
|
|
9 #include <ps2util.h>
|
|
10
|
|
11 #include "car.h"
|
|
12 #include "game.h"
|
|
13 #include "lindaapi.h"
|
44
|
14 #include "linda.h"
|
0
|
15
|
|
16 extern void carNode_append(CarPtr);
|
|
17 extern FILE *main_fp;
|
43
|
18 static int my_id;
|
0
|
19 static CarPtr linda_carlist[CLIENT_MAX+1];
|
|
20 static int linda_seq[CLIENT_MAX+1];
|
|
21
|
61
|
22 static Bool (*sche_func)(int);
|
|
23
|
0
|
24 static void
|
44
|
25 set_header(unsigned int data, char *pkt, int offset)
|
|
26 {
|
|
27 int *ipkt;
|
|
28 int ndata = htonl(data);
|
|
29
|
|
30 ipkt = (int*)pkt;
|
|
31 ipkt[offset/4] = ndata;
|
|
32 }
|
|
33
|
|
34 static unsigned int
|
|
35 get_header(char *pkt, int offset)
|
|
36 {
|
|
37 int *ipkt;
|
|
38 int data;
|
|
39 unsigned int header;
|
|
40
|
|
41 ipkt = (int *)pkt;
|
|
42 data = ipkt[offset/4];
|
|
43 header = (unsigned int)ntohl(data);
|
|
44
|
|
45 return header;
|
|
46 }
|
|
47
|
|
48 static char*
|
|
49 make_packet(unsigned int mode, unsigned int carid,
|
|
50 unsigned int courseid, char *data)
|
|
51 {
|
|
52 char *packet;
|
|
53 unsigned int len = 0;
|
|
54
|
|
55 if (data) len += sizeof(FMATRIX);
|
|
56
|
|
57 packet = (char*)malloc(PKT_HEADER_SIZE+len);
|
|
58
|
|
59 set_header(mode, packet, PKT_MODE_OFFSET);
|
|
60 set_header(carid, packet, PKT_CARID_OFFSET);
|
|
61 set_header(courseid, packet, PKT_COURSEID_OFFSET);
|
|
62
|
|
63 if (data)
|
|
64 memcpy(packet+PKT_DATA_OFFSET, data, len);
|
|
65
|
|
66 return packet;
|
|
67 }
|
|
68
|
|
69
|
|
70 static void
|
|
71 send_packet(unsigned int dest, unsigned int mode, unsigned int car,
|
|
72 unsigned int course, char *data)
|
|
73 {
|
|
74 char *pkt;
|
83
|
75 //char *reply;
|
44
|
76 int len = PKT_HEADER_SIZE;
|
|
77
|
|
78 if (data) len += sizeof(FMATRIX);
|
|
79
|
78
|
80 //reply = psx_reply(linda_seq[dest])
|
83
|
81 /*
|
80
|
82 if (linda_seq[dest] == 0) {
|
|
83 pkt = make_packet(mode, car, course, data);
|
|
84 psx_out(dest, pkt, len);
|
|
85 free(pkt);
|
82
|
86 } else if (reply = psx_reply(linda_seq[dest])) {
|
77
|
87 pkt = make_packet(mode, car, course, data);
|
|
88 psx_out(dest, pkt, len);
|
|
89 free(pkt);
|
|
90 psx_free(reply);
|
83
|
91 }
|
|
92 */
|
|
93 pkt = make_packet(mode, car, course, data);
|
|
94 psx_out(dest, pkt, len);
|
|
95 free(pkt);
|
44
|
96 }
|
|
97
|
|
98 static void
|
|
99 get_packet(int id, int *flg, int *mode, int *car, int *course, char *data)
|
|
100 {
|
47
|
101 char *reply = NULL;
|
|
102 char *pkt = NULL;
|
44
|
103
|
|
104 reply = psx_reply(linda_seq[id]);
|
|
105 if (reply) {
|
|
106 pkt = reply+LINDA_HEADER_SIZE;
|
|
107
|
46
|
108 if (flg) *flg = 1;
|
|
109 if (mode) *mode = get_header(pkt, PKT_MODE_OFFSET);
|
|
110 if (car) *car = get_header(pkt, PKT_CARID_OFFSET);
|
|
111 if (course) *course = get_header(pkt, PKT_COURSEID_OFFSET);
|
56
|
112 if (data)
|
|
113 memcpy(data, pkt+PKT_DATA_OFFSET, sizeof(FMATRIX));
|
44
|
114 psx_free(reply);
|
|
115 linda_seq[id] = psx_rd(id);
|
|
116 }
|
|
117 }
|
|
118
|
84
|
119 static void
|
44
|
120 linda_set_schedule(void *func, int mode)
|
|
121 {
|
83
|
122 int id = game.play_id;
|
|
123
|
84
|
124 linda_seq[id] = psx_in(id);
|
|
125 sche_func = func;
|
|
126 send_packet(id, mode, game.car_id, game.course_id, NULL);
|
44
|
127 }
|
|
128
|
|
129 static Bool
|
58
|
130 linda_sche_wait0(int p)
|
44
|
131 {
|
|
132 int i, flg=0;
|
81
|
133 int mode = 0;
|
46
|
134 int id = game.play_id;
|
44
|
135 int connect = 1; // 接続済みユーザ数
|
|
136
|
47
|
137 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
138 if (i == id) continue;
|
81
|
139 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
82
|
140 if (flg == 1 && mode == MODE_WAIT) {
|
51
|
141 connect++;
|
|
142 flg = 0;
|
|
143 }
|
44
|
144 }
|
|
145
|
58
|
146 if (p == 1 && connect == CLIENT_MAX) {
|
84
|
147 linda_set_schedule(linda_sche_wait_ready0, MODE_WAIT_READY);
|
44
|
148 } else {
|
|
149 return FALSE;
|
|
150 }
|
|
151
|
|
152 }
|
|
153
|
|
154 static Bool
|
58
|
155 linda_sche_wait1(int p)
|
44
|
156 {
|
|
157 int mode;
|
|
158
|
|
159 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
160
|
|
161 if (mode == MODE_WAIT_READY) {
|
|
162 linda_set_schedule(linda_sche_wait_ready1, MODE_WAIT_READY);
|
|
163 return TRUE;
|
|
164 } else {
|
|
165 return FALSE;
|
|
166 }
|
|
167 }
|
|
168
|
|
169 static Bool
|
58
|
170 linda_sche_wait_ready0(int p)
|
44
|
171 {
|
|
172 int i, flg, mode;
|
46
|
173 int id = game.play_id;
|
44
|
174 int connect = 1;
|
|
175
|
49
|
176 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
177 if (i == id) continue;
|
50
|
178 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
51
|
179 if (i == id) {
|
|
180 flg = 0;
|
|
181 continue;
|
|
182 }
|
|
183 if (flg == 1 && mode == MODE_WAIT_READY) {
|
44
|
184 connect++;
|
51
|
185 flg = 0;
|
|
186 }
|
44
|
187 }
|
|
188
|
58
|
189 if (p == 1 && connect == CLIENT_MAX) {
|
44
|
190 linda_set_schedule(linda_sche_opening0, MODE_OPENING);
|
|
191 return TRUE;
|
|
192 } else {
|
|
193 return FALSE;
|
|
194 }
|
|
195
|
|
196 }
|
|
197
|
46
|
198 static Bool
|
58
|
199 linda_sche_wait_ready1(int p)
|
44
|
200 {
|
|
201 int mode;
|
|
202
|
|
203 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
204
|
|
205 if (mode == MODE_OPENING) {
|
|
206 linda_set_schedule(linda_sche_opening1, MODE_OPENING);
|
|
207 return TRUE;
|
|
208 } else {
|
|
209 return FALSE;
|
|
210 }
|
|
211 }
|
|
212
|
46
|
213 static Bool
|
58
|
214 linda_sche_opening0(int p)
|
44
|
215 {
|
|
216 int i, flg, mode;
|
46
|
217 int id = game.play_id;
|
44
|
218 int connect = 1;
|
|
219
|
49
|
220 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
221 if (i == id) continue;
|
50
|
222 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
51
|
223 if (flg == 1 && mode == MODE_OPENING) {
|
44
|
224 connect++;
|
51
|
225 flg = 0;
|
|
226 }
|
44
|
227 }
|
|
228
|
58
|
229 if (p == 1 && connect == CLIENT_MAX) {
|
44
|
230 linda_set_schedule(linda_sche_select_car0, MODE_SELECT_CAR);
|
|
231 return TRUE;
|
|
232 } else {
|
|
233 return FALSE;
|
|
234 }
|
|
235 }
|
|
236
|
46
|
237 static Bool
|
58
|
238 linda_sche_opening1(int p)
|
44
|
239 {
|
|
240 int mode;
|
|
241
|
|
242 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
243
|
|
244 if (mode == MODE_SELECT_CAR) {
|
|
245 linda_set_schedule(linda_sche_select_car1, MODE_SELECT_CAR);
|
|
246 return TRUE;
|
|
247 } else {
|
|
248 return FALSE;
|
|
249 }
|
|
250 }
|
|
251
|
|
252 static Bool
|
58
|
253 linda_sche_select_car0(int p)
|
44
|
254 {
|
|
255 int i, flg, mode;
|
46
|
256 int id = game.play_id;
|
44
|
257 int connect = 1;
|
|
258
|
49
|
259 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
260 if (i == id) continue;
|
50
|
261 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
51
|
262 if (flg == 1 && mode == MODE_SELECT_CAR) {
|
44
|
263 connect++;
|
51
|
264 flg = 0;
|
|
265 }
|
44
|
266 }
|
|
267
|
58
|
268 if (p == 1 && connect == CLIENT_MAX) {
|
44
|
269 linda_set_schedule(linda_sche_select_course0, MODE_SELECT_COURSE);
|
|
270 return TRUE;
|
|
271 } else {
|
|
272 return FALSE;
|
|
273 }
|
|
274 }
|
|
275
|
|
276 static Bool
|
58
|
277 linda_sche_select_car1(int p)
|
44
|
278 {
|
|
279 int mode;
|
|
280
|
|
281 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
282
|
|
283 if (mode == MODE_SELECT_COURSE) {
|
|
284 linda_set_schedule(linda_sche_select_course1, MODE_SELECT_COURSE);
|
|
285 return TRUE;
|
|
286 } else {
|
|
287 return FALSE;
|
|
288 }
|
|
289 }
|
|
290
|
|
291 static Bool
|
58
|
292 linda_sche_select_course0(int p)
|
44
|
293 {
|
46
|
294 int i;
|
|
295 int flg, mode;
|
50
|
296 int connect = 1;
|
46
|
297 int id = game.play_id;
|
44
|
298 static int course_id = 1;
|
|
299
|
|
300 if (course_id != game.course_id) {
|
|
301 course_id = game.course_id;
|
58
|
302 linda_seq[id] = psx_in(id);
|
|
303 send_packet(id, MODE_SELECT_COURSE, 0, course_id, NULL);
|
50
|
304 return FALSE;
|
44
|
305 }
|
|
306
|
49
|
307 for (i=1; i<=CLIENT_MAX; i++) {
|
58
|
308 if (i == id) continue;
|
50
|
309 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
51
|
310 if (flg == 1 && mode == MODE_SELECT_COURSE) {
|
44
|
311 connect++;
|
51
|
312 flg = 0;
|
|
313 }
|
|
314
|
44
|
315 }
|
|
316
|
58
|
317 if (p == 1 && connect == CLIENT_MAX) {
|
68
|
318 linda_set_schedule(linda_sche_ready0, MODE_READY);
|
44
|
319 return TRUE;
|
|
320 } else {
|
|
321 return FALSE;
|
|
322 }
|
|
323 }
|
|
324
|
|
325 static Bool
|
58
|
326 linda_sche_select_course1(int p)
|
44
|
327 {
|
|
328 int mode, course_id;
|
|
329
|
|
330 get_packet(PLAYER_1P, NULL, &mode, NULL, &course_id, NULL);
|
|
331
|
|
332 if (mode == MODE_SELECT_COURSE) {
|
|
333 game.course_id = course_id;
|
|
334 return FALSE;
|
|
335 } else if (mode == MODE_READY) {
|
68
|
336 linda_set_schedule(linda_sche_ready1, MODE_READY);
|
44
|
337 return TRUE;
|
|
338 } else {
|
|
339 return FALSE;
|
|
340 }
|
|
341 }
|
|
342
|
|
343
|
|
344 static Bool
|
68
|
345 linda_sche_ready0(int p)
|
|
346 {
|
|
347 int i, flg, mode;
|
|
348 int id = game.play_id;
|
|
349 int connect = 1;
|
|
350
|
|
351 for (i=1; i<=CLIENT_MAX; i++) {
|
|
352 if (i == id) continue;
|
|
353 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
|
354 if (flg == 1 && mode == MODE_READY) {
|
|
355 connect++;
|
|
356 flg = 0;
|
|
357 }
|
|
358 }
|
|
359
|
|
360 if (p == 1 && connect == CLIENT_MAX) {
|
69
|
361 linda_set_schedule(linda_sche_main_init, MODE_MAIN_INIT);
|
68
|
362 return TRUE;
|
|
363 } else {
|
|
364 return FALSE;
|
|
365 }
|
|
366 }
|
|
367
|
|
368 static Bool
|
|
369 linda_sche_ready1(int p)
|
|
370 {
|
|
371 int mode;
|
|
372
|
|
373 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
374
|
|
375 if (mode == MODE_MAIN_INIT) {
|
70
|
376 linda_set_schedule(linda_sche_main_init, MODE_MAIN_INIT);
|
68
|
377 return TRUE;
|
|
378 } else {
|
|
379 return FALSE;
|
|
380 }
|
|
381 }
|
|
382
|
|
383 static Bool
|
69
|
384 linda_sche_main_init(int p)
|
|
385 {
|
|
386 int i, flg, mode, car_id;
|
|
387 int id = game.play_id;
|
|
388 int connect = 1;
|
|
389 CarPtr car = NULL;
|
|
390
|
|
391 for (i=1; i<=CLIENT_MAX; i++) {
|
|
392 if (i == id) continue;
|
|
393 get_packet(i, &flg, &mode, &car_id, NULL, NULL);
|
|
394
|
|
395 if (flg == 1 && mode == MODE_MAIN_INIT) {
|
|
396 if (linda_carlist[i] == NULL) {
|
|
397 car = car_init(car_id);
|
|
398 carNode_append(car);
|
|
399 linda_carlist[i] = car;
|
|
400 }
|
|
401 connect++;
|
|
402 flg = 0;
|
|
403 }
|
|
404 }
|
|
405
|
|
406 if (p == 1 && connect == CLIENT_MAX) {
|
|
407 if (id == PLAYER_1P)
|
|
408 linda_set_schedule(linda_sche_main_ready0, MODE_MAIN_READY);
|
|
409 else
|
|
410 linda_set_schedule(linda_sche_main_ready1, MODE_MAIN_READY);
|
|
411 return TRUE;
|
|
412 } else {
|
|
413 return FALSE;
|
|
414 }
|
|
415 }
|
|
416
|
|
417
|
|
418 static Bool
|
|
419 linda_sche_main_ready0(int p)
|
44
|
420 {
|
67
|
421 int i, flg, mode;
|
|
422 int id = game.play_id;
|
|
423 int connect = 1;
|
|
424
|
|
425 for (i=1; i<=CLIENT_MAX; i++) {
|
|
426 if (i == id) continue;
|
|
427 get_packet(i, &flg, &mode, NULL, NULL, NULL);
|
69
|
428 if (flg == 1 && mode == MODE_MAIN_READY) {
|
67
|
429 connect++;
|
|
430 flg = 0;
|
|
431 }
|
|
432 }
|
|
433
|
|
434 if (p == 1 && connect == CLIENT_MAX) {
|
74
|
435 linda_set_schedule(linda_sche_main, MODE_MAIN);
|
67
|
436 return TRUE;
|
|
437 } else {
|
|
438 return FALSE;
|
|
439 }
|
44
|
440 }
|
|
441
|
|
442 static Bool
|
69
|
443 linda_sche_main_ready1(int p)
|
44
|
444 {
|
67
|
445 int mode;
|
|
446
|
|
447 get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
|
|
448
|
|
449 if (mode == MODE_MAIN) {
|
74
|
450 linda_set_schedule(linda_sche_main, MODE_MAIN);
|
67
|
451 return TRUE;
|
|
452 } else {
|
|
453 return FALSE;
|
|
454 }
|
52
|
455 }
|
|
456
|
|
457 static Bool
|
74
|
458 linda_sche_main(int p)
|
|
459 {
|
|
460 int i, flg, mode;
|
|
461 int id = game.play_id;
|
|
462 int connect = 1;
|
|
463 FMATRIX po;
|
|
464 CarPtr mycar = game.jiki;
|
|
465 CarPtr enemy = NULL;
|
|
466
|
|
467 for (i=1; i<=CLIENT_MAX; i++) {
|
|
468 ps2_vu0_unit_matrix(po);
|
83
|
469 get_packet(i, &flg, &mode, NULL, NULL, (char*)po);
|
74
|
470
|
|
471 if (i == id) {
|
|
472 ps2_vu0_copy_matrix(po, mycar->body->transfer);
|
|
473 ps2_vu0_copy_vector(po[3], mycar->location);
|
|
474
|
|
475 linda_seq[i] = psx_in(i);
|
|
476 send_packet(i, MODE_MAIN, 0, 0, (char*)po);
|
|
477 } else {
|
|
478 enemy = linda_carlist[i];
|
|
479 get_packet(i, NULL, &mode, NULL, NULL, (char*)po);
|
83
|
480 if (flg == 1 && mode == MODE_MAIN) {
|
74
|
481 ps2_vu0_copy_matrix(enemy->body->transfer, po);
|
75
|
482 enemy->body->transfer[3][0] -= mycar->location[0];
|
|
483 enemy->body->transfer[3][1] -= mycar->location[1];
|
|
484 enemy->body->transfer[3][2] -= mycar->location[2];
|
74
|
485 enemy->body->transfer[3][3] = 1;
|
|
486 }
|
|
487 }
|
|
488 }
|
76
|
489 return FALSE;
|
74
|
490 }
|
|
491
|
61
|
492 Bool
|
|
493 linda_update(int p)
|
|
494 {
|
|
495 return sche_func(p);
|
|
496 }
|
|
497
|
44
|
498 #if 0
|
0
|
499
|
|
500 /*
|
|
501 * 位置が同じなら1を返す。
|
|
502 * もっと良い比較方法があるんでは...
|
|
503 */
|
|
504 static int
|
|
505 linda_jiki_compareLocation()
|
|
506 {
|
|
507 float x,y,z;
|
|
508 double d;
|
|
509
|
|
510 if (common_state == GAME_MAIN || common_state == GAME_GOAL) {
|
|
511 x = jiki.position[3][0] - game.jiki->location[0];
|
|
512 y = jiki.position[3][1] - game.jiki->location[1];
|
|
513 z = jiki.position[3][2] - game.jiki->location[2];
|
|
514 d = sqrt(x*x+y*y+z*z);
|
|
515
|
|
516 if (d < 1.0) {
|
|
517 return 1;
|
|
518 } else {
|
|
519 return 0;
|
|
520 }
|
|
521 } else {
|
|
522 return 1;
|
|
523 }
|
|
524 }
|
|
525
|
44
|
526
|
0
|
527 /*
|
|
528 * 自機情報が更新されていなければ
|
|
529 * 0を返す(psx_outしない)
|
|
530 */
|
|
531 static int
|
|
532 linda_jiki_compare()
|
|
533 {
|
|
534 if ((jiki.car_id == game.car_id) &&
|
|
535 (jiki.course_id == game.course_id) &&
|
|
536 (jiki.create_flg == ((game.jiki) ? 1:0)) &&
|
|
537 (jiki.state == common_state) &&
|
|
538 (linda_jiki_compareLocation())) {
|
|
539 return 0;
|
|
540 } else {
|
|
541 return 1;
|
|
542 }
|
|
543 }
|
|
544
|
|
545 static void
|
|
546 linda_jiki_update()
|
|
547 {
|
|
548 int i,j;
|
44
|
549
|
0
|
550
|
|
551 jiki.car_id = game.car_id;
|
|
552 jiki.course_id = game.course_id;
|
|
553 jiki.create_flg = (game.jiki) ? 1 : 0;
|
|
554 jiki.state = common_state;
|
|
555
|
|
556 if (common_state == GAME_MAIN || common_state == GAME_GOAL) {
|
|
557 for (i=0; i<3; i++) {
|
|
558 for (j=0; j<4; j++) {
|
|
559 jiki.position[i][j]
|
|
560 = game.jiki->body->transfer[i][j];
|
|
561 }
|
|
562 }
|
|
563 jiki.position[3][0] = game.jiki->location[0];
|
|
564 jiki.position[3][1] = game.jiki->location[1];
|
|
565 jiki.position[3][2] = game.jiki->location[2];
|
|
566 jiki.position[3][3] = 1;
|
|
567 }
|
|
568 }
|
|
569
|
|
570 void
|
|
571 linda_update()
|
|
572 {
|
|
573 int i;
|
|
574 int barrier = 1; // バリア同期(?)用
|
|
575 int connect = 1;
|
44
|
576 int mode, id, flg;
|
0
|
577 char* reply;
|
44
|
578 char* pkt;
|
0
|
579 CarPtr car = NULL;
|
|
580
|
|
581 for (i=1; i<=CLIENT_MAX; i++) {
|
|
582 reply = psx_reply(linda_seq[i]);
|
|
583 if (reply) {
|
44
|
584 pkt = reply+LINDA_HEADER_SIZE;
|
|
585 mode = get_header(pkt, PKT_MODE_OFFSET);
|
|
586 id = get_header(pkt, PKT_ID_OFFSET);
|
|
587 flg = get_header(pkt, PKT_FLG_OFFSET);
|
|
588
|
0
|
589 if (i != game.play_id) {
|
|
590 connect++;
|
|
591
|
|
592 car = linda_carlist[i];
|
|
593 if (common_state == GAME_MAIN && !car && p->create_flg == 1) {
|
|
594 car = car_init(p->car_id);
|
|
595 carNode_append(car);
|
|
596 linda_carlist[i] = car;
|
|
597 }
|
|
598 linda_enemy_update(i, car, p);
|
|
599 if (common_state == p->state) {
|
|
600 barrier++;
|
|
601 }
|
|
602 }
|
|
603 psx_free(reply);
|
|
604 linda_seq[i] = psx_rd(i);
|
|
605 }
|
|
606 }
|
|
607
|
|
608 if (connect == CLIENT_MAX) {
|
|
609 if (game.state == GAME_WAIT) {
|
|
610 gFont_SetString("CONNECT OK!!", 170, 300);
|
|
611 if (game.play_id == 1)
|
|
612 gFont_SetString(" PUSH START ", 170, 400);
|
|
613 }
|
|
614
|
|
615 // ごちゃごちゃしてる...
|
|
616 // なんか無駄な処理がありそうだ
|
|
617 if (game.play_id == 1) {
|
|
618 // 全員のフラグ成立
|
|
619 if (common_state == GAME_GOAL) {
|
|
620 if (game.state == GAME_FINISH) {
|
|
621 common_state = game.state;
|
|
622 } else {
|
|
623 game.state = common_state;
|
|
624 }
|
|
625 } else if (barrier == CLIENT_MAX) {
|
|
626 common_state = game.state;
|
|
627 } else {
|
|
628 game.state = common_state;
|
|
629 }
|
|
630 } else {
|
|
631 if (game.state == GAME_GOAL) {
|
|
632 if (common_state != GAME_FINISH) {
|
|
633 common_state = game.state;
|
|
634 } else {
|
|
635 game.state = common_state;
|
|
636 }
|
|
637 } else {
|
|
638 game.state = common_state;
|
|
639 }
|
|
640 }
|
|
641 } else {
|
|
642 if (game.state == GAME_WAIT) {
|
|
643 gFont_SetString("WAITING...", 200, 100);
|
|
644 }
|
|
645 game.state = common_state;
|
|
646 }
|
|
647
|
|
648 if (linda_jiki_compare()) {
|
|
649 #ifdef DEBUG
|
|
650 // どのタイミングでoutされてるか見る
|
|
651 // 必要なときだけoutしないと重いですね当然だけど
|
|
652 //fprintf(main_fp, "psx_out() jiki\n");
|
|
653 #endif
|
|
654 linda_jiki_update();
|
|
655 // 無理矢理
|
|
656 // 古いものを消すだけなんだけど
|
|
657 // 正しいやり方が他に有るのかな?
|
|
658 // 実行し続けてると最終的に激重になるので
|
|
659 // ここら辺に問題が有るのだろうか。
|
|
660 // psx_free(psx_reply(psx_in(game.play_id)));
|
|
661 linda_seq[my_id]=psx_in(game.play_id);
|
|
662 psx_out(game.play_id, (char*)&jiki, sizeof(CarInfo));
|
|
663 }
|
|
664 }
|
44
|
665 #endif
|
0
|
666
|
|
667 static int
|
|
668 get_id()
|
|
669 {
|
|
670 unsigned char * reply;
|
|
671 int seq;
|
|
672 int id;
|
|
673
|
|
674 //ユーザIDが格納されているTUPLE SpaceのIDへアクセス
|
|
675 seq = psx_in(LINDA_ASK_ID);
|
|
676
|
|
677 // IDが取得できるまでループ
|
|
678 while((reply = psx_reply(seq)) == 0) psx_sync_n();
|
|
679
|
|
680 id = atoi(reply+LINDA_HEADER_SIZE);
|
|
681 psx_free(reply);
|
|
682 return id;
|
|
683 }
|
|
684
|
|
685 void
|
43
|
686 linda_env_init()
|
0
|
687 {
|
43
|
688 int i;
|
0
|
689
|
|
690 for (i=0; i<CLIENT_MAX+1; i++) {
|
|
691 linda_carlist[i] = NULL;
|
|
692 }
|
43
|
693
|
0
|
694 }
|
|
695
|
|
696
|
|
697
|
|
698 int
|
|
699 linda_init()
|
|
700 {
|
|
701 int i;
|
|
702
|
|
703 start_linda(LINDA_HOST);
|
|
704 my_id = get_id();
|
|
705
|
|
706 for (i=1; i<=CLIENT_MAX; i++) {
|
|
707 if (i == my_id) {
|
44
|
708 send_packet(i, MODE_WAIT, i, 0, NULL);
|
0
|
709 }
|
|
710 linda_seq[i] = psx_rd(i);
|
|
711 }
|
|
712 psx_sync_n();
|
|
713
|
48
|
714 if (my_id == PLAYER_1P) {
|
63
|
715 sche_func = &linda_sche_wait0;
|
48
|
716 } else {
|
63
|
717 sche_func = &linda_sche_wait1;
|
48
|
718 }
|
84
|
719 send_packet(game.play_id, MODE_WAIT, 1, 1, NULL);
|
|
720
|
0
|
721 return my_id;
|
|
722 }
|