# HG changeset patch # User game@henri.cr.ie.u-ryukyu.ac.jp # Date 1253266136 -32400 # Node ID d1f1e27d0a1202e96047b4410408b4ef30ba02eb # Parent 8c5fa57128cb2099929ba8af776a8e4c990e4a53 don't move. separate allExecute from run_loop diff -r 8c5fa57128cb -r d1f1e27d0a12 TaskManager/Test/test_render/SceneGraph.h --- a/TaskManager/Test/test_render/SceneGraph.h Thu Sep 17 16:55:18 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.h Fri Sep 18 18:28:56 2009 +0900 @@ -24,6 +24,7 @@ float stack_angle[3]; int id; + int property_size; void* propertyptr; // xml ファイルから生成した時のオブジェクトリスト diff -r 8c5fa57128cb -r d1f1e27d0a12 TaskManager/Test/test_render/SceneGraphRoot.cpp --- a/TaskManager/Test/test_render/SceneGraphRoot.cpp Thu Sep 17 16:55:18 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraphRoot.cpp Fri Sep 18 18:28:56 2009 +0900 @@ -160,6 +160,92 @@ } void +SceneGraphRoot::speExecute(int screen_w, int screen_h) +{ + + 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を形成*/ + while (t) { + SceneGraphPtr c = NULL; + if (!t->isRemoved()) { + c = t->clone(); + addNext(c); + cur_parent->addChild(c); + c->frame = t->frame; + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); + } + + if (t->children != NULL && c != NULL) { + cur_parent = c; + t = t->children; + } else if (t->brother != NULL) { + t = t->brother; + } else { + while (t) { + if (t->brother != NULL) { + t = t->brother; + break; + } else { + if (t->parent == NULL) { + t = NULL; + break; + } else { + cur_parent = cur_parent->parent; + t = t->parent; + + } + } + } + } + } + + + + // 現在、allExecute が終わった時点では + // camera->children が User SceneGraph の root になる + + /** + * NULL じゃなかったら、setSceneData が呼ばれてるから + * そっちを次の Scene にする + */ + + sg_exec_tree = camera->children; +} + + +void SceneGraphRoot::allExecute(int screen_w, int screen_h) { SceneGraphPtr list = sg_available_list; diff -r 8c5fa57128cb -r d1f1e27d0a12 TaskManager/Test/test_render/SceneGraphRoot.h --- a/TaskManager/Test/test_render/SceneGraphRoot.h Thu Sep 17 16:55:18 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraphRoot.h Fri Sep 18 18:28:56 2009 +0900 @@ -62,6 +62,8 @@ SceneGraphPtr getDrawSceneGraph(void); void updateControllerState(void); + void speExecute(int screen_w, int screen_h); + /* System API */ void registSceneGraph(SceneGraphPtr sg); void addNext(SceneGraphPtr sg); diff -r 8c5fa57128cb -r d1f1e27d0a12 TaskManager/Test/test_render/chain.cpp --- a/TaskManager/Test/test_render/chain.cpp Thu Sep 17 16:55:18 2009 +0900 +++ b/TaskManager/Test/test_render/chain.cpp Fri Sep 18 18:28:56 2009 +0900 @@ -23,11 +23,12 @@ } CHAIN_VARS; /* SceneGraph の property */ +CHAIN_VARS* properties[2]; CHAIN_VARS* property; -CHAIN_VARS cv[CHAIN_LEN]; -void createSceneGraphFromProperty(CHAIN_VARS* p) ; +//void createSceneGraphFromProperty(CHAIN_VARS* p) ; +void createSceneGraphFromProperty(void* p) ; void init_chain_vars(CHAIN_VARS *cv) { @@ -74,17 +75,25 @@ chain_move(SceneGraphPtr sg, int w, int h) { int id = sg->id; - CHAIN_VARS* p = (CHAIN_VARS*)sg->propertyptr; - if(id == 0) { - HTaskPtr chain_cal; - chain_cal = manager->create_task(CHAINCAL_TASK); - chain_cal->add_inData(&property[CHAIN_LEN-1], sizeof(CHAIN_VARS)); - chain_cal->add_param(id); - chain_cal->add_outData(property, sizeof(CHAIN_VARS)*CHAIN_LEN); - chain_cal->spawn(); - createSceneGraphFromProperty(p); + //CHAIN_VARS* p = (CHAIN_VARS*)sg->propertyptr; + HTaskPtr chain_cal; + CHAIN_VARS* 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(CHAIN_VARS)*CHAIN_LEN); + chain_cal->add_param(id); + chain_cal->add_outData(output, sizeof(CHAIN_VARS)*CHAIN_LEN); + chain_cal->set_post(createSceneGraphFromProperty, (void*)id); + chain_cal->spawn(); + } void @@ -94,13 +103,14 @@ } void -createSceneGraphFromProperty(CHAIN_VARS* p) +createSceneGraphFromProperty(void* p) { - SceneGraphPtr chain_copy; - chain_copy = sgroot->createSceneGraph(CHAIN); - chain_copy->propertyptr = (void*)p; - set_vector(p, chain_copy); - p->parent->addChild(chain_copy); + CHAIN_VARS* chain_p = (CHAIN_VARS*)p; + SceneGraphPtr chain_copy = sgroot->createSceneGraph(CHAIN); + chain_copy->propertyptr = (void*)chain_p; + chain_copy->property_size = sizeof(CHAIN_VARS); + set_vector(chain_p, chain_copy); + chain_p->parent->addChild(chain_copy); } void @@ -111,12 +121,16 @@ HTaskPtr chain_init; + sgroot->createFromXMLfile("xml_file/chain.xml"); /* SPE に送る property の配列の領域確保 */ - property = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*CHAIN_LEN); + properties[0] = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*CHAIN_LEN); + properties[1] = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*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; @@ -135,19 +149,21 @@ 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->set_move_collision(chain_move, chain_collision); + chain->propertyptr = &property[i]; + chain->property_size = sizeof(CHAIN_VARS); root_chain->addChild(chain); property[i].parent = root_chain; } - cv[0].can_move = FALSE; + property[0].can_move = FALSE; // property を SPU の共有領域へコピーする chain_init = manager->create_task(CHAININIT_TASK); chain_init->add_inData(property, sizeof(CHAIN_VARS)*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); } diff -r 8c5fa57128cb -r d1f1e27d0a12 TaskManager/Test/test_render/post.cpp --- a/TaskManager/Test/test_render/post.cpp Thu Sep 17 16:55:18 2009 +0900 +++ b/TaskManager/Test/test_render/post.cpp Fri Sep 18 18:28:56 2009 +0900 @@ -13,3 +13,15 @@ { screen->run_draw(); } + +void +post2runMove(void *arg) +{ + screen->run_move(); +} + +void +post2exchange_sgroot(void *arg) +{ + screen->exchange_sgroot(); +} diff -r 8c5fa57128cb -r d1f1e27d0a12 TaskManager/Test/test_render/spe/ChainCal.cpp --- a/TaskManager/Test/test_render/spe/ChainCal.cpp Thu Sep 17 16:55:18 2009 +0900 +++ b/TaskManager/Test/test_render/spe/ChainCal.cpp Fri Sep 18 18:28:56 2009 +0900 @@ -31,13 +31,10 @@ int ChainCal::run(void *rbuf, void *wbuf) { - CHAIN_VARS* property = (CHAIN_VARS*)global_get(DATA_ID); - //&property[CHAIN_LEN-1] = (CHAIN_VARS*)get_input(rbuf, 0); - CHAIN_VARS* pro = (CHAIN_VARS*)get_input(rbuf, 0); + CHAIN_VARS* property = (CHAIN_VARS*)rbuf; int id = get_param(0); - memcpy(&property[CHAIN_LEN-1], pro, sizeof(CHAIN_VARS)); - CHAIN_VARS* o_property = (CHAIN_VARS*)get_output(wbuf, 0); + //CHAIN_VARS* o_property = (CHAIN_VARS*)wbuf; for(int cnt = 0; cnt < 600; cnt++) { for(int i = 0; i < CHAIN_LEN; i++) { @@ -76,18 +73,19 @@ } } - int p, n; - p = n = id; - if(p != 0) { - p--; + for (int j = 0; j < CHAIN_LEN; j++) { + int p, n; + id = property[j].id; + p = n = id; + if(p != 0) { + p--; + } + if(n != CHAIN_LEN - 1) { + n++; + } + property[j].angle[2-(id%2)*2] + = 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI; } - if(n != CHAIN_LEN - 1) { - n++; - } - property->angle[2-(id%2)*2] - = 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI; - - o_property = property; - + return 0; } diff -r 8c5fa57128cb -r d1f1e27d0a12 TaskManager/Test/test_render/viewer.cpp --- a/TaskManager/Test/test_render/viewer.cpp Thu Sep 17 16:55:18 2009 +0900 +++ b/TaskManager/Test/test_render/viewer.cpp Fri Sep 18 18:28:56 2009 +0900 @@ -11,9 +11,14 @@ #include #include "Pad.h" +HTaskPtr move_DUMMY = manager->create_task(TASK_DUMMY); +HTaskPtr draw_DUMMY = manager->create_task(TASK_DUMMY); extern void post2runLoop(void *); extern void post2runDraw(void *); +extern void post2runMove(void *); +extern void post2exchange_sgroot(void *); + /* measure for FPS (Frame Per Second) */ int start_time; @@ -21,6 +26,7 @@ int frames; SceneGraphRootPtr sgroot; +SceneGraphRootPtr sgroot_2; /* Data Pack sent to Other CPUs (ex. SPE) */ SceneGraphPack *sgpack; @@ -92,7 +98,7 @@ extern void lcube_init(int, int); extern void direction_init(void); extern void init_position(int, int); -//extern void vacuum_init(int w, int h); +extern void vacuum_init(int w, int h); extern void untitled_init(void); extern void chain_init(int w, int h); extern void boss1_init(int w, int h); @@ -110,50 +116,51 @@ frames = 0; sgroot = new SceneGraphRoot(this->width, this->height); + sgroot_2 = new SceneGraphRoot(this->width, this->height); //sgroot->createFromXMLFile(xml); switch (sg_number) { case 0: case 1: - create_cube_split(sg_number); + create_cube_split(sg_number); break; case 2: case 3: case 4: - panel_init(sg_number); + panel_init(sg_number); break; case 5: - universe_init(); + universe_init(); break; case 6: - ieshoot_init(); + ieshoot_init(); break; case 7: - ball_bound_init(this->width, this->height); + ball_bound_init(this->width, this->height); break; case 8: - lcube_init(this->width, this->height); + lcube_init(this->width, this->height); break; case 9: - direction_init(); + direction_init(); break; case 10: - init_position(this->width, this->height); + init_position(this->width, this->height); break; case 11: // vacuum_init(this->width, this->height); break; case 12: - untitled_init(); + untitled_init(); break; case 13: - boss1_init(this->width, this->height); + boss1_init(this->width, this->height); break; case 14: - init_gaplant(this->width, this->height); + init_gaplant(this->width, this->height); break; case 15: - vacuum_init2(this->width, this->height); + vacuum_init2(this->width, this->height); break; case 16: chain_init(this->width, this-> height); @@ -218,64 +225,64 @@ } task_next->set_post(&post2runLoop, NULL); // set_post(function(this->run_loop()), NULL) + task_next->set_post(&post2runMove, NULL); // set_post(function(this->run_move()), NULL) task_next->spawn(); // TASK_INIT_TEXTURE が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ } void -Viewer::run_loop(void) +Viewer::exchange_sgroot() { - HTaskPtr task_create_pp = NULL; - HTaskPtr task_create_sp = NULL; - HTaskPtr task_next; - bool quit_flg; - - quit_flg = quit_check(); + SceneGraphRootPtr tmp = sgroot; + sgroot = sgroot_2; + sgroot_2 = tmp; + HTaskPtr task_next = manager->create_task(TASK_DUMMY); + task_next->set_post(&post2runLoop, NULL); // set_post(function(this->run_loop()), NULL) + task_next->set_post(&post2runMove, NULL); // set_post(function(this->run_move()), NULL) + task_next->spawn(); + +} - if (quit_flg == true) { - this_time = get_ticks(); - run_finish(); - return; - } +void +Viewer::run_move() +{ + sgroot->updateControllerState(); + sgroot->allExecute(width, height); + // run_loop と待ち合わせの処理 - clean_pixels(); + HTaskPtr task_next; + task_next = manager->create_task(TASK_DUMMY); - for (int i = 1; i <= spackList_length; i++) { - spackList[i-1].reinit(i*split_screen_h); - } - - task_next = manager->create_task(TASK_DUMMY); + task_next->wait_for(draw_DUMMY); + task_next->wait_for(move_DUMMY); + move_DUMMY->spawn(); + //task_next->set_post(exchange_sgroot, NULL); // set_post(function(this->run_loop()), NULL) + task_next->spawn(); -#if 0 - // SceneGraphPack の update - HTaskPtr task_update_sgp = NULL; - task_update_sgp = manager->create_task(TASK_UPDATE_SGP); - task_update_sgp->add_inData(sgpack, sizeof(SceneGraphPack)); - task_update_sgp->add_outData(sgpack, sizeof(SceneGraphPack)); - task_update_sgp->add_param(width); - task_update_sgp->add_param(height); - task_next->wait_for(task_update_sgp); - task_update_sgp->spawn(); -#else - sgroot->updateControllerState(); - sgroot->allExecute(width, height); - //sgroot->checkRemove(); -#endif +} + +void +Viewer::run_collision() +{ +} -#if 0 - // SceneGraphPack(配列) -> PolygonPack - task_create_pp = manager->create_task(TASK_CREATE_PP); - task_create_pp->add_inData(sgpack, sizeof(SceneGraphPack)); - task_create_pp->add_param((uint32)ppack); -#else +void +Viewer::rendering() +{ + HTaskPtr task_create_pp = NULL; + HTaskPtr task_create_sp = NULL; + HTaskPtr task_next; + + task_next = manager->create_task(TASK_DUMMY); + // SceneGraph(木構造) -> PolygonPack task_create_pp = manager->create_task(TASK_CREATE_PP2); - task_create_pp->add_param((uint32)sgroot->getDrawSceneGraph()); + task_create_pp->add_param((uint32)sgroot_2->getDrawSceneGraph()); task_create_pp->add_param((uint32)ppack); -#endif - task_next->wait_for(task_create_pp); + //task_next->wait_for(task_create_pp); + int range_base = spe_num; // 切り上げのつもり int range = (spackList_length + range_base - 1) / range_base; @@ -315,19 +322,48 @@ task_create_pp->spawn(); // Barrier 同期 + // run_draw() を呼ぶ post2runDraw task_next->set_post(post2runDraw, NULL); // set_post(function(this->run_draw()), NULL) task_next->spawn(); // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ } void -Viewer::run_draw(void) +Viewer::run_loop() +{ + bool quit_flg; + + quit_flg = quit_check(); + if (quit_flg == true) { + this_time = get_ticks(); + run_finish(); + return; + } + + clean_pixels(); + + for (int i = 1; i <= spackList_length; i++) { + spackList[i-1].reinit(i*split_screen_h); + } + + //task_next = manager->create_task(TASK_DUMMY); + + //sgroot->updateControllerState(); + //sgroot->allExecute(width, height); + //sgroot->checkRemove(); + + // ここから下は Rendering という関数にする + rendering(); +} + +void +Viewer::run_draw() // 引数に post2runLoop を入れるようにする { HTaskPtr task_next; HTaskPtr task_draw; task_next = manager->create_task(TASK_DUMMY); - task_next->set_post(post2runLoop, NULL); + //task_next->set_post(post2runLoop, NULL); ppack->clear(); for (int i = 0; i < spackList_length; i++) { @@ -350,24 +386,9 @@ (uint32)&pixels[(startx-1) + this->width*(starty-1)]); task_draw->add_param(this->width); } else { -#if 0 - //break; - // Draw Background (現在は塗りつぶし) - task_draw = manager->create_task(TASK_DRAW_BACK); - task_draw->add_param(0xffffffff); - - for (int k = 0; k < rangey; k++) { - task_draw->add_outData( - &pixels[(startx-1)+this->width*(k+starty-1)], - (endx - startx + 1)*sizeof(int)); - } -#else memset(&pixels[(startx-1)+this->width*(starty-1)], 0, (this->width)*sizeof(int)*rangey); - //wmemset((wchar_t*)&pixels[(startx-1)+this->width*(starty-1)], - //0xFFFFFFFF, (this->width)*sizeof(int)*rangey/sizeof(wchar_t)); - break; -#endif + break; } task_draw->add_param(startx); @@ -385,9 +406,12 @@ } } } - - task_next->set_post(post2runLoop, NULL); // set_post(function(this->run_loop()), NULL) - task_next->spawn(); + + task_next->wait_for(draw_DUMMY); + task_next->wait_for(move_DUMMY); + draw_DUMMY->spawn(); + task_next->set_post(post2exchange_sgroot, NULL); // set_post(function(this->run_loop()), NULL) + task_next->spawn(); // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ frames++; @@ -401,6 +425,6 @@ } delete sgroot; - + delete sgroot_2; quit(); } diff -r 8c5fa57128cb -r d1f1e27d0a12 TaskManager/Test/test_render/viewer.h --- a/TaskManager/Test/test_render/viewer.h Thu Sep 17 16:55:18 2009 +0900 +++ b/TaskManager/Test/test_render/viewer.h Fri Sep 18 18:28:56 2009 +0900 @@ -36,6 +36,10 @@ virtual void run_loop(void); virtual void run_draw(void); virtual void run_finish(void); + virtual void run_move(); + virtual void run_collision(); + virtual void rendering(); + virtual void exchange_sgroot(); }; #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK