Mercurial > hg > Game > Cerium
changeset 506:5d8e364027d5 draft
change Application
author | hiroki@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 12 Oct 2009 11:26:17 +0900 |
parents | afb37b9a3424 |
children | 823532f263af |
files | TaskManager/Test/test_render/Application.cc TaskManager/Test/test_render/Application.h TaskManager/Test/test_render/Application/Chain.cc TaskManager/Test/test_render/Application/Chain.h TaskManager/Test/test_render/Application/chain.cc TaskManager/Test/test_render/SceneGraphRoot.cc TaskManager/Test/test_render/SceneGraphRoot.h TaskManager/Test/test_render/viewer.cc |
diffstat | 8 files changed, 353 insertions(+), 230 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Application.cc Tue Oct 06 14:21:37 2009 +0900 +++ b/TaskManager/Test/test_render/Application.cc Mon Oct 12 11:26:17 2009 +0900 @@ -1,39 +1,43 @@ #include "Application.h" -// void -// Application::set_move_func(move_func new_move) -// { -// this->move = new_move; -// } +/* +void +Application::set_move_func(move_func new_move) +{ + this->move = new_move; +} -// void -// Application::set_move_coll(coll_func new_coll) -// { -// this->coll = new_coll; -// } +void +Application::set_move_coll(coll_func new_coll) +{ + this->coll = new_coll; +} +*/ Application::Application(){} Application::~Application(){} -// void -// Application::apply_property(PropertyPtr p, SceneGraphPtr sgptr) -// { -// sgptr->xyz[0] = p->xyz[0]; -// sgptr->xyz[1] = p->xyz[1]; -// sgptr->xyz[2] = p->xyz[2]; -// sgptr->angle[0] = p->angle[0]; -// sgptr->angle[1] = p->angle[1]; -// sgptr->angle[2] = p->angle[2]; +#if 0 +void +Application::apply_property(PropertyPtr p, SceneGraphPtr sgptr) +{ + sgptr->xyz[0] = p->xyz[0]; + sgptr->xyz[1] = p->xyz[1]; + sgptr->xyz[2] = p->xyz[2]; -// sgptr->frame++; + sgptr->angle[0] = p->angle[0]; + sgptr->angle[1] = p->angle[1]; + sgptr->angle[2] = p->angle[2]; -// } + sgptr->frame++; + +} SceneGraphPtr Application::scenegraph_factory(void *p, int size) { - //SceneGraphPtr sgptr = p->scenegraph; - //apply_property(p, sgptr); + SceneGraphPtr sgptr = p->scenegraph; + apply_property(p, sgptr); return NULL; } @@ -42,43 +46,73 @@ Application::scenegraph_connector(void *p, int size, SceneGraphPtr sg, SceneGraphPtr sg_available_list) { -// SceneGraphPtr last = sg_available_list; + SceneGraphPtr last = sg_available_list; -// if (!last) { -// sg_available_list = sg; -// } else { -// while (last->next) { -// last = last->next; -// } -// last->next = sg; -// sg->prev = last; -// } + if (!last) { + sg_available_list = sg; + } else { + while (last->next) { + last = last->next; + } + last->next = sg; + sg->prev = last; + } -// PropertyPtr p_curent = (PropertyPtr)sg->propertyPtr; -// PropertyPtr p_parent = p[p_curent->parent_id]; -// SceneGraphPtr s_parent = p_parent->scenegraph; + PropertyPtr p_curent = (PropertyPtr)sg->propertyPtr; + PropertyPtr p_parent = p[p_curent->parent_id]; + SceneGraphPtr s_parent = p_parent->scenegraph; -// /* childrenのリストの最後に加える (brother として)*/ -// if (s_parent->lastChild != NULL) { -// SceneGraphPtr last = s_parent->lastChild; -// last->brother = sg; -// } + /* childrenのリストの最後に加える (brother として)*/ + if (s_parent->lastChild != NULL) { + SceneGraphPtr last = s_parent->lastChild; + last->brother = sg; + } -// s_parent->lastChild = sg; + s_parent->lastChild = sg; -// if (s_parent->children == NULL) { -// s_parent->children = sg; -// } + if (s_parent->children == NULL) { + s_parent->children = sg; + } -// sg->parent = s_parent; + sg->parent = s_parent; return NULL; } +#endif -void Application::init(TaskManager *manager, int w, int h) { +/* +SceneGraphPtr +Application::scenegraph_factory(void *p, int size) +{ } -int Application::move_task_id() { +SceneGraphPtr +Application::scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list) +{ +} +*/ + +void +Application::apply_property(void *p, SceneGraphPtr sgptr) +{ +} + +void +Application::scenegraph_factory(void *p, int size) +{ +} + +void +Application::scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list) +{ +} + +void Application::init(TaskManager *manager, int w, int h) +{ +} + +int Application::move_task_id() +{ return move_task_id_; }
--- a/TaskManager/Test/test_render/Application.h Tue Oct 06 14:21:37 2009 +0900 +++ b/TaskManager/Test/test_render/Application.h Mon Oct 12 11:26:17 2009 +0900 @@ -13,13 +13,16 @@ void *propertyPtr; int property_size; - int move_task_id_; - + int move_task_id_; + int move_task_id(); - void set_move_func(move_func move); - void set_coll_func(coll_func coll); - SceneGraphPtr scenegraph_factory(void *p, int size); - SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list); + //void set_move_func(move_func move); + //void set_coll_func(coll_func coll); + virtual void apply_property(void *p, SceneGraphPtr sgptr); + virtual void scenegraph_factory(void *p, int size); + virtual void scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list); + //virtual SceneGraphPtr scenegraph_factory(void *p, int size); + //virtual SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list); virtual void init(TaskManager *manager, int w, int h) ; };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/Application/Chain.cc Mon Oct 12 11:26:17 2009 +0900 @@ -0,0 +1,179 @@ +#include <iostream> +#include <math.h> +#include "SceneGraphRoot.h" +#include "SceneGraph.h" +#include "SGList.h" +#include "TaskManager.h" +#include "Func.h" +#include "Chain.h" +#define FALSE 0 +#define TRUE !FALSE +#define CHAIN_LEN 50 + +static double chain_width = 10; + + +/* SceneGraph の property */ +ChainPropertyPtr properties[2]; +ChainPropertyPtr property; + + +//void createSceneGraphFromProperty(ChainPropertyPtr p) ; +void createSceneGraphFromProperty(void* p) ; + +void +Chain::init_chain_vars(ChainPropertyPtr cv) { + cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; + cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0; + cv->can_move = TRUE; +} + +void +set_vector(ChainPropertyPtr p, SceneGraphPtr sg) { + sg->xyz[0] = p->next_x; + sg->xyz[1] = p->next_y; + sg->xyz[2] = 0.0f; + sg->angle[0] = p->angle[0]; + sg->angle[1] = p->angle[1]; + sg->angle[2] = p->angle[2]; +} + +#if 0 +static void +chain_move_ope(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->circle.isHold()) { + property[CHAIN_LEN-1].can_move = FALSE; + if (pad->left.isHold()) { + property[CHAIN_LEN-1].x += -5.0; + } else if (pad->right.isHold()) { + property[CHAIN_LEN-1].x += 5.0; + } + + if (pad->up.isHold()) { + property[CHAIN_LEN-1].y += -5.0; + } else if (pad->down.isHold()) { + property[CHAIN_LEN-1].y += 5.0; + } + } else { + property[CHAIN_LEN-1].can_move = TRUE; + } +} +#endif + +void +Chain::chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h) +{ + int id = sg->id; + //ChainPropertyPtr p = (ChainPropertyPtr)sg->propertyptr; + HTaskPtr chain_cal; + ChainPropertyPtr output; + + // SceneGraph の切り替えもここでやる + if (property == properties[0]) { + property = properties[1]; + output = properties[0]; + }else{ + property = properties[0]; + output = properties[1]; + } + chain_cal = manager->create_task(CHAINCAL_TASK); + chain_cal->add_inData(property, sizeof(ChainProperty)*CHAIN_LEN); + chain_cal->add_param(id); + chain_cal->add_outData(output, sizeof(ChainProperty)*CHAIN_LEN); + chain_cal->set_post(createSceneGraphFromProperty, (void*)id); + chain_cal->spawn(); + +} + +void +Chain::chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) +{ + +} + +void +createSceneGraphFromProperty(void* p) +{ + ChainPropertyPtr chain_p = (ChainPropertyPtr)p; + SceneGraphPtr chain_copy = sgroot->createSceneGraph(CHAIN); + chain_copy->propertyptr = (void*)chain_p; + chain_copy->property_size = sizeof(ChainProperty); + set_vector(chain_p, chain_copy); + chain_p->parent->addChild(chain_copy); +} + +void +Chain::apply_property(void *p, SceneGraphPtr sgptr) +{ + ChainPropertyPtr cp = (ChainPropertyPtr)p; + + sgptr->xyz[0] = cp->xyz[0]; + sgptr->xyz[1] = cp->xyz[1]; + sgptr->xyz[2] = cp->xyz[2]; + + sgptr->angle[0] = cp->angle[0]; + sgptr->angle[1] = cp->angle[1]; + sgptr->angle[2] = cp->angle[2]; + + sgptr->frame++; +} + +void +Chain::init(TaskManager *manager, int w, int h) +{ + SceneGraphPtr root_chain, chain; + ChainPropertyPtr rcv; + ChainProperty r; + HTaskPtr chain_init; + + rcv = &r; + + sgroot->createFromXMLfile(manager, "xml_file/chain.xml"); + + /* SPE に送る property の配列の領域確保 */ + properties[0] = (ChainPropertyPtr)manager->allocate(sizeof(ChainProperty)*CHAIN_LEN); + properties[1] = (ChainPropertyPtr)manager->allocate(sizeof(ChainProperty)*CHAIN_LEN); + property = properties[0]; + + root_chain = sgroot->createSceneGraph(CHAIN); + // set_move_collision()ではだめ +// root_chain->set_move_collision(chain_move_ope, chain_collision); + init_chain_vars(rcv); + rcv->next_x = w / 2; + rcv->next_y = 0.0; + rcv->angle[0] = 0; + rcv->angle[1] = 0; + rcv->angle[2] = 0; + + set_vector(rcv, root_chain); + + for(int i = 0; i < CHAIN_LEN; i++) { + chain = sgroot->createSceneGraph(CHAIN); + property[i].id = i; + init_chain_vars(&property[i]); + property[i].x = 0; + property[i].y = chain_width * i; + set_vector(&property[i], chain); + property->angle[1] = -90 * (i % 2); + //chain->set_move_collision(chain_move, chain_collision); + chain->propertyptr = &property[i]; + chain->property_size = sizeof(ChainProperty); + root_chain->addChild(chain); + property[i].parent = root_chain; + } + property[0].can_move = FALSE; + + // property を SPU の共有領域へコピーする + chain_init = manager->create_task(CHAININIT_TASK); + chain_init->add_inData(property, sizeof(ChainProperty)*CHAIN_LEN); + chain_init->add_param(CHAIN_LEN); + chain_init->set_cpu(SPE_0); + chain_init->set_post(createSceneGraphFromProperty, (void*)property); + chain_init->spawn(); + + sgroot->setSceneData(root_chain); +} +
--- a/TaskManager/Test/test_render/Application/Chain.h Tue Oct 06 14:21:37 2009 +0900 +++ b/TaskManager/Test/test_render/Application/Chain.h Mon Oct 12 11:26:17 2009 +0900 @@ -1,8 +1,9 @@ -#include "Application.h" +#include "../Application.h" typedef struct { double x, y, next_x, next_y; double vx, vy, next_vx, next_vy; + double xyz[3]; double angle[3]; int can_move; SceneGraphPtr parent; @@ -14,10 +15,15 @@ class Chain : public Application { public: Chain(){} + + //SceneGraphPtr scenegraph_factory(void *p, int size); + //SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list); + // Application virtual func + void scenegraph_factory(void *p, int size) {}; + void scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list) {}; + void apply_property(void *p, SceneGraphPtr sgptr); - SceneGraphPtr scenegraph_factory(void *p, int size); - SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list); - void init(TaskManager *manager, int w, int h); + void init(TaskManager *manager, int w, int h); void init_chain_vars(ChainPropertyPtr cv); void chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h); void chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg);
--- a/TaskManager/Test/test_render/Application/chain.cc Tue Oct 06 14:21:37 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,163 +0,0 @@ -#include <iostream> -#include <math.h> -#include "SceneGraphRoot.h" -#include "SceneGraph.h" -#include "SGList.h" -#include "TaskManager.h" -#include "Func.h" -#include "Chain.h" -#define FALSE 0 -#define TRUE !FALSE -#define CHAIN_LEN 50 - -static double chain_width = 10; - - -/* SceneGraph の property */ -ChainPropertyPtr properties[2]; -ChainPropertyPtr property; - - -//void createSceneGraphFromProperty(ChainPropertyPtr p) ; -void createSceneGraphFromProperty(void* p) ; - -void -Chain::init_chain_vars(ChainPropertyPtr cv) { - cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; - cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0; - cv->can_move = TRUE; -} - -void -set_vector(ChainPropertyPtr p, SceneGraphPtr sg) { - sg->xyz[0] = p->next_x; - sg->xyz[1] = p->next_y; - sg->xyz[2] = 0.0f; - sg->angle[0] = p->angle[0]; - sg->angle[1] = p->angle[1]; - sg->angle[2] = p->angle[2]; -} - -#if 0 -static void -chain_move_ope(SceneGraphPtr node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - - if (pad->circle.isHold()) { - property[CHAIN_LEN-1].can_move = FALSE; - if (pad->left.isHold()) { - property[CHAIN_LEN-1].x += -5.0; - } else if (pad->right.isHold()) { - property[CHAIN_LEN-1].x += 5.0; - } - - if (pad->up.isHold()) { - property[CHAIN_LEN-1].y += -5.0; - } else if (pad->down.isHold()) { - property[CHAIN_LEN-1].y += 5.0; - } - } else { - property[CHAIN_LEN-1].can_move = TRUE; - } -} -#endif - -void -Chain::chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h) -{ - int id = sg->id; - //ChainPropertyPtr p = (ChainPropertyPtr)sg->propertyptr; - HTaskPtr chain_cal; - ChainPropertyPtr output; - - // SceneGraph の切り替えもここでやる - if (property == properties[0]) { - property = properties[1]; - output = properties[0]; - }else{ - property = properties[0]; - output = properties[1]; - } - chain_cal = manager->create_task(CHAINCAL_TASK); - chain_cal->add_inData(property, sizeof(ChainProperty)*CHAIN_LEN); - chain_cal->add_param(id); - chain_cal->add_outData(output, sizeof(ChainProperty)*CHAIN_LEN); - chain_cal->set_post(createSceneGraphFromProperty, (void*)id); - chain_cal->spawn(); - -} - -void -Chain::chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) -{ - -} - -void -createSceneGraphFromProperty(void* p) -{ - ChainPropertyPtr chain_p = (ChainPropertyPtr)p; - SceneGraphPtr chain_copy = sgroot->createSceneGraph(CHAIN); - chain_copy->propertyptr = (void*)chain_p; - chain_copy->property_size = sizeof(ChainProperty); - set_vector(chain_p, chain_copy); - chain_p->parent->addChild(chain_copy); -} - -void -Chain::init(TaskManager *manager, int w, int h) -{ - SceneGraphPtr root_chain, chain; - ChainPropertyPtr rcv; - ChainProperty r; - HTaskPtr chain_init; - - rcv = &r; - - sgroot->createFromXMLfile(manager, "xml_file/chain.xml"); - - /* SPE に送る property の配列の領域確保 */ - properties[0] = (ChainPropertyPtr)manager->allocate(sizeof(ChainProperty)*CHAIN_LEN); - properties[1] = (ChainPropertyPtr)manager->allocate(sizeof(ChainProperty)*CHAIN_LEN); - property = properties[0]; - - root_chain = sgroot->createSceneGraph(CHAIN); - // set_move_collision()ではだめ -// root_chain->set_move_collision(chain_move_ope, chain_collision); - init_chain_vars(rcv); - rcv->next_x = w / 2; - rcv->next_y = 0.0; - rcv->angle[0] = 0; - rcv->angle[1] = 0; - rcv->angle[2] = 0; - - set_vector(rcv, root_chain); - - for(int i = 0; i < CHAIN_LEN; i++) { - chain = sgroot->createSceneGraph(CHAIN); - property[i].id = i; - init_chain_vars(&property[i]); - property[i].x = 0; - property[i].y = chain_width * i; - set_vector(&property[i], chain); - property->angle[1] = -90 * (i % 2); - //chain->set_move_collision(chain_move, chain_collision); - chain->propertyptr = &property[i]; - chain->property_size = sizeof(ChainProperty); - root_chain->addChild(chain); - property[i].parent = root_chain; - } - property[0].can_move = FALSE; - - // property を SPU の共有領域へコピーする - chain_init = manager->create_task(CHAININIT_TASK); - chain_init->add_inData(property, sizeof(ChainProperty)*CHAIN_LEN); - chain_init->add_param(CHAIN_LEN); - chain_init->set_cpu(SPE_0); - chain_init->set_post(createSceneGraphFromProperty, (void*)property); - chain_init->spawn(); - - sgroot->setSceneData(root_chain); -} -
--- a/TaskManager/Test/test_render/SceneGraphRoot.cc Tue Oct 06 14:21:37 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraphRoot.cc Mon Oct 12 11:26:17 2009 +0900 @@ -7,6 +7,7 @@ #include "TextureHash.h" #include "texture.h" #include "SGList.h" +#include "Application.h" int cnt = 0; @@ -218,6 +219,65 @@ sg_exec_tree = camera->children; } +void +SceneGraphRoot::speExecute(int screen_w, int screen_h, Application *app) +{ + + SceneGraphPtr list = sg_available_list; + // SceneGraphPtr t = sg_exec_tree; + // SceneGraphPtr cur_parent = camera; + + // 前フレームで描画した SceneGraph は削除 + allRemove(sg_remove_list); + + // 前フレームに作られた SceneGraph は描画用に移行 + // 現フレームでの操作は以下の tree,list には適用されない + sg_draw_tree = sg_exec_tree; + sg_remove_list = sg_available_list; + + // 現フレームで新しく SceneGraph がコピーされるので初期化 + sg_exec_tree = NULL; + sg_available_list = NULL; + + camera->move_execute(screen_w, screen_h); + camera->update(screen_w, screen_h); + + camera->children = NULL; + camera->lastChild = NULL; + + list->move_execute(screen_w, screen_h); + list->collision_check(screen_w, screen_h, list); + + list->frame++; + list = list->next; + + if(sg_exec_tree != NULL) { + return; + } + + /*removeのflagをもとにtreeを形成*/ + /* spe から送り返されてきた property の配列を見て生成する for()*/ + /* + for (Property *t = property[0]; is_end(t); t++){ + SceneGraphPtr s = application->scenegraph_factory(t); // SceneGraphNode を作る + t->scenegraph = s; // property list には SceneGraphへのポインタが入っている + application->scenegraph_connector(property[0], s); // add する + } + */ + + + + // 現在、allExecute が終わった時点では + // camera->children が User SceneGraph の root になる + + /** + * NULL じゃなかったら、setSceneData が呼ばれてるから + * そっちを次の Scene にする + */ + + sg_exec_tree = camera->children; +} + void SceneGraphRoot::allExecute(int screen_w, int screen_h)
--- a/TaskManager/Test/test_render/SceneGraphRoot.h Tue Oct 06 14:21:37 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraphRoot.h Mon Oct 12 11:26:17 2009 +0900 @@ -5,6 +5,7 @@ #include "SceneGraphArray.h" #include "Camera.h" #include "SceneGraphIterator.h" +#include "Application.h" class SceneGraphRoot { public: @@ -63,6 +64,7 @@ void updateControllerState(void); void speExecute(int screen_w, int screen_h); + void speExecute(int screen_w, int screen_h, Application *app); /* System API */ void registSceneGraph(SceneGraphPtr sg);
--- a/TaskManager/Test/test_render/viewer.cc Tue Oct 06 14:21:37 2009 +0900 +++ b/TaskManager/Test/test_render/viewer.cc Mon Oct 12 11:26:17 2009 +0900 @@ -10,13 +10,14 @@ #include "TaskManager.h" #include <wchar.h> #include "Pad.h" +#include "Application.h" static void post2runLoop(void *viewer); static void post2runDraw(void *viewer); static void post2speRendering(void *viewer); static void post2speDraw(void *viewer); // static void post2speRunLoop(void *viewer); -//static void post2runMove(void *viewer); +static void post2runMove(void *viewer); //static void post2exchange_sgroot(void *viewer); //static void post2speRunLoop(void *viewer); static void post2runMoveDrawLoop(void *viewer); @@ -164,11 +165,11 @@ vacuum_init2(manager, this->width, this->height); break; case 16: - app = new Chain(); + app = new Chain(); app->init(manager, this->width, this->height); - speLoop(); - return; - break; + speLoop(); + return; + break; case 17: chain_old_init(manager, this->width, this->height); break; @@ -321,8 +322,10 @@ /* TASK_MOVE は外から引数で取ってくるべき */ //HTaskPtr move_task = viewer->manager->create_task(viewer->app->move_taskid); - HTaskPtr move_task = viewer->manager->create_task(TASK_MOVE); + //HTaskPtr move_task = viewer->manager->create_task(TASK_MOVE); //move_task->add_param(sgroot); + HTaskPtr move_task = viewer->manager->create_task(TASK_DUMMY); + move_task->set_post(post2runMove, (void*)viewer); //HTaskPtr draw_task = viewer->manager->create_task(TASK_DRAW); @@ -364,7 +367,7 @@ task_next->spawn(); } -#if 0 +#if 1 void post2runMove(void *viewer_) { @@ -379,7 +382,7 @@ Viewer::run_move(HTaskPtr task_next) { sgroot->updateControllerState(); - sgroot->allExecute(width, height); + sgroot->speExecute(width, height, app); } void @@ -483,7 +486,6 @@ spackList[i-1].reinit(i*split_screen_h); } - //run_move(task_next); sgroot->updateControllerState(); sgroot->allExecute(width, height); //sgroot->checkRemove();