# HG changeset patch # User kazz@kazzone.st.ie.u-ryukyu.ac.jp # Date 1257618606 -32400 # Node ID 529188ae604d79955da968337926f20781de82ee # Parent 6b865e0467104bb4321b3d7f647de3cc9fd31364 change htonl to xdr_float (checked working on mac) diff -r 6b865e046710 -r 529188ae604d Renderer/Test/dynamic_create.cc --- a/Renderer/Test/dynamic_create.cc Sat Nov 07 18:07:28 2009 +0900 +++ b/Renderer/Test/dynamic_create.cc Sun Nov 08 03:30:06 2009 +0900 @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "SceneGraphRoot.h" #include "lindaapi.h" #include "dynamic_create.h" @@ -15,6 +17,8 @@ #define SERIAL_REGIST_TUPLE_NO 1 +#define RECV_DATA_SIZE sizeof(float) * 6 + /* typedef struct { caddr_t file_mmap; @@ -84,17 +88,15 @@ moon_move(SceneGraphPtr node, int screen_w, int screen_h) { // LindaServerから座標データを取得してオブジェクトに反映させる。 -// static int seq = 0; -// float *reply; - -// if (seq == 0) -// seq = psx_wait_rd(sgroot->tid, node->id * 10 + 1); unsigned char *reply = psx_reply(node->seq); if (reply != NULL) { - float *data = (float *)(reply + LINDA_HEADER_SIZE); + char *data = (char *)(reply + LINDA_HEADER_SIZE); + // XDRの準備 + XDR xdrs; + xdrmem_create(&xdrs, data, RECV_DATA_SIZE, XDR_DECODE); // ntoh_float(&data[0]); ntoh_float(&data[1]); for (int i = 0; i < 3; i++) { - node->xyz[i] = ntohl(data[i]); + xdr_float(&xdrs, &node->xyz[i]); } node->seq = psx_wait_rd(sgroot->tid, node->id * 10 + 1); } @@ -148,8 +150,7 @@ data = taple + LINDA_HEADER_SIZE; // clientのSerialIDを取得 serial_id = ntohl(*(int *)data); - printf("serial id = %d\n", serial_id); - // タプルを解放 + printf("serial id = %d\n", serial_id); // タプルを解放 //psx_del(carg->tid, SERIAL_REGIST_TUPLE_NO); // xml fileを取得する もうすでにxml fileが送信済みである事を期待 diff -r 6b865e046710 -r 529188ae604d Renderer/Test/send_linda.cc --- a/Renderer/Test/send_linda.cc Sat Nov 07 18:07:28 2009 +0900 +++ b/Renderer/Test/send_linda.cc Sun Nov 08 03:30:06 2009 +0900 @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "SceneGraphRoot.h" #include "lindaapi.h" #include "send_linda.h" @@ -15,30 +17,32 @@ #define PORT_NUM 10000 #define LISTEN_PORT 1 #define MULTI_NUM 10 -#define SEND_DATA_SIZE 24 //sizeof(float) * 6; +#define SEND_DATA_SIZE sizeof(float) * 6 + void send_position(SceneGraphPtr node) { char *data; - float send_data[6]; // 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 ++) { - send_data[i] = htonl(node->xyz[i]); - send_data[i+3] = htonl(node->angle[i]); + if ((data = (char *)psx_reply(node->seq)) == NULL) { + //float send_data[6]; // xyz[3] and angle[3] + int tapleid = node->id * 10 + 1; + int fd = *(int*)node->propertyptr; + + // XDRの準備 + XDR xdrs; + char send_data[SEND_DATA_SIZE]; + xdrmem_create(&xdrs, send_data, SEND_DATA_SIZE, XDR_ENCODE); + + for (int i = 0; i < 3; i ++) { + xdr_float(&xdrs, &node->xyz[i]); + } + for (int i = 0; i < 3; i ++) { + xdr_float(&xdrs, &node->angle[i]); + } + node->seq = psx_in(fd, tapleid); + psx_out(fd, tapleid, (unsigned char *)send_data, SEND_DATA_SIZE); + psx_free(data); } - seq = psx_in(fd, tapleid); - do { - psx_sync_n(); - data = (char *)psx_reply(seq); - } while (data == NULL); - // hton_float(&send_data[0]); hton_float(&send_data[1]); - psx_out(fd, tapleid, (unsigned char *)send_data, SEND_DATA_SIZE); - psx_sync_n(); - psx_free(data); } void @@ -69,7 +73,6 @@ /* ここでキー入力を向こうに送る */ - if (flag) { send_position(node); } @@ -140,32 +143,6 @@ psx_sync_n(); } -/* -void -mainLoop(int tid, int write_id, int fd) -{ - void *addr; - struct stat sb; - - if (fstat(fd, &sb) == -1) { - perror("fstat"); - exit(1); - } - addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (addr==NULL) { - perror("mmap"); - exit(1); - } - - printf("file size=%d\n", sb.st_size); - - psx_out(tid, write_id, addr, sb.st_size); - psx_sync_n(); - - return; -} -*/ - static char *xml; static char *linda = HOSTNAME; @@ -181,38 +158,59 @@ SceneGraphPtr sgp; SceneGraphPtr root; + // ここら辺長ったるいから、関数で分けるべきか... + + // root オブジェクト作成 root = sgroot->createSceneGraph(); + // root_moveはコントローラーの入力で動き、座標をLinda Serverにout root->set_move_collision(root_move, root_collision); - + + // XMLをメモリにmapして、オブジェクト生成 addr = file_map(xml, &size); sgp = sgroot->createSceneGraph(); sgroot->createFromXMLmemory(sgroot->tmanager, sgp, (char *)addr, size); sgp->set_move_collision(move, collision); - + + // rootに接続 root->addChild(sgp); + // Linda Serverに接続 tspace = open_linda_java(linda, PORT_NUM); + // rootにLindaのfdを持たせる root->propertyptr = sgroot->tmanager->allocate(sizeof(int)); root->property_size = sizeof(int); *(int *)root->propertyptr = tspace; + + // このclientのserial_idを取得 + serial = get_serial_id(tspace); + root->id = serial; + + // ここから先の処理は、裏で何か動かせないかを考える + // とりあえず、関数に分けようか - serial = get_serial_id(tspace); - root->id = serial; + // serial_idを十倍したところにXMLを送信 xml_id = serial * 10; - send_xml(tspace, xml_id, addr, size); + send_xml(tspace, xml_id, addr, size); // ここのpsx_sync_n()は仕方ない + // XMLの送信が終了してから、serial_idをLindaに送信する int client_id = htonl(serial); + psx_out(tspace, LISTEN_PORT, (unsigned char *)&client_id, sizeof(int)); - send_xml(tspace, LISTEN_PORT, (unsigned char *)&client_id, sizeof(int)); - + // serial_idを十倍して1足したところに座標データを送る + // 初期化のout() 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); + char pos_data[SEND_DATA_SIZE] = {0}; +// float pos_data[6]; +// for (int i = 0; i < 6; i++) { +// pos_data[i] = 0.0f; +// } + psx_out(tspace, pos_id, (unsigned char *)pos_data, SEND_DATA_SIZE); + + // 初期化のin() + // send_position()でinの終了を確認する分岐が最初にあるため + root->seq = psx_in(tspace, pos_id); + sgroot->setSceneData(root); - sgroot->setSceneData(root); return sgr; } diff -r 6b865e046710 -r 529188ae604d old/tmp/test.c --- a/old/tmp/test.c Sat Nov 07 18:07:28 2009 +0900 +++ b/old/tmp/test.c Sun Nov 08 03:30:06 2009 +0900 @@ -17,36 +17,39 @@ int main() { - XDR xdrs; + XDR xdrs1, xdrs2; double dp[6]; int size = CHUNK; - char *addr = (char*)malloc(size); + unsigned char *addr = (unsigned char*)malloc(size); int i; double d = 0.1; - xdrmem_create(&xdrs, addr, size, XDR_ENCODE); + xdrmem_create(&xdrs1, addr, size, XDR_ENCODE); - for (i = 0; i< 6; i++) { + printf("--send side--\n"); + for (i = 0; i < 6; i++) { dp[i] = d * i; - xdr_double(&xdrs, &dp[i]); + xdr_double(&xdrs1, &dp[i]); } - int pos = xdr_getpos(&xdrs); + int pos = xdr_getpos(&xdrs1); printf("xdr written %d\n",pos); + for (i = 0; i < pos; i++) { + printf("%02x", addr[i]); + } + printf("\n"); for (i = 0; i< 6; i++) dp[i] = 0.0; - xdrmem_create(&xdrs, addr, size, XDR_DECODE); + xdrmem_create(&xdrs2, addr, size, XDR_DECODE); + printf("--recieve side--\n"); for (i = 0; i< 6; i++) { - xdr_double(&xdrs, &dp[i]); - printf("%g ",dp[i]); + xdr_double(&xdrs2, &dp[i]); + printf("%g\n", dp[i]); } - printf("\n"); - - - - + free(addr); + return 0; }