Mercurial > hg > old > magoroku_racing
comparison linda.c @ 91:cb6c6de125dc
halfway
author | Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 May 2011 14:44:03 +0900 |
parents | 8edae89a3877 |
children | 0b65ca27f113 |
comparison
equal
deleted
inserted
replaced
90:8edae89a3877 | 91:cb6c6de125dc |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <stdbool.h> | 3 #include <stdbool.h> |
4 #include <string.h> | |
4 #include <math.h> | 5 #include <math.h> |
5 //#include <arpa/inet.h> | 6 #include <arpa/inet.h> |
6 //#include <libps2.h> | 7 #include "libps2.h" |
7 //#include <ps2util.h> | 8 #include "ps2util.h" |
8 | 9 |
9 #include "car.h" | 10 #include "car.h" |
10 #include "game.h" | 11 #include "game.h" |
11 //#include "Linda/lindaapi.h" | 12 #include "Linda/lindaapi.h" |
12 #include "linda.h" | 13 #include "linda.h" |
13 | 14 |
14 //extern void psx_free(unsigned char *); | 15 extern void psx_free(unsigned char *); |
15 extern void carNode_append(CarPtr); | 16 extern void carNode_append(CarPtr); |
16 extern FILE *main_fp; | 17 extern FILE *main_fp; |
17 static int my_id; | 18 static int my_id; |
18 static CarPtr linda_carlist[CLIENT_MAX+1]; | 19 static CarPtr linda_carlist[CLIENT_MAX+1]; |
19 static int linda_seq[CLIENT_MAX+1]; | 20 static int linda_seq[CLIENT_MAX+1]; |
49 unsigned int courseid, char *data) | 50 unsigned int courseid, char *data) |
50 { | 51 { |
51 char *packet; | 52 char *packet; |
52 unsigned int len = 0; | 53 unsigned int len = 0; |
53 | 54 |
54 // if (data) len += sizeof(FMATRIX); | 55 if (data) len += sizeof(FMATRIX); |
55 | 56 |
56 packet = (char*)malloc(PKT_HEADER_SIZE+len); | 57 packet = (char*)malloc(PKT_HEADER_SIZE+len); |
57 | 58 |
58 set_header(mode, packet, PKT_MODE_OFFSET); | 59 set_header(mode, packet, PKT_MODE_OFFSET); |
59 set_header(carid, packet, PKT_CARID_OFFSET); | 60 set_header(carid, packet, PKT_CARID_OFFSET); |
60 set_header(courseid, packet, PKT_COURSEID_OFFSET); | 61 set_header(courseid, packet, PKT_COURSEID_OFFSET); |
61 | 62 |
62 if (data) | 63 if (data) |
63 // memcpy(packet+PKT_DATA_OFFSET, data, len); | 64 memcpy(packet+PKT_DATA_OFFSET, data, len); |
64 | 65 |
65 return packet; | 66 return packet; |
66 } | 67 } |
67 | 68 |
68 | 69 |
72 { | 73 { |
73 char *pkt; | 74 char *pkt; |
74 char *reply; | 75 char *reply; |
75 int len = PKT_HEADER_SIZE; | 76 int len = PKT_HEADER_SIZE; |
76 | 77 |
77 // if (data) len += sizeof(FMATRIX); | 78 if (data) len += sizeof(FMATRIX); |
78 | 79 |
79 //reply = psx_reply(linda_seq[dest]) | 80 reply = psx_reply(linda_seq[dest]); |
80 /* | 81 |
81 if (linda_seq[dest] == 0) { | 82 if (linda_seq[dest] == 0) { |
82 pkt = make_packet(mode, car, course, data); | 83 pkt = make_packet(mode, car, course, data); |
83 psx_out(dest, pkt, len); | 84 psx_out(dest, pkt, len); |
84 free(pkt); | 85 free(pkt); |
85 } else if (reply = psx_reply(linda_seq[dest])) { | 86 } else if (reply = psx_reply(linda_seq[dest])) { |
86 pkt = make_packet(mode, car, course, data); | 87 pkt = make_packet(mode, car, course, data); |
87 psx_out(dest, pkt, len); | 88 psx_out(dest, pkt, len); |
88 free(pkt); | 89 free(pkt); |
89 psx_free(reply); | 90 psx_free(reply); |
90 } | 91 } |
91 */ | 92 |
92 pkt = make_packet(mode, car, course, data); | 93 pkt = make_packet(mode, car, course, data); |
93 psx_out(dest, pkt, len); | 94 //psx_out(dest, pkt, len); |
94 free(pkt); | 95 free(pkt); |
95 } | 96 } |
96 | 97 |
97 static void | 98 static void |
98 get_packet(int id, int *flg, int *mode, int *car, int *course, char *data) | 99 get_packet(int id, int *flg, int *mode, int *car, int *course, char *data) |
106 | 107 |
107 if (flg) *flg = 1; | 108 if (flg) *flg = 1; |
108 if (mode) *mode = get_header(pkt, PKT_MODE_OFFSET); | 109 if (mode) *mode = get_header(pkt, PKT_MODE_OFFSET); |
109 if (car) *car = get_header(pkt, PKT_CARID_OFFSET); | 110 if (car) *car = get_header(pkt, PKT_CARID_OFFSET); |
110 if (course) *course = get_header(pkt, PKT_COURSEID_OFFSET); | 111 if (course) *course = get_header(pkt, PKT_COURSEID_OFFSET); |
111 if (data) | 112 if (data) memcpy(data, pkt+PKT_DATA_OFFSET, sizeof(FMATRIX)); |
112 // memcpy(data, pkt+PKT_DATA_OFFSET, sizeof(FMATRIX)); | |
113 psx_free(reply); | 113 psx_free(reply); |
114 linda_seq[id] = psx_rd(id); | 114 linda_seq[id] = psx_rd(id); |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
456 linda_sche_main(int p, Game *game) | 456 linda_sche_main(int p, Game *game) |
457 { | 457 { |
458 int i, flg, mode; | 458 int i, flg, mode; |
459 int id = game->play_id; | 459 int id = game->play_id; |
460 int connect = 1; | 460 int connect = 1; |
461 // FMATRIX po; | 461 FMATRIX po; |
462 CarPtr mycar = game->jiki; | 462 CarPtr mycar = game->jiki; |
463 CarPtr enemy = NULL; | 463 CarPtr enemy = NULL; |
464 | 464 |
465 for (i=1; i<=CLIENT_MAX; i++) { | 465 for (i=1; i<=CLIENT_MAX; i++) { |
466 // ps2_vu0_unit_matrix(po); | 466 ps2_vu0_unit_matrix(po); |
467 // get_packet(i, &flg, &mode, NULL, NULL, (char*)po); | 467 get_packet(i, &flg, &mode, NULL, NULL, (char*)po); |
468 | 468 |
469 if (i == id) { | 469 if (i == id) { |
470 // ps2_vu0_copy_matrix(po, mycar->body->transfer); | 470 ps2_vu0_copy_matrix(po, mycar->body->transfer); |
471 // ps2_vu0_copy_vector(po[3], mycar->location); | 471 ps2_vu0_copy_vector(po[3], mycar->location); |
472 | 472 |
473 linda_seq[i] = psx_in(i); | 473 linda_seq[i] = psx_in(i); |
474 // send_packet(i, MODE_MAIN, 0, 0, (char*)po); | 474 send_packet(i, MODE_MAIN, 0, 0, (char*)po); |
475 } else { | 475 } else { |
476 enemy = linda_carlist[i]; | 476 enemy = linda_carlist[i]; |
477 if (flg == 1 && mode == MODE_MAIN) { | 477 if (flg == 1 && mode == MODE_MAIN) { |
478 /* ps2_vu0_copy_matrix(enemy->body->transfer, po); | 478 ps2_vu0_copy_matrix(enemy->body->transfer, po); |
479 enemy->body->transfer[3][0] -= mycar->location[0]; | 479 enemy->body->transfer[3][0] -= mycar->location[0]; |
480 enemy->body->transfer[3][1] -= mycar->location[1]; | 480 enemy->body->transfer[3][1] -= mycar->location[1]; |
481 enemy->body->transfer[3][2] -= mycar->location[2]; | 481 enemy->body->transfer[3][2] -= mycar->location[2]; |
482 enemy->body->transfer[3][3] = 1;*/ | 482 enemy->body->transfer[3][3] = 1; |
483 } | 483 } |
484 } | 484 } |
485 } | 485 } |
486 | 486 |
487 if (p == 1 && connect == CLIENT_MAX) { | 487 if (p == 1 && connect == CLIENT_MAX) { |
656 | 656 |
657 if (linda_jiki_compare()) { | 657 if (linda_jiki_compare()) { |
658 #ifdef DEBUG | 658 #ifdef DEBUG |
659 // どのタイミングでoutされてるか見る | 659 // どのタイミングでoutされてるか見る |
660 // 必要なときだけoutしないと重いですね当然だけど | 660 // 必要なときだけoutしないと重いですね当然だけど |
661 //fprintf(main_fp, "psx_out() jiki\n"); | 661 fprintf(main_fp, "psx_out() jiki\n"); |
662 #endif | 662 #endif |
663 linda_jiki_update(); | 663 linda_jiki_update(); |
664 // 無理矢理 | 664 // 無理矢理 |
665 // 古いものを消すだけなんだけど | 665 // 古いものを消すだけなんだけど |
666 // 正しいやり方が他に有るのかな? | 666 // 正しいやり方が他に有るのかな? |
667 // 実行し続けてると最終的に激重になるので | 667 // 実行し続けてると最終的に激重になるので |
668 // ここら辺に問題が有るのだろうか。 | 668 // ここら辺に問題が有るのだろうか。 |
669 // psx_free(psx_reply(psx_in(game->play_id))); | 669 psx_free(psx_reply(psx_in(game->play_id))); |
670 linda_seq[my_id]=psx_in(game->play_id); | 670 linda_seq[my_id]=psx_in(game->play_id); |
671 psx_out(game->play_id, (char*)&jiki, sizeof(CarInfo)); | 671 psx_out(game->play_id, (char*)&jiki, sizeof(CarInfo)); |
672 } | 672 } |
673 } | 673 } |
674 #endif | 674 #endif |
685 | 685 |
686 // IDが取得できるまでループ | 686 // IDが取得できるまでループ |
687 while((reply = psx_reply(seq)) == 0) psx_sync_n(); | 687 while((reply = psx_reply(seq)) == 0) psx_sync_n(); |
688 | 688 |
689 id = atoi(reply+LINDA_HEADER_SIZE); | 689 id = atoi(reply+LINDA_HEADER_SIZE); |
690 //psx_free(reply); | 690 psx_free(reply); |
691 return id; | 691 return id; |
692 } | 692 } |
693 | 693 |
694 void | 694 void |
695 linda_env_init() | 695 linda_env_init() |