diff Renderer/Test/aquarium.cc @ 868:58b4fb8ad77c

[aquarium]: update screen scope on linda with protobuf
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Jun 2010 16:10:28 +0900
parents c26aa4e52258
children 157f2ffeb526
line wrap: on
line diff
--- a/Renderer/Test/aquarium.cc	Tue Jun 22 12:52:25 2010 +0900
+++ b/Renderer/Test/aquarium.cc	Tue Jun 22 16:10:28 2010 +0900
@@ -3,12 +3,15 @@
 #include "SceneGraphRoot.h"
 #include "lindaapi.h"
 #include "aquarium.h"
+#include "aquarium.pb.h"
 
 #define GET_SERIAL_ID 65535
 
 linda_t aquarium::linda_addr = { "localhost", 10000 };
 int aquarium::linda;
 int aquarium::serial_id;
+int aquarium::width;
+int aquarium::start_x;
 
 const char *usr_help_str = "Usage: ./aquarium -linda LINDA_SERVER_NAME\n";
 void TMend(TaskManager *manager);
@@ -20,16 +23,12 @@
     return new aquarium();
 }
 
-void init_network() {
-	aquarium::linda_connect();
-	
-	
-}
-
 MainLoopPtr
 aquarium::init(Viewer *sgroot, int screen_w, int screen_h)
 {
-	init_network();
+	width = screen_w;
+	linda_connect();
+	update_screen_scope();
 	return sgroot;
 }
 
@@ -45,9 +44,31 @@
 		data = psx_reply(seq);
 	} while (data == NULL);
 	serial_id = atoi((char *)data + LINDA_HEADER_SIZE);
+	psx_free(data);
 	printf("Get serial_id: %d\n", serial_id);
 }
 
+void
+aquarium::update_screen_scope() {
+	int seq = psx_in(linda, 1);
+	unsigned char *data = NULL;
+	do {
+		psx_sync_n();
+		data = psx_reply(seq);
+	} while (data == NULL);
+	aqua::Width *w = new aqua::Width();
+	w->ParseFromArray(data + LINDA_HEADER_SIZE, *(int *)(data + LINDA_DATA_LENGTH_OFFSET));
+	start_x = w->width(); // 現在の全長を取得
+	w->set_width(start_x + width); // 自分の横幅を足す
+	int size = w->ByteSize();
+	unsigned char *msg = (unsigned char *) malloc(sizeof(char) * size);
+	w->SerializeToArray(msg, size); // 更新したデータを再度シリアライズ
+	psx_out(linda, 1, msg, size);
+	psx_sync_n();
+	printf("start_x = %d, width = %d\n", start_x, width);
+	delete w;
+}
+
 int
 TMmain(TaskManager *manager, int argc, char *argv[])
 {