Mercurial > hg > Members > kono > Cerium
changeset 549:fdd9b928c895
linda view one object (bug...)
author | kazz@kazz187.st.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 22 Oct 2009 19:03:18 +0900 |
parents | c878c27678f4 |
children | 6df27ea54d7b |
files | TaskManager/Test/test_render/Application/dynamic_create.cc TaskManager/Test/test_render/viewer.cc |
diffstat | 2 files changed, 129 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Application/dynamic_create.cc Thu Oct 22 13:53:29 2009 +0900 +++ b/TaskManager/Test/test_render/Application/dynamic_create.cc Thu Oct 22 19:03:18 2009 +0900 @@ -6,11 +6,14 @@ #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> +#include <arpa/inet.h> #include "SceneGraphRoot.h" #include "lindaapi/lindaapi.h" #define PORT 10000 +#define SERIAL_REGIST_TUPLE_NO 1 + /* typedef struct { caddr_t file_mmap; @@ -18,12 +21,63 @@ } st_mmap_t; */ +typedef struct client_ { + int id; + SceneGraphPtr sgp; + struct client_ *next; +} client_t; + typedef struct { int tid; + int sid; int read_id; SceneGraphPtr node; + TaskManager *manager; + client_t *clist; } callback_arg; + +void +client_list_init(TaskManager* manager, client_t *clist) +{ + clist->id = -1; + clist->next = clist; +} + +void +client_list_update(TaskManager *manager, client_t *clist, int id, SceneGraphPtr sgp) +{ + //client_t *c; + // for (c = clist->next; c != clist; c = c->next) { + // if (c->id == id) { + // c->sgp = sgp; + // return; + // } + // } + + // c->next = (client_t *)manager->allocate(sizeof(client_t)); + // c->next->id = id; + // c->next->sgp = sgp; + // c->next->next = clist; +} + +void +client_list_delete(TaskManager *manager, client_t *clist, int id) +{ + client_t *c, *prev; + for (c = clist->next, prev = clist; c->next != clist; c = c->next) { + if (c->id == id) { + prev->next = c->next; + return; + } + prev = clist; + } + if (c->id == id) { + prev->next = c->next; + return; + } +} + int fix_byte(int size,int fix_byte_size) { @@ -79,7 +133,7 @@ static void moon_move(SceneGraphPtr node, int screen_w, int screen_h) { - node->angle[0] += 3.0f; + //node->angle[0] += 3.0f; node->xyz[1] += 1.0f; } @@ -87,20 +141,20 @@ static void earth_move(SceneGraphPtr node, int screen_w, int screen_h) { - node->angle[1] += 1.0f; - if (node->angle[1] > 360.0f) { - node->angle[1] = 0.0f; - } + // node->angle[1] += 1.0f; + // if (node->angle[1] > 360.0f) { + // node->angle[1] = 0.0f; + // } - node->xyz[0] += node->stack_xyz[0]; - if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) { - node->stack_xyz[0] = -node->stack_xyz[0]; - } - - node->xyz[1] += node->stack_xyz[1]; - if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { - node->stack_xyz[1] = -node->stack_xyz[1]; - } + // node->xyz[0] += node->stack_xyz[0]; + // if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) { + // node->stack_xyz[0] = -node->stack_xyz[0]; + // } + + // node->xyz[1] += node->stack_xyz[1]; + // if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { + // node->stack_xyz[1] = -node->stack_xyz[1]; + // } //Pad *pad = sgroot->getController(); @@ -124,48 +178,86 @@ psx_sync_n(); } -void -create_sg(SceneGraphPtr node, unsigned char *data, int len) +SceneGraphPtr +create_sg(TaskManager *manager, SceneGraphPtr node, unsigned char *data, int len, int serial_id) { - SceneGraphPtr earth; + SceneGraphPtr earth; //sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml"); const char *objname = sgroot->createFromXMLmemory(sgroot->tmanager, (char *)data, len); earth = sgroot->createSceneGraph(objname); + earth->id = serial_id; earth->set_move_collision(moon_move, moon_collision); node->addChild(earth); - + + return earth; +} + +void +del_callback(unsigned char *data, void *arg) +{ + free(data); +} + +void +psx_del(int t, int id) +{ + psx_callback_in(t, id, del_callback, NULL); +} + +static void +callback_get_xml(unsigned char *xml_tuple, void *arg) { + int xml_len = psx_get_datalength(xml_tuple); + callback_arg *carg = (callback_arg *)arg; + unsigned char *xml_data = xml_tuple+LINDA_HEADER_SIZE; + SceneGraphPtr sgp; + // ここで create + sgp = create_sg(carg->manager, carg->node, xml_data, xml_len, carg->sid); + client_list_update(carg->manager, carg->clist, carg->sid, sgp); + + free(xml_tuple); } static void callbacker(unsigned char *tuple, void *arg) { - int len; + int serial_id, xml_id; + unsigned char *data; callback_arg *carg = (callback_arg *)arg; - - len = psx_get_datalength(tuple); + // 最初の4byteデータは使わない data = tuple+LINDA_HEADER_SIZE; - - // ここで create - create_sg(carg->node, data, len); + // clientのSerialIDを取得 + serial_id = ntohl(*(int *)data); + + // タプルを解放 + psx_del(carg->tid, SERIAL_REGIST_TUPLE_NO); + + // xml fileを取得する もうすでにxml fileが送信済みである事を期待 + // つまり、送信者がserial_idを送る前にxml fileを送信していなくてはならない + xml_id = serial_id * 10; + callback_arg *copy_arg = (callback_arg *)carg->manager->allocate(sizeof(callback_arg)); + *copy_arg = *carg; + copy_arg->sid = serial_id; + 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(tuple); + free(tuple); psx_callback_wait_rd(carg->tid, carg->read_id, callbacker, arg); } - void -linda_init(TaskManager *manager, SceneGraphPtr node) +linda_init(TaskManager *manager, client_t *clist, SceneGraphPtr node) { init_linda(); callback_arg *carg = (callback_arg *)manager->allocate(sizeof(callback_arg)); - carg->tid = open_linda_java("133.13.59.231", PORT); - carg->read_id = 10; + carg->tid = open_linda_java("localhost", PORT); + carg->read_id = SERIAL_REGIST_TUPLE_NO; carg->node = node; + carg->manager = manager; + carg->clist = clist; psx_callback_wait_rd(carg->tid, carg->read_id, callbacker, carg); } @@ -174,7 +266,10 @@ { //SceneGraphPtr earth; sgroot->tmanager = manager; + client_t *clist; + clist = (client_t *)manager->allocate(sizeof(client_t)); + client_list_init(manager, clist); #if 0 // テスト用に mmap したデータを第2引数に渡す予定でした sgroot->createFromXMLmemory(manager, "xml_file/universe.xml"); @@ -185,9 +280,10 @@ SceneGraphPtr parent; parent = sgroot->createSceneGraph(); parent->set_move_collision(earth_move, earth_collision); + parent->xyz[0] += 300; #endif - linda_init(manager, parent); + linda_init(manager, clist, parent); // SceneGraphRoot に、使用する SceneGraph を設定する // このとき、ユーザーが記述した SceneGraph の root を渡す。
--- a/TaskManager/Test/test_render/viewer.cc Thu Oct 22 13:53:29 2009 +0900 +++ b/TaskManager/Test/test_render/viewer.cc Thu Oct 22 19:03:18 2009 +0900 @@ -166,16 +166,16 @@ vacuum_init2(manager, this->width, this->height); break; case 16: - app = new Chain(); + app = new Chain(); app->init(manager, this->width, this->height); - speLoop(); + speLoop(); return; break; case 17: chain_old_init(manager, this->width, this->height); break; case 18: - dynamic_init(manager); + dynamic_init(manager); break; default: node_init(manager);