Mercurial > hg > Members > kono > Cerium
changeset 552:a307e33178e7
add Application/send_linda.cc
author | aaa |
---|---|
date | Thu, 22 Oct 2009 19:34:38 +0900 |
parents | c878c27678f4 |
children | ac9fb0d5a997 |
files | TaskManager/Test/test_render/Application/dynamic_create.cc TaskManager/Test/test_render/Application/send_linda.cc TaskManager/Test/test_render/SceneGraphRoot.cc TaskManager/Test/test_render/viewer.cc |
diffstat | 4 files changed, 157 insertions(+), 8 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:34:38 2009 +0900 @@ -163,7 +163,8 @@ { init_linda(); callback_arg *carg = (callback_arg *)manager->allocate(sizeof(callback_arg)); - carg->tid = open_linda_java("133.13.59.231", PORT); + //carg->tid = open_linda_java("133.13.59.231", PORT); + carg->tid = open_linda_java("localhost", PORT); carg->read_id = 10; carg->node = node; psx_callback_wait_rd(carg->tid, carg->read_id, callbacker, carg);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/Application/send_linda.cc Thu Oct 22 19:34:38 2009 +0900 @@ -0,0 +1,142 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <unistd.h> +#include <arpa/inet.h> +#include "SceneGraphRoot.h" +#include "lindaapi/lindaapi.h" + +#define HOSTNAME "localhost" +#define PORT_NUM 10000 +#define LISTEN_PORT 1 +#define MULTI_NUM 10 + +void +root_move(SceneGraphPtr node, int w, int h) +{ + Pad *pad = sgroot->getController(); + + if (pad->right.isHold() || pad->left.isHold()) { + if (pad->right.isHold()) { + node->xyz[0] += 5.0f; + } else if (pad->left.isHold()) { + node->xyz[0] -= 5.0f; + } + } + + if (pad->down.isHold() || pad->up.isHold() ) { + if (pad->down.isHold()) { + node->xyz[1] += 5.0f; + } else if (pad->up.isHold()) { + node->xyz[1] -= 5.0f; + } + } + + /* + ここでキー入力を向こうに送る + */ + +} + +void +root_collision(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) +{ +} + +void +move(SceneGraphPtr node, int w, int h) +{ +} + +void +collision(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) +{ +} + +void * +file_map(const char *filename, int *size) { + int fd; + void *addr; + struct stat sb; + + if ((fd = open(filename, O_RDONLY)) == -1) { + fprintf(stderr, "Can't open %s\n", filename); + perror(NULL); + } + if (fstat(fd, &sb) == -1) { + fprintf(stderr, "Can't fstat %s\n", filename); + perror(NULL); + } + *size = sb.st_size; + addr = mmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0); + if (addr == MAP_FAILED) { + perror("mmap error\n"); + exit(EXIT_FAILURE); + } + close(fd); + + return addr; +} + + +void +linda_init(char *addr, int *size) +{ + +} + +int get_serial_id(int fd) { + char *data; + int serial; + int seq; + + seq = psx_in(fd, 65535); + psx_sync_n(); + data = (char *)psx_reply(seq); + serial = atoi(data + LINDA_HEADER_SIZE); + psx_free(data); + + return serial; +} + + +void +send_xml(int fd, int id, void *addr, int size) { + psx_out(fd, id, (unsigned char *)addr, size); + psx_sync_n(); +} + +void +send_linda_init(TaskManager *manager, const char *xml) +{ + void *addr; + int size; + int fd; + int tuple_id; + + SceneGraphPtr sgp; + SceneGraphPtr root; + root = sgroot->createSceneGraph(); + root->set_move_collision(root_move, root_collision); + + // createFromXMLfile で object name のリストを生成するべき + sgroot->createFromXMLfile(manager, xml); + // 今だけは決め打ち、本当はリストを回して object 数 create したい + sgp = sgroot->createSceneGraph("Ball"); + sgp->set_move_collision(move, collision); + + root->addChild(sgp); + sgroot->setSceneData(root); + + addr = file_map(xml, &size); + fd = open_linda_java(HOSTNAME, PORT_NUM); + tuple_id = get_serial_id(fd); + send_xml(fd, tuple_id*MULTI_NUM, addr, size); + + int client_id = htonl(tuple_id); + send_xml(fd, LISTEN_PORT, (void *)client_id, sizeof(int)); +}
--- a/TaskManager/Test/test_render/SceneGraphRoot.cc Thu Oct 22 13:53:29 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraphRoot.cc Thu Oct 22 19:34:38 2009 +0900 @@ -117,14 +117,16 @@ /* XMLのノードを一つずつ解析 */ for (cur=cur->children; cur; cur=cur->next) { /* 扱うのはsurfaceオンリー */ - if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) { - continue; - } + if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) { + continue; + } + + /* ポリゴン(SceneGraph)生成 */ + tmp = new SceneGraph(manager, cur); + + addSceneGraphList(manager, tmp); - /* ポリゴン(SceneGraph)生成 */ - tmp = new SceneGraph(manager, cur); - - registSceneGraph(tmp); + registSceneGraphList(tmp); } xmlFreeDoc(doc);
--- 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:34:38 2009 +0900 @@ -108,6 +108,7 @@ extern void init_gaplant(TaskManager *manager, int w, int h); extern void vacuum_init2(TaskManager *manager, int w, int h); extern void dynamic_init(TaskManager *manager); +extern void send_linda_init(TaskManager *manager, const char *xml); void Viewer::run_init(TaskManager *manager, const char *xml, int sg_number) @@ -177,6 +178,9 @@ case 18: dynamic_init(manager); break; + case 19: + send_linda_init(manager, xml); + break; default: node_init(manager); break;