Mercurial > hg > Game > Cerium
changeset 841:8d702fc5d77a draft
dynamic loading demo bug fix
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 02 Jun 2010 01:39:15 +0900 |
parents | 1ba88b4cfe44 |
children | 8accca9e168e |
files | Renderer/Engine/SceneGraph.h Renderer/Engine/lindaapi.cc Renderer/Engine/lindaapi.h Renderer/Engine/viewer.cc Renderer/Test/dynamic_create.cc Renderer/Test/send_linda.cc Renderer/Test/writer.c |
diffstat | 7 files changed, 132 insertions(+), 107 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraph.h Tue May 25 19:14:44 2010 +0900 +++ b/Renderer/Engine/SceneGraph.h Wed Jun 02 01:39:15 2010 +0900 @@ -32,7 +32,7 @@ int id; // Objectのシーケンス番号(Linda) // とりあえず動かしたいので追加 - int seq; + int seq, seq_rd, resend_flag; int property_size; void *propertyptr;
--- a/Renderer/Engine/lindaapi.cc Tue May 25 19:14:44 2010 +0900 +++ b/Renderer/Engine/lindaapi.cc Wed Jun 02 01:39:15 2010 +0900 @@ -11,12 +11,13 @@ #include <unistd.h> #include <netinet/in.h> #include <sys/select.h> -#include <sys/types.h> -#include <sys/socket.h> #include <netdb.h> #include <netinet/tcp.h> #include <sys/un.h> #include <errno.h> + +#include <sys/types.h> +#include <sys/socket.h> #include <arpa/inet.h> #include "lindaapi.h" @@ -37,12 +38,12 @@ static REPLY *reply, *r_end; /* 受け取り用キュー */ static int qsize; /* コマンドキューのサイズ */ static fd_set g_fds; /* 接続しているタプルスペース群のFD(FileDiscripter)を保持 */ -static int g_max_fds = 0; /* 監視するFDの最大値 */ +static int g_max_fds; /* 監視するFDの最大値 */ /* Static Functions */ static void unix_chkserv(int ps); void psx_free(void *); -static long psx_queue(unsigned int tspace_id, unsigned int id, +static int psx_queue(unsigned int tspace_id, unsigned int id, unsigned int size, unsigned char *data, char mode, void(*callback)(unsigned char *,void *),void * obj); @@ -96,6 +97,31 @@ #define unix_read_w read +#if 0 +/*-------------------------------------------------------------------/ + static int + unix_write (int fd, unsigned char *buf, unsigned int size): + サーバへTUPLEを送る。 + + 引き数: + fd - サーバのファイルディスクリプタ + buf - サーバへ送るデータ(TUPLEヘッダ含む) + size - bufのbyte数 + 返り値: + 送った(書きこんだ)データのbyte数 +/-------------------------------------------------------------------*/ +static int +unix_write_bak(int fd,unsigned char *buf,unsigned int size) { + int i,nsize; + nsize = htonl(size); + i = write(fd,&nsize,INT_SIZE); + i += write(fd,buf,size); // size == datasize + LINDA_HEADER_SIZE +#ifdef COUNT_PACKET + count_packet('s'); +#endif + return(i); +} +#endif static int unix_write(int fd,unsigned char *buf,unsigned int size) { @@ -108,7 +134,7 @@ /* 目的のデータを送信 */ while (count < size) { - count += write(fd, buf+count, size-count); + count += write(fd, buf+count, size-count); } #ifdef COUNT_PACKET count_packet('s'); @@ -141,6 +167,27 @@ */ } +struct addrinfo *gethostaddrinfo(const char *host, int port) { + struct addrinfo hints; + hints.ai_protocol = 0; + hints.ai_addrlen = 0; + hints.ai_addr = NULL; + hints.ai_canonname = NULL; + hints.ai_next = NULL; + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE; + struct addrinfo *res0; + char portbuf[6]; + sprintf(portbuf, "%d", port); + int error = getaddrinfo(host, portbuf, &hints, &res0); + if (error) { + fprintf(stderr, "error: getaddrinfo (%d)\n", error); + } + return res0; +} + + /*-------------------------------------------------------------------/ int @@ -156,7 +203,7 @@ 失敗すると -1 を返す。 /-------------------------------------------------------------------*/ int -open_linda(const char * hostname, int port){ +open_linda(char * hostname, int port){ int fd; struct hostent *hoste; struct sockaddr_in serv_addr; @@ -213,7 +260,7 @@ } int -open_linda_java(const char * hostname, int port){ +open_linda_java(char * hostname, int port){ int fd; struct hostent *hoste; struct sockaddr_in serv_addr; @@ -314,10 +361,10 @@ 返り値: シーケンス番号 /-------------------------------------------------------------------*/ -long +int psx_out(unsigned int tspace_id, unsigned int id, unsigned char *data, unsigned int size){ - long r; + int r; if ((r = psx_queue(tspace_id, id, size, data, 'o', NULL, NULL)) == FAIL) { return(FAIL); } @@ -343,10 +390,10 @@ 返り値: psx_queue内でmallocされたREPLY構造体へのポインタ /-------------------------------------------------------------------*/ -long +int psx_ld(unsigned int tspace_id, unsigned int id, char mode, void(*callback)(unsigned char *,void *), void * obj){ - long r; + int r; if ((r = psx_queue(tspace_id, id, 0, NULL, mode, callback, obj)) == FAIL) { return(FAIL); } @@ -414,18 +461,21 @@ 送信し、サーバから送られて来たデータを対応するREPLYへいれる。 /-------------------------------------------------------------------*/ #define TIMEDELTA 10 + void -psx_sync_n(){ +psx_sync_n() { + psx_sync_n_timeout(TIMEDELTA); +} + +void +psx_sync_n_timeout(int time) { int acount; - int i; COMMAND *c, *t; - if (g_max_fds==0) return; - fd_set tmp; struct timeval timeout; timeout.tv_sec=0; - timeout.tv_usec=TIMEDELTA * 1000; + timeout.tv_usec=time * 1000; acount = 0; while (q_top != NULL){ @@ -439,8 +489,9 @@ } tmp = g_fds; - while(select(g_max_fds+1, &tmp, NULL, NULL, &timeout) > 0) { - for (i = 0; i < g_max_fds+1; i++) { + while(select((unsigned int)g_max_fds+1, &tmp, NULL, NULL, &timeout) > 0) { + unsigned int i; + for (i = 0; i < (unsigned int)g_max_fds+1; i++) { if (FD_ISSET(i, &tmp)) { unix_chkserv(i); } @@ -471,7 +522,7 @@ 0が返る。 失敗した場合 - FAIL(-1)が返る。 /-------------------------------------------------------------------*/ -static long +static int psx_queue(unsigned int tspace_id, unsigned int id, unsigned int size, unsigned char *data, char mode, void(*callback)(unsigned char *,void *), void * obj){ @@ -517,7 +568,7 @@ p = r_end->next; r_end = p; p->next = NULL; } p->mode = '?'; - p->seq = (long)p; // 構造体のアドレスで識別 + p->seq = (int)p; // 構造体のアドレスで識別 p->callback = callback; p->obj = obj; PSX_Debug(("psx_queue: seq %d reply %x p %x r_end %x",seq,reply,p,r_end)); @@ -529,10 +580,10 @@ q_end->command[LINDA_ID_OFFSET] = id >> 8; q_end->command[LINDA_ID_OFFSET+1] = id & 0xff; - q_end->command[LINDA_SEQ_OFFSET] = ((long)p>>24) & 0xff; - q_end->command[LINDA_SEQ_OFFSET+1] = ((long)p>>16) & 0xff; - q_end->command[LINDA_SEQ_OFFSET+2] = ((long)p>>8) & 0xff; - q_end->command[LINDA_SEQ_OFFSET+3] = ((long)p) & 0xff; + q_end->command[LINDA_SEQ_OFFSET] = ((int)p>>24) & 0xff; + q_end->command[LINDA_SEQ_OFFSET+1] = ((int)p>>16) & 0xff; + q_end->command[LINDA_SEQ_OFFSET+2] = ((int)p>>8) & 0xff; + q_end->command[LINDA_SEQ_OFFSET+3] = ((int)p) & 0xff; q_end->command[LINDA_DATA_LENGTH_OFFSET] = (size>>24) & 0xff; q_end->command[LINDA_DATA_LENGTH_OFFSET+1] = (size>>16) & 0xff; @@ -545,7 +596,7 @@ qsize++; if (data && size>0) memcpy(q_end->command+LINDA_HEADER_SIZE, data, size); - return((long)p); + return((int)p); } /*-------------------------------------------------------------------/ @@ -561,7 +612,6 @@ static void unix_chkserv(int ps){ int i,pkt,npkt,mode; - unsigned int k; REPLY *r,*prev; int a; unsigned char * tuple = 0; @@ -590,7 +640,7 @@ #endif mode = psx_get_mode(tuple); i = psx_get_id(tuple); - k = psx_get_seq(tuple); + unsigned int k = psx_get_seq(tuple); PSX_Debug(("psx_chkserv: anser packet size = %d id %d seq %d", pkt,i,k)); DEB(fprintf(stdout, "psx_chkserv: data from server: %s id=%d seq = %d\n", tuple, i, k)); DEB (
--- a/Renderer/Engine/lindaapi.h Tue May 25 19:14:44 2010 +0900 +++ b/Renderer/Engine/lindaapi.h Wed Jun 02 01:39:15 2010 +0900 @@ -1,13 +1,3 @@ -#ifndef _LINDAAPI_H - -#define _LINDAAPI_H 1 - -#include "types.h" - -#ifdef __cplusplus -extern "C" { -#endif - /* $Id$ */ /*---------------------------------------------------------------------- @@ -62,24 +52,24 @@ ----------------------------------------------------------------------*/ extern void init_linda(void); -extern int open_linda(const char *hostname, int port); -extern int open_linda_java(const char *hostname, int port); +extern int open_linda(char *hostname, int port); +extern int open_linda_java(char *hostname, int port); extern int close_linda(int tspace_id); extern void psx_free(void*); extern unsigned char *psx_reply(unsigned int seq); extern void psx_sync_n(void); +extern void psx_sync_n_timeout(int time); extern unsigned int psx_get_datalength(unsigned char *); -extern unsigned char *psx_get_data(unsigned char *); extern unsigned int psx_get_seq(unsigned char *); extern unsigned short psx_get_id(unsigned char *); extern unsigned char psx_get_mode(unsigned char *); extern unsigned char * psx_get_data(unsigned char *); -extern long psx_out(unsigned int tspace_id, unsigned int id, +extern int psx_out(unsigned int tspace_id, unsigned int id, unsigned char *data, unsigned int size); -extern long psx_ld(unsigned int tspace_id, unsigned int id, +extern int psx_ld(unsigned int tspace_id, unsigned int id, char mode, void(*callback)(unsigned char *,void *),void * obj); #define psx_in(tid, id) psx_ld(tid, id, 'i', NULL, NULL) @@ -92,9 +82,3 @@ #define psx_callback_ck(tid, id,callback,obj) psx_ld(tid, id, 'c', callback, obj) #define psx_callback_wait_rd(tid, id,callback,obj) psx_ld(tid, id, 'w', callback, obj) - - -#ifdef __cplusplus -}; // for extern "C" -#endif -#endif // _LINDAAPI_H
--- a/Renderer/Engine/viewer.cc Tue May 25 19:14:44 2010 +0900 +++ b/Renderer/Engine/viewer.cc Wed Jun 02 01:39:15 2010 +0900 @@ -372,7 +372,6 @@ Viewer *viewer = (Viewer*)viewer_; HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); viewer->run_loop(task_next); - psx_sync_n(); }
--- a/Renderer/Test/dynamic_create.cc Tue May 25 19:14:44 2010 +0900 +++ b/Renderer/Test/dynamic_create.cc Wed Jun 02 01:39:15 2010 +0900 @@ -19,13 +19,6 @@ #define RECV_DATA_SIZE sizeof(float) * 6 -/* - typedef struct { - caddr_t file_mmap; - off_t size; - } st_mmap_t; -*/ - typedef struct client_ { int id; SceneGraphPtr sgp; @@ -86,25 +79,29 @@ } static void +set_position(SceneGraphPtr node, unsigned char *reply) { + char *data = (char *)(reply + LINDA_HEADER_SIZE); + // XDRの準備 + XDR xdrs; + xdrmem_create(&xdrs, data, RECV_DATA_SIZE, XDR_DECODE); + for (int i = 0; i < 3; i++) { + xdr_float(&xdrs, &node->xyz[i]); + } +} + +static void moon_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) { SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; // LindaServerから座標データを取得してオブジェクトに反映させる。 - unsigned char *reply = psx_reply(node->seq); - if (reply != NULL) { - 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++) { - xdr_float(&xdrs, &node->xyz[i]); - } - node->seq = psx_wait_rd(sgroot->tid, node->id * 10 + 1); + unsigned char *reply_rd = psx_reply(node->seq_rd); + if (reply_rd != NULL) { + set_position(node, reply_rd); + free(reply_rd); + node->seq_rd = psx_wait_rd(sgroot->tid, node->id * 10 + 1); } } - static void earth_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) { @@ -121,7 +118,7 @@ sgroot->createFromXMLmemory(sgroot->tmanager, child, (char *)data, len); child->set_move_collision(moon_move, moon_collision); child->id = serial_id; - child->seq = psx_wait_rd(sgroot->tid, serial_id * 10 + 1); + child->seq_rd = psx_wait_rd(sgroot->tid, serial_id * 10 + 1); return child; } @@ -134,7 +131,6 @@ unsigned char *xml_data = xml_tuple + LINDA_HEADER_SIZE; SceneGraphPtr sgp; // ここで create - // fwrite(xml_data, 1, 10, stdout); sgp = create_sg(carg->manager, carg->sgroot, carg->node, xml_data, xml_len, carg->sid); printf("%s size %d loaded\n", sgp->children->name, xml_len); client_list_update(carg->manager, carg->clist, carg->sid, sgp); @@ -154,7 +150,6 @@ // clientのSerialIDを取得 serial_id = ntohl(*(int *)data); printf("serial id = %d\n", serial_id); // タプルを解放 - //psx_del(carg->tid, SERIAL_REGIST_TUPLE_NO); // xml fileを取得する もうすでにxml fileが送信済みである事を期待 // つまり、送信者がserial_idを送る前にxml fileを送信していなくてはならない @@ -165,15 +160,13 @@ psx_callback_in(carg->tid, xml_id, callback_get_xml, (void *)copy_arg); /* dataは'\0'で終わっている事を期待 (writerで保証する) */ - //printf("get data[%d]: `%s'\n", len, data); free(taple); // arg は使い回すらしい。 - psx_callback_in(carg->tid, carg->read_id, callbacker, arg); } -static char const *linda = "localhost"; +static char *linda = (char *)"localhost"; static void linda_init(TaskManager *manager, SceneGraphRoot *sgroot, client_t *clist, SceneGraphPtr node) @@ -194,7 +187,6 @@ MainLoopPtr dynamic_create::init(Viewer *sgroot, int screen_w, int screen_h) { - //SceneGraphPtr earth; client_t *clist; clist = (client_t *)sgroot->manager->allocate(sizeof(client_t)); @@ -203,8 +195,6 @@ SceneGraphPtr parent; parent = sgroot->createSceneGraph(); parent->set_move_collision(earth_move, earth_collision); -// parent->xyz[0] += 300; -// parent->xyz[1] += 300; linda_init(sgroot->manager, sgroot->sgroot, clist, parent); // SceneGraphRoot に、使用する SceneGraph を設定する @@ -246,4 +236,3 @@ } /* end */ -
--- a/Renderer/Test/send_linda.cc Tue May 25 19:14:44 2010 +0900 +++ b/Renderer/Test/send_linda.cc Wed Jun 02 01:39:15 2010 +0900 @@ -23,26 +23,32 @@ send_position(SceneGraphPtr node) { char *data; - 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; + if (node->seq == 0) { + } else if ((data = (char *)psx_reply(node->seq)) == NULL) { + psx_free(data); + } else { + node->resend_flag = 1; + return; + } + node->resend_flag = 0; + + //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); + // 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); + 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); } void @@ -74,7 +80,7 @@ /* ここでキー入力を向こうに送る */ - if (flag) { + if (flag || node->resend_flag) { send_position(node); } } @@ -145,7 +151,7 @@ } static char *xml; -static const char *linda = HOSTNAME; +static char *linda = HOSTNAME; MainLoopPtr send_linda::init(Viewer *sgr, int screen_w, int screen_h) @@ -200,15 +206,12 @@ // 初期化のout() int pos_id = serial * 10 + 1; char pos_data[SEND_DATA_SIZE] = {0}; -// float pos_data[6]; -// for (int i = 0; i < 6; i++) { -// pos_data[i] = 0.0f; -// } + + // init seq + // send_position()でinの終了を確認する分岐が最初にあるため psx_out(tspace, pos_id, (unsigned char *)pos_data, SEND_DATA_SIZE); - - // 初期化のin() - // send_position()でinの終了を確認する分岐が最初にあるため - root->seq = psx_in(tspace, pos_id); + root->seq = 0; + root->resend_flag = 0; sgr->setSceneData(root); return sgr;
--- a/Renderer/Test/writer.c Tue May 25 19:14:44 2010 +0900 +++ b/Renderer/Test/writer.c Wed Jun 02 01:39:15 2010 +0900 @@ -64,7 +64,7 @@ int tspace; int serial; int xml_id; - const char *linda_serv = "localhost"; + char *linda_serv = (char *)"localhost"; if (argc > 1) linda_serv = argv[1]; init_linda();