Mercurial > hg > Members > kono > Cerium
changeset 769:2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
author | hiroki@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Sun, 14 Feb 2010 01:23:38 +0900 |
parents | 719573b2e569 |
children | aed3d2501c38 |
files | Renderer/Engine/RenderingTasks.h Renderer/Engine/SceneGraph.h Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/spe/Makefile Renderer/Engine/spe/chain_move.cc Renderer/Engine/spe/spe-main.cc Renderer/Engine/spe/univers_move.cc Renderer/Engine/spe/univers_move.h Renderer/Engine/spe/universe_move.cc Renderer/Engine/spe/universe_move.h Renderer/Test/Makefile.cell Renderer/Test/create_task.cc Renderer/Test/property_chain.cc Renderer/Test/property_universe.cc Renderer/Test/property_universe.h Renderer/Test/universe.cc |
diffstat | 16 files changed, 386 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/RenderingTasks.h Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Engine/RenderingTasks.h Sun Feb 14 01:23:38 2010 +0900 @@ -33,6 +33,7 @@ ChainCal, ChainInit, PropertyTask, + UniverseTask, RUN_FINISH,
--- a/Renderer/Engine/SceneGraph.h Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Engine/SceneGraph.h Sun Feb 14 01:23:38 2010 +0900 @@ -37,8 +37,10 @@ int property_size; void *propertyptr; //void *property; + //void *update_property; memaddr property; - void *update_property; + memaddr update_property; + // xml ファイルから生成した時のオブジェクトリスト SceneGraphPtr next;
--- a/Renderer/Engine/SceneGraphRoot.cc Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Sun Feb 14 01:23:38 2010 +0900 @@ -533,6 +533,8 @@ light_vector[i*4] /= light_vector[i*4+2]; light_vector[i*4+1] /= light_vector[i*4+2]; + light_vector[i*4+2] *= -1; + light_vector[i*4+3] *= -1; } //sgchange->viewer->light_xyz_stock = getLightVector();
--- a/Renderer/Engine/spe/Makefile Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Engine/spe/Makefile Sun Feb 14 01:23:38 2010 +0900 @@ -10,7 +10,7 @@ OBJS = $(SRCS:.cc=.o) CC = spu-g++ -CFLAGS = -Wall -fno-exceptions -fno-rtti $(OPT)#-DDEBUG +CFLAGS = -Wall -fno-exceptions -fno-rtti $(OPT)#-DDEBUG INCLUDE = -I$(TOP)/include/TaskManager -I. -I.. LIBS = -L$(TOP)/TaskManager -lspemanager
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/spe/chain_move.cc Sun Feb 14 01:23:38 2010 +0900 @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <string.h> +#include <math.h> +#include "chain_move.h" +#include "Func.h" +#include "types.h" + +/* これは必須 */ +SchedDefineTask(ChainTask); + +static const int PROPERTY_LENGTH = 51; + +typedef struct { + float xyz[3]; + float angle[3]; + float stack_xyz[3]; + float next_xyz[3]; + float v_xyz[3]; + int property_index; + int parent_index; + int have_parent; + int can_move; + memaddr parent; + memaddr children; + memaddr node; + const char *name; +} *PropertyPtr, Property; + +static int +run(SchedTask *s,void *rbuf, void *wbuf) +{ + PropertyPtr property = (PropertyPtr)s->get_input(rbuf, 0); + PropertyPtr update_property = (PropertyPtr)s->get_output(wbuf, 0); + + int id = 0; + + memcpy((void*)update_property, (void*)property, sizeof(Property)*PROPERTY_LENGTH); + + return 0; +}
--- a/Renderer/Engine/spe/spe-main.cc Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Engine/spe/spe-main.cc Sun Feb 14 01:23:38 2010 +0900 @@ -22,7 +22,7 @@ SchedExternTask(UpdateKey); SchedExternTask(PropertyTask); -SchedExternTask(UniversTask); +SchedExternTask(UniverseTask); void task_init(Scheduler *s) @@ -47,5 +47,5 @@ SchedRegister( UpdateKey); SchedRegister( PropertyTask); - SchedRegister( UniversTask); + SchedRegister( UniverseTask); }
--- a/Renderer/Engine/spe/univers_move.cc Sat Feb 13 17:34:26 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <math.h> -#include "universe_move.h" -#include "Func.h" -#include "types.h" - -/* これは必須 */ -SchedDefineTask(UniversTask); - -typedef struct { - float xyz[3]; - float angle[3]; - float stack_xyz[3]; - SceneGraphPtr parent; - SceneGraphPtr children; - int property_index; - int parent_index; - SceneGraphPtr sg; - const char *name; -} *PropertyPtr, Property; - -static int -run(SchedTask *s,void *rbuf, void *wbuf) -{ - PropertyPtr property = (PropertyPtr)s->get_input(rbuf, 0); - PropertyPtr update_property = (PropertyPtr)s->get_output(wbuf, 0); - - property[0]->angle[1] += 1.0f; - if (property[0]->angle[1] > 360.0f) { - property[0]->angle[1] = 0.0f; - } - - property[0]->xyz[0] += property[0]->stack_xyz[0]; - if ((int)property[0]->xyz[0] > screen_w || (int)property[0]->xyz[0] < 0) { - property[0]->stack_xyz[0] = -property[0]->stack_xyz[0]; - } - - property[0]->xyz[1] += property[0]->stack_xyz[1]; - if ((int)property[0]->xyz[1] > screen_h || (int)property[0]->xyz[1] < 0) { - property[0]->stack_xyz[1] = -property[0]->stack_xyz[1]; - } - - memcpy((void*)update_property, (void*)property, sizeof(Property)*2); - - return 0; -}
--- a/Renderer/Engine/spe/univers_move.h Sat Feb 13 17:34:26 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#ifndef INCLUDED_TASK_UNIVERS -#define INCLUDED_TASK_UNIVERSY - -#ifndef INCLUDED_SCHED_TASK -# include "SchedTask.h" -#endif - - -#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/spe/universe_move.cc Sun Feb 14 01:23:38 2010 +0900 @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <string.h> +#include <math.h> +#include "universe_move.h" +#include "Func.h" +#include "types.h" + +/* これは必須 */ +SchedDefineTask(UniverseTask); + +typedef struct { + float xyz[3]; + float angle[3]; + float stack_xyz[3]; + int property_index; + int parent_index; + int have_parent; + memaddr parent; + memaddr children; + memaddr node; + const char *name; +} *PropertyPtr, Property; + +static int +run(SchedTask *s,void *rbuf, void *wbuf) +{ + PropertyPtr property = (PropertyPtr)s->get_input(rbuf, 0); + PropertyPtr update_property = (PropertyPtr)s->get_output(wbuf, 0); + int screen_w = 1920; + int screen_h = 1080; + + property[0].angle[1] += 1.0f; + if (property[0].angle[1] > 360.0f) { + property[0].angle[1] = 0.0f; + } + + property[0].xyz[0] += property[0].stack_xyz[0]; + if ((int)property[0].xyz[0] > screen_w || (int)property[0].xyz[0] < 0) { + property[0].stack_xyz[0] = -property[0].stack_xyz[0]; + } + + property[0].xyz[1] += property[0].stack_xyz[1]; + if ((int)property[0].xyz[1] > screen_h || (int)property[0].xyz[1] < 0) { + property[0].stack_xyz[1] = -property[0].stack_xyz[1]; + } + + memcpy((void*)update_property, (void*)property, sizeof(Property)*2); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/spe/universe_move.h Sun Feb 14 01:23:38 2010 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_UNIVERSE +#define INCLUDED_TASK_UNIVERSE + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif
--- a/Renderer/Test/Makefile.cell Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Test/Makefile.cell Sun Feb 14 01:23:38 2010 +0900 @@ -11,7 +11,7 @@ .cc.o: $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange property_test create_task +ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange property_test create_task property_universe chain_old all: $(ALL) speobject: @@ -87,6 +87,14 @@ CREATE_TASK_OBJ = create_task.o create_task : $(CREATE_TASK_OBJ) $(CC) -o $@ $? $(LIBS) + +P_UNIVERSE_OBJ = property_universe.o +property_universe : $(P_UNIVERSE_OBJ) + $(CC) -o $@ $? $(LIBS) + +CHAIN_OLD = chain_old.o +chain_old : $(CHAIN_OLD) + $(CC) -o $@ $? $(LIBS) debug: $(TARGET) sudo ppu-gdb ./$(TARGET)
--- a/Renderer/Test/create_task.cc Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Test/create_task.cc Sun Feb 14 01:23:38 2010 +0900 @@ -144,8 +144,8 @@ ball->xyz[2] = 30.0f; //SceneGraph に property を持たせておく - ball->property = (void *)property; - ball->update_property = (void *)update_property; + ball->property = (memaddr)property; + ball->update_property = (memaddr)update_property; set_property(property, ball);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Test/property_chain.cc Sun Feb 14 01:23:38 2010 +0900 @@ -0,0 +1,226 @@ +#include <math.h> +#include <stdlib.h> +#include "SceneGraphRoot.h" +#include "MainLoop.h" +#include "property_chain.h" +#include "types.h" +#include "Func.h" +#include "sys.h" +#include "SgChange.h" + +#define FALSE 0 +#define TRUE !FALSE +static const int PROPERTY_LENGTH = 51; + +typedef struct { + double x, y, next_x, next_y; + double vx, vy, next_vx, next_vy; + int can_move; +} CHAIN_VARS; + +typedef struct { + float xyz[3]; + float angle[3]; + float stack_xyz[3]; + float next_xyz[3]; + float v_xyz[3]; + int property_index; + int parent_index; + int have_parent; + int can_move; + memaddr parent; + memaddr children; + memaddr node; + const char *name; +} *PropertyPtr, Property; + + +Property *property, *update_property; + +// prototype +static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); +static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); +static void createSceneGraphFromProperty(SchedTask *s, void *sgroot, void *arg1); +static void set_property(Property *p, SceneGraphPtr sg, int index); +static void apply_property(SceneGraphPtr sg, Property *p); +static void regist_task(SceneGraphRoot *sgroot); +static void set_relation(SceneGraphPtr parent, SceneGraphPtr child); + +static void +move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) +{ + SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; + HTaskPtr property_task = sgroot->move_exec_task; + + property_task->add_inData(property, sizeof(Property)*PROPERTY_LENGTH); + property_task->add_outData(update_property, sizeof(Property)*PROPERTY_LENGTH); + property_task->set_cpu(SPE_ANY); + property_task->set_post(createSceneGraphFromProperty, (void *)sgroot, 0); + property_task->spawn(); +} + +static void +collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +static void +createSceneGraphFromProperty(SchedTask *s, void *sgroot_, void *arg1) +{ + SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; + SceneGraphPtr camera = sgroot->camera; + SceneGraphPtr p_node; + + // ここが allExecute の tree をたどって clone して行くところに相当する + Property *p; + + for (int i = 0; i < PROPERTY_LENGTH; i++) { + p = &update_property[i]; + SceneGraphPtr node = sgroot->createSceneGraph(p->name); + if (strcmp(node->name, "Earth") == 0) { + node->set_move_collision(move, collision); + } + apply_property(node, p); + } + + for (int j = 0; j < PROPERTY_LENGTH; j++) { + p = &update_property[j]; + p_node = (SceneGraphPtr)p->node; + if (p->have_parent) { + SceneGraphPtr parent = (SceneGraphPtr)update_property[p->parent_index].node; + parent->addChild(p_node); + get_matrix(p_node->matrix, p_node->angle, p_node->xyz, parent->matrix); + get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, parent->real_matrix); + } else { + get_matrix(p_node->matrix, p_node->angle, p_node->xyz, camera->matrix); + get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, camera->real_matrix); + } + } + + sgroot->setSceneData((SceneGraphPtr)update_property[0].node); + + Property *tmp = property; + property = update_property; + update_property = tmp; + + sgroot->move_finish(); +} + +static void +apply_property(SceneGraphPtr node, Property *p) +{ + for (int i = 0; i < 3; i++) { + node->xyz[i] = p->xyz[i]; + node->angle[i] = p->angle[i]; + node->stack_xyz[i] = p->stack_xyz[i]; + } + p->node = (memaddr)node; + node->property = (memaddr)p; +} + +/* + ここで必要な値をプロパティに格納 + */ +static void +set_property(Property *p, SceneGraphPtr node, int index) +{ + for (int i = 0; i < 3; i++) { + p->xyz[i] = node->xyz[i]; + p->angle[i] = node->angle[i]; + p->stack_xyz[i] = node->stack_xyz[i]; + } + p->parent = (memaddr)node->parent; + p->children = (memaddr)node->children; + p->name = node->name; + p->property_index = index; + + p->node = (memaddr)node; + node->property = (memaddr)p; +} + +static void +regist_task(SceneGraphRoot *sgroot) +{ + TaskManager *manager = sgroot->tmanager; + HTaskPtr task = manager->create_task(UniverseTask); + // sgroot->setExecTask(task); とやるべき? + sgroot->move_exec_task = task; +} + +static void +set_relation(SceneGraphPtr parent, SceneGraphPtr child) +{ + /* + child->property->parent_index = parent->property->property_index; + child->property->have_parent = 1; + */ + + Property *p = (Property *)parent->property; + Property *c = (Property *)child->property; + c->parent_index = p->property_index; + c->have_parent = 1; + +} + +MainLoopPtr +property_universe::init(Viewer *viewer, int screen_w, int screen_h) +{ + // SgChange を使うための2行 + SgChange *sgroot = new SgChange(viewer); + sgroot->run_init(); + // 上で書いた regist_task() を登録 + // sgroot->appTaskRegist(regist_task); がいいかな + sgroot->sgroot_A->appTaskRegist(regist_task); + + int root_obj_index = 0; + property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH); + update_property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH); + + SceneGraphPtr root_chain, chain; + sgroot->createFromXMLfile("xml_file/chain.xml"); + root_chain = sgroot->createSceneGraph("CHAIN"); + root_chain->xyz[0] = screen_w / 2; + root_chain->xyz[1] = screen_h / 2; + + SceneGraphPtr moon; + moon = sgroot->createSceneGraph("Moon"); + + earth->addChild(moon); + + set_property(&property[root_obj_index], earth, 0); + set_property(&property[1], moon, 1); + set_relation(earth, moon); + + sgroot->setSceneData(earth); + + return sgroot; +} + +extern Application * +application() { + return new property_universe(); +} + +const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; + +extern int init(TaskManager *manager, int argc, char *argv[]); +extern void task_initialize(); +static void TMend(TaskManager *manager); + +int +TMmain(TaskManager *manager, int argc, char *argv[]) +{ + task_initialize(); + manager->set_TMend(TMend); + return init(manager, argc, argv); + +} + +void +TMend(TaskManager *manager) +{ + printf("test_nogl end\n"); +} + +/* end */
--- a/Renderer/Test/property_universe.cc Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Test/property_universe.cc Sun Feb 14 01:23:38 2010 +0900 @@ -8,7 +8,7 @@ #include "sys.h" #include "SgChange.h" -#define PROPERTY_LENGTH 2; +static const int PROPERTY_LENGTH = 2; Property *property, *update_property; @@ -16,7 +16,7 @@ static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); static void createSceneGraphFromProperty(SchedTask *s, void *sgroot, void *arg1); -static void set_property(Property *p, SceneGraphPtr sg); +static void set_property(Property *p, SceneGraphPtr sg, int index); static void apply_property(SceneGraphPtr sg, Property *p); static void regist_task(SceneGraphRoot *sgroot); static void set_relation(SceneGraphPtr parent, SceneGraphPtr child); @@ -27,8 +27,8 @@ SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; HTaskPtr property_task = sgroot->move_exec_task; - property_task->add_inData(property, sizeof(Property)); - property_task->add_outData(update_property, sizeof(Property)); + property_task->add_inData(property, sizeof(Property)*PROPERTY_LENGTH); + property_task->add_outData(update_property, sizeof(Property)*PROPERTY_LENGTH); property_task->set_cpu(SPE_ANY); property_task->set_post(createSceneGraphFromProperty, (void *)sgroot, 0); property_task->spawn(); @@ -46,25 +46,25 @@ SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; SceneGraphPtr camera = sgroot->camera; SceneGraphPtr p_node; - int p_length = sgroot->; - + // ここが allExecute の tree をたどって clone して行くところに相当する - //Property *t = update_property; Property *p; - + for (int i = 0; i < PROPERTY_LENGTH; i++) { p = &update_property[i]; - SceneGraphPtr node = sgroot->createSceneGraph(t->name); - node->set_move_collision(t->move_func, t->collision_func); - apply_property(node, t); + SceneGraphPtr node = sgroot->createSceneGraph(p->name); + if (strcmp(node->name, "Earth") == 0) { + node->set_move_collision(move, collision); + } + apply_property(node, p); } for (int j = 0; j < PROPERTY_LENGTH; j++) { p = &update_property[j]; - p_node = p->node; - if (t->have_parent) { - SceneGraphPtr parent = update_property[t->parent_index]->node; - parent->addChilde(p_node); + p_node = (SceneGraphPtr)p->node; + if (p->have_parent) { + SceneGraphPtr parent = (SceneGraphPtr)update_property[p->parent_index].node; + parent->addChild(p_node); get_matrix(p_node->matrix, p_node->angle, p_node->xyz, parent->matrix); get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, parent->real_matrix); } else { @@ -73,7 +73,7 @@ } } - sgroot->setSceneData(update_property[0]->node); + sgroot->setSceneData((SceneGraphPtr)update_property[0].node); Property *tmp = property; property = update_property; @@ -90,7 +90,7 @@ node->angle[i] = p->angle[i]; node->stack_xyz[i] = p->stack_xyz[i]; } - p->node = node; + p->node = (memaddr)node; node->property = (memaddr)p; } @@ -105,12 +105,12 @@ p->angle[i] = node->angle[i]; p->stack_xyz[i] = node->stack_xyz[i]; } - p->parent = node->parent; - p->children = node->children; + p->parent = (memaddr)node->parent; + p->children = (memaddr)node->children; p->name = node->name; p->property_index = index; - p->node = node; + p->node = (memaddr)node; node->property = (memaddr)p; } @@ -118,7 +118,7 @@ regist_task(SceneGraphRoot *sgroot) { TaskManager *manager = sgroot->tmanager; - HTaskPtr task = manager->create_task(PropertyUniverseTask); + HTaskPtr task = manager->create_task(UniverseTask); // sgroot->setExecTask(task); とやるべき? sgroot->move_exec_task = task; } @@ -126,8 +126,16 @@ static void set_relation(SceneGraphPtr parent, SceneGraphPtr child) { + /* child->property->parent_index = parent->property->property_index; child->property->have_parent = 1; + */ + + Property *p = (Property *)parent->property; + Property *c = (Property *)child->property; + c->parent_index = p->property_index; + c->have_parent = 1; + } MainLoopPtr @@ -147,18 +155,17 @@ SceneGraphPtr earth; sgroot->createFromXMLfile("xml_file/universe.xml"); earth = sgroot->createSceneGraph("Earth"); - earth->set_move_collision(earth_move, earth_collision); + earth->set_move_collision(move, collision); earth->xyz[0] = screen_w / 2; earth->xyz[1] = screen_h / 2; SceneGraphPtr moon; moon = sgroot->createSceneGraph("Moon"); - moon->set_move_collision(moon_move, moon_collision); earth->addChild(moon); - set_property(property[root_obj_index], earth, 0); - set_property(property[1], moon, 1); + set_property(&property[root_obj_index], earth, 0); + set_property(&property[1], moon, 1); set_relation(earth, moon); sgroot->setSceneData(earth); @@ -168,7 +175,7 @@ extern Application * application() { - return new create_task(); + return new property_universe(); } const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
--- a/Renderer/Test/property_universe.h Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Test/property_universe.h Sun Feb 14 01:23:38 2010 +0900 @@ -9,12 +9,17 @@ float xyz[3]; // 12 byte float angle[3]; float stack_xyz[3]; - SceneGraphPtr parent; - SceneGraphPtr children; int property_index; int parent_index; int have_parent; + /* + SceneGraphPtr parent; + SceneGraphPtr children; SceneGraphPtr node; + */ + memaddr parent; + memaddr children; + memaddr node; const char *name; } *PropertyPtr, Property;
--- a/Renderer/Test/universe.cc Sat Feb 13 17:34:26 2010 +0900 +++ b/Renderer/Test/universe.cc Sun Feb 14 01:23:38 2010 +0900 @@ -52,7 +52,7 @@ earth = sgroot->createSceneGraph("Earth"); // SceneGraph の move と collision を設定 - earth->set_move_collision(moon_move, earth_collision); + earth->set_move_collision(earth_move, earth_collision); earth->xyz[0] = screen_w / 2; earth->xyz[1] = screen_h / 2;