Mercurial > hg > Game > Cerium
view TaskManager/Test/test_render/Application/send_linda.cc @ 533:bf9c44b21d67 draft
add Application/send_linda.cc
author | aaa |
---|---|
date | Thu, 22 Oct 2009 19:34:38 +0900 |
parents | |
children | b4e47b4eb6b8 |
line wrap: on
line source
#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)); }