changeset 588:d5d8e1cf1899

send position test
author kazz@kazz187.st.ie.u-ryukyu.ac.jp
date Thu, 29 Oct 2009 12:34:58 +0900
parents bdeb424ce649
children c81018fbf51e
files Renderer/Test/send_linda.cc
diffstat 1 files changed, 52 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Test/send_linda.cc	Wed Oct 28 20:28:17 2009 +0900
+++ b/Renderer/Test/send_linda.cc	Thu Oct 29 12:34:58 2009 +0900
@@ -15,32 +15,63 @@
 #define PORT_NUM 10000
 #define LISTEN_PORT 1
 #define MULTI_NUM 10
+#define SEND_DATA_SIZE 24  //sizeof(float) * 6;
+void
+send_position(SceneGraphPtr node)
+{
+	char *data;
+	char send_data[SEND_DATA_SIZE]; // xyz[3] and angle[3]
+	int tapleid = node->id * 10 + 1;
+	int fd = *(int*)node->propertyptr;
+    int seq;
+	int i;
+	
+	for (i = 0; i < 3; i ++) {
+		((float *)send_data)[i] = htonl(node->xyz[i]);
+		((float *)send_data)[i+3] = htonl(node->angle[i]);
+	}
+    seq = psx_in(fd, tapleid);
+	do {
+		psx_sync_n();
+		data = (char *)psx_reply(seq);
+	} while (data == NULL);
+	psx_out(fd, tapleid, (unsigned char *)send_data, SEND_DATA_SIZE);
+	psx_sync_n();
+    psx_free(data);
+}
 
 void
 root_move(SceneGraphPtr node, int w, int h)
 {
     Pad *pad = sgroot->getController();
-
+	int flag = 0;
     if (pad->right.isHold() || pad->left.isHold()) {
 		if (pad->right.isHold()) {
 			node->xyz[0] += 5.0f;
+			flag = 1;
 		} else if (pad->left.isHold()) {
 			node->xyz[0] -= 5.0f;
+			flag = 1;
 		}
     }
     
     if (pad->down.isHold() || pad->up.isHold() ) {
 		if (pad->down.isHold()) {
 			node->xyz[1] += 5.0f;
+			flag = 1;
 		} else if (pad->up.isHold()) {
 			node->xyz[1] -= 5.0f;
+			flag = 1;
 		}
     }
 
-    /*
+	/*
       ここでキー入力を向こうに送る
 	*/
-    
+
+	if (flag) {
+		send_position(node);
+	}
 }
 
 void
@@ -160,14 +191,26 @@
     root->addChild(sgp);
 
 	tspace = open_linda_java(linda, PORT_NUM);
+	root->propertyptr = sgroot->tmanager->allocate(sizeof(int));
+	root->property_size = sizeof(int);
+	*(int *)root->propertyptr = tspace;
+	
     serial = get_serial_id(tspace);
+	root->id = serial;
     xml_id = serial * 10;
     send_xml(tspace, xml_id, addr, size);    
 
 	int client_id = htonl(serial);
 	printf("serial id = %d\n", client_id);
     send_xml(tspace, LISTEN_PORT, (unsigned char *)&client_id, sizeof(int));
-
+	
+	int pos_id = serial * 10 + 1;
+	char pos_data[SEND_DATA_SIZE];
+	for (int i = 0; i < 6; i++) {
+		((float *)pos_data)[i] = htonl(0.0f);
+	}
+	send_xml(tspace, pos_id, (unsigned char *)pos_data, SEND_DATA_SIZE);
+	
     sgroot->setSceneData(root);
     return sgr;
 }
@@ -191,11 +234,11 @@
     manager->set_TMend(TMend);
 
     for(int i=0;i<argc;i++) {
-	if (strcmp(argv[i],"-xml") == 0 && i+1<=argc) {
-	    xml = argv[i+1];
-	} else if (strcmp(argv[i],"-linda") == 0 && i+1<=argc) {
-	    linda = argv[i+1];
-	}
+		if (strcmp(argv[i],"-xml") == 0 && i+1<=argc) {
+			xml = argv[i+1];
+		} else if (strcmp(argv[i],"-linda") == 0 && i+1<=argc) {
+			linda = argv[i+1];
+		}
     }
 
     if (xml==0) {