diff 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
line wrap: on
line diff
--- a/linda.c	Thu May 19 16:41:21 2011 +0900
+++ b/linda.c	Thu May 26 14:44:03 2011 +0900
@@ -1,17 +1,18 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
+#include <string.h>
 #include <math.h>
-//#include <arpa/inet.h>
-//#include <libps2.h>
-//#include <ps2util.h>
+#include <arpa/inet.h>
+#include "libps2.h"
+#include "ps2util.h"
 
 #include "car.h"
 #include "game.h"
-//#include "Linda/lindaapi.h"
+#include "Linda/lindaapi.h"
 #include "linda.h"
 
-//extern void psx_free(unsigned char *);
+extern void psx_free(unsigned char *);
 extern void carNode_append(CarPtr);
 extern FILE *main_fp;
 static int my_id;
@@ -51,7 +52,7 @@
     char *packet;
     unsigned int len = 0;
 
-    //    if (data) len += sizeof(FMATRIX);
+    if (data) len += sizeof(FMATRIX);
 
     packet = (char*)malloc(PKT_HEADER_SIZE+len);
 
@@ -60,7 +61,7 @@
     set_header(courseid, packet, PKT_COURSEID_OFFSET);
 
     if (data)
-      //	memcpy(packet+PKT_DATA_OFFSET, data, len);
+      	memcpy(packet+PKT_DATA_OFFSET, data, len);
 
     return packet;
 }
@@ -74,10 +75,10 @@
     char *reply;
     int len = PKT_HEADER_SIZE;
 
-    //    if (data) len += sizeof(FMATRIX);
+    if (data) len += sizeof(FMATRIX);
 
-    //reply = psx_reply(linda_seq[dest])
-    /*
+    reply = psx_reply(linda_seq[dest]);
+    
     if (linda_seq[dest] == 0) {
 	pkt = make_packet(mode, car, course, data);
 	psx_out(dest, pkt, len);
@@ -88,9 +89,9 @@
 	free(pkt);
 	psx_free(reply);
 	}
-    */
+    
     pkt = make_packet(mode, car, course, data);
-    psx_out(dest, pkt, len);
+    //psx_out(dest, pkt, len);
     free(pkt);
 }
 
@@ -108,8 +109,7 @@
 	if (mode)   *mode   = get_header(pkt, PKT_MODE_OFFSET);
 	if (car)    *car    = get_header(pkt, PKT_CARID_OFFSET);
 	if (course) *course = get_header(pkt, PKT_COURSEID_OFFSET);
-	if (data)
-	  //	    memcpy(data, pkt+PKT_DATA_OFFSET, sizeof(FMATRIX));
+	if (data)   memcpy(data, pkt+PKT_DATA_OFFSET, sizeof(FMATRIX));
 	psx_free(reply);
 	linda_seq[id] = psx_rd(id);
     }    
@@ -458,28 +458,28 @@
     int i, flg, mode;
     int id = game->play_id;
     int connect = 1;
-    //    FMATRIX po;
+    FMATRIX po;
     CarPtr mycar = game->jiki;
     CarPtr enemy = NULL;
 
     for (i=1; i<=CLIENT_MAX; i++) {
-      //	ps2_vu0_unit_matrix(po);
-      //	get_packet(i, &flg, &mode, NULL, NULL, (char*)po);
+      	ps2_vu0_unit_matrix(po);
+      	get_packet(i, &flg, &mode, NULL, NULL, (char*)po);
 
 	if (i == id) {
-	  //	    ps2_vu0_copy_matrix(po, mycar->body->transfer);
-	  //	    ps2_vu0_copy_vector(po[3], mycar->location);
+	    ps2_vu0_copy_matrix(po, mycar->body->transfer);
+	    ps2_vu0_copy_vector(po[3], mycar->location);
 	    
 	    linda_seq[i] = psx_in(i);
-	    //	    send_packet(i, MODE_MAIN, 0, 0, (char*)po);
+	    send_packet(i, MODE_MAIN, 0, 0, (char*)po);
 	} else {
 	    enemy = linda_carlist[i];
 	    if (flg == 1 && mode == MODE_MAIN) {
-	      /*		ps2_vu0_copy_matrix(enemy->body->transfer, po);
+	        ps2_vu0_copy_matrix(enemy->body->transfer, po);
 		enemy->body->transfer[3][0] -= mycar->location[0];
 		enemy->body->transfer[3][1] -= mycar->location[1];
 		enemy->body->transfer[3][2] -= mycar->location[2];
-		enemy->body->transfer[3][3] = 1;*/
+		enemy->body->transfer[3][3] = 1;
 	    }
 	}
     }
@@ -658,7 +658,7 @@
 #ifdef DEBUG
 	// どのタイミングでoutされてるか見る
 	// 必要なときだけoutしないと重いですね当然だけど
-	//fprintf(main_fp, "psx_out() jiki\n");
+	fprintf(main_fp, "psx_out() jiki\n");
 #endif
 	linda_jiki_update();
 	// 無理矢理
@@ -666,7 +666,7 @@
 	// 正しいやり方が他に有るのかな?
 	// 実行し続けてると最終的に激重になるので
 	// ここら辺に問題が有るのだろうか。
-	//	psx_free(psx_reply(psx_in(game->play_id)));
+	psx_free(psx_reply(psx_in(game->play_id)));
 	linda_seq[my_id]=psx_in(game->play_id);
 	psx_out(game->play_id, (char*)&jiki, sizeof(CarInfo));
     }
@@ -687,7 +687,7 @@
     while((reply = psx_reply(seq)) == 0) psx_sync_n();
 
     id = atoi(reply+LINDA_HEADER_SIZE);
-    //psx_free(reply);
+    psx_free(reply);
     return id;
 }