Mercurial > hg > Game > Cerium
changeset 374:4fad8f9329ac draft
CHAIN ADDED
author | kazz@kazzone.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 06 May 2009 15:49:30 +0900 |
parents | dd24efac4519 |
children | 2ae25549dd6a |
files | TaskManager/Test/test_render/SceneGraph.h TaskManager/Test/test_render/ball_bound.cpp TaskManager/Test/test_render/vacuum.cpp TaskManager/Test/test_render/viewer.cpp |
diffstat | 4 files changed, 191 insertions(+), 186 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/SceneGraph.h Sun Mar 29 22:03:16 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.h Wed May 06 15:49:30 2009 +0900 @@ -13,7 +13,7 @@ typedef void (*move_func)(SceneGraph* node, int screen_w, int screen_h); typedef void (*collision_func)(SceneGraph* node, int screen_w, int screen_h, - SceneGraph* tree); + SceneGraph* tree); typedef SceneGraph* SceneGraphPtr; class SceneGraph : public Polygon { @@ -27,6 +27,7 @@ // xyz,angle ぐらいあればおk? float stack_xyz[3]; float stack_angle[3]; + int id; // xml ファイルから生成した時のオブジェクトリスト SceneGraphPtr next; @@ -72,7 +73,7 @@ SceneGraphPtr clone(void *buf); SceneGraphPtr searchSceneGraph(char *name); void set_move_collision(SceneGraphPtr node, - move_func new_move, collision_func new_collision); + move_func new_move, collision_func new_collision); void set_move_collision(move_func new_move, collision_func new_collision); void remove(void); SceneGraphPtr realRemoveFromTree(SceneGraphPtr tree);
--- a/TaskManager/Test/test_render/ball_bound.cpp Sun Mar 29 22:03:16 2009 +0900 +++ b/TaskManager/Test/test_render/ball_bound.cpp Wed May 06 15:49:30 2009 +0900 @@ -10,7 +10,7 @@ static float vy = 0.0f; // y 方向速度 -static float dt = 1.0/1.0f; // frame rate +static float dt = 1.0/1.0f; // frame rate static float e = -0.8f; // 反発係数 static float g = 9.8f; // 重力加速度 @@ -27,25 +27,25 @@ Pad *pad = sgroot->getController(); if (pad->circle.isHold()) { - if (pad->left.isHold()) { - node->xyz[0] -= speed; - if(node->xyz[0] < ball_radius) - node->xyz[0] = ball_radius; - } else if (pad->right.isHold()) { - node->xyz[0] += speed; - if(node->xyz[0] > screen_w - ball_radius) - node->xyz[0] = screen_w - ball_radius; - } + if (pad->left.isHold()) { + node->xyz[0] -= speed; + if(node->xyz[0] < ball_radius) + node->xyz[0] = ball_radius; + } else if (pad->right.isHold()) { + node->xyz[0] += speed; + if(node->xyz[0] > screen_w - ball_radius) + node->xyz[0] = screen_w - ball_radius; + } - if (pad->up.isHold()) { - node->xyz[1] -= speed; - } else if (pad->down.isHold()) { - node->xyz[1] += speed; + if (pad->up.isHold()) { + node->xyz[1] -= speed; + } else if (pad->down.isHold()) { + node->xyz[1] += speed; if(node->xyz[1] > screen_h - ball_radius) - node->xyz[1] = screen_h - ball_radius; - } + node->xyz[1] = screen_h - ball_radius; + } } else { - node->set_move_collision(ball_move, ball_collision); + node->set_move_collision(ball_move, ball_collision); } } @@ -57,15 +57,15 @@ Pad *pad = sgroot->getController(); if (pad->circle.isPush()) { - node->set_move_collision(ball_move_idle2, ball_collision_idle); - time = 0; + node->set_move_collision(ball_move_idle2, ball_collision_idle); + time = 0; } time++; if (time > 90) { float w = (float)random(); - + w = fmodf(w, screen_w - ball_radius*2); node->xyz[0] = w + ball_radius; node->xyz[1] = h0; @@ -89,16 +89,16 @@ static void ball_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) + SceneGraphPtr tree) { if (node->xyz[1] > screen_h - ball_radius) { - node->xyz[1] = screen_h - ball_radius; + node->xyz[1] = screen_h - ball_radius; - vy *= e; - if (vy > -g && vy < 0) { - vy = 0.0; - node->set_move_collision(ball_move_idle, ball_collision_idle); - } + vy *= e; + if (vy > -g && vy < 0) { + vy = 0.0; + node->set_move_collision(ball_move_idle, ball_collision_idle); + } } }
--- a/TaskManager/Test/test_render/vacuum.cpp Sun Mar 29 22:03:16 2009 +0900 +++ b/TaskManager/Test/test_render/vacuum.cpp Wed May 06 15:49:30 2009 +0900 @@ -6,7 +6,7 @@ static void cube_move_right(SceneGraphPtr node, int screen_w, int screen_h); static void cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h); static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree); + SceneGraphPtr tree); static void cube_split(SceneGraphPtr root); static void vacuum_move(SceneGraphPtr node, int w, int h); @@ -27,11 +27,11 @@ #endif if (node->xyz[0] < 0) { - node->set_move_collision(cube_move_right, cube_collision); + node->set_move_collision(cube_move_right, cube_collision); } if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { - node->stack_xyz[1] = -node->stack_xyz[1]; + node->stack_xyz[1] = -node->stack_xyz[1]; } //node->angle[0] += 2.0f; @@ -39,7 +39,7 @@ //node->angle[2] += 2.0f * node->stack_xyz[2]; if (++node->frame > 60) { - cube_split(node); + cube_split(node); } } @@ -53,21 +53,21 @@ #else node->xyz[1] += node->stack_xyz[1]; #endif - + if (node->xyz[0] > screen_w) { - node->set_move_collision(cube_move_left, cube_collision); + node->set_move_collision(cube_move_left, cube_collision); } if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { - node->stack_xyz[1] = -node->stack_xyz[1]; + node->stack_xyz[1] = -node->stack_xyz[1]; } //node->angle[0] += 2.0f; //node->angle[1] += 2.0f * node->stack_xyz[1]; //node->angle[2] += 2.0f * node->stack_xyz[2]; - + if (++node->frame > 60) { - cube_split(node); + cube_split(node); } } @@ -105,19 +105,19 @@ Pad *pad = sgroot->getController(); if (pad->circle.isPush()) { - cube_split(node); + cube_split(node); } } static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) + SceneGraphPtr tree) { } static void vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) + SceneGraphPtr tree) { SceneGraphIteratorPtr it = sgroot->getIterator(); SceneGraphPtr bigm; @@ -126,46 +126,46 @@ float q = 0; if (pad->cross.isRelease()) { - return; + return; } return; for (; it->hasNext(MCUBE);) { - it->next(MCUBE); - SceneGraphPtr mcube = it->get(); - - dx = node->xyz[0] - mcube->xyz[0]; - dy = node->xyz[1] - mcube->xyz[1]; - - r = sqrt(dx*dx + dy*dy); + it->next(MCUBE); + SceneGraphPtr mcube = it->get(); + + dx = node->xyz[0] - mcube->xyz[0]; + dy = node->xyz[1] - mcube->xyz[1]; - if (r >= 1) q = 300/r; + r = sqrt(dx*dx + dy*dy); + + if (r >= 1) q = 300/r; - if (r < 50.0f) { - mcube->remove(); - continue; - } + if (r < 50.0f) { + mcube->remove(); + continue; + } - if (dx == 0) { - if(mcube->xyz[1] > node->xyz[1]) { - mcube->xyz[1] -= q; - } else if(mcube->xyz[1] < node->xyz[1]) { - mcube->xyz[1] += q; - } - } else { - if(mcube->xyz[0] > node->xyz[0]) { - mcube->xyz[0] -= q*cos(atan(dy/dx)); - mcube->xyz[1] -= q*sin(atan(dy/dx)); - mcube->stack_xyz[0] = -q*cos(atan(dy/dx)); - mcube->stack_xyz[1] = -q*sin(atan(dy/dx)); - } else if(mcube->xyz[0] < mcube->xyz[0]) { - mcube->xyz[0] += q*cos(atan(dy/dx)); - mcube->xyz[1] += q*sin(atan(dy/dx)); - mcube->stack_xyz[0] = -q*cos(atan(dy/dx)); - mcube->stack_xyz[1] = -q*sin(atan(dy/dx)); - } - } + if (dx == 0) { + if(mcube->xyz[1] > node->xyz[1]) { + mcube->xyz[1] -= q; + } else if(mcube->xyz[1] < node->xyz[1]) { + mcube->xyz[1] += q; + } + } else { + if(mcube->xyz[0] > node->xyz[0]) { + mcube->xyz[0] -= q*cos(atan(dy/dx)); + mcube->xyz[1] -= q*sin(atan(dy/dx)); + mcube->stack_xyz[0] = -q*cos(atan(dy/dx)); + mcube->stack_xyz[1] = -q*sin(atan(dy/dx)); + } else if(mcube->xyz[0] < mcube->xyz[0]) { + mcube->xyz[0] += q*cos(atan(dy/dx)); + mcube->xyz[1] += q*sin(atan(dy/dx)); + mcube->stack_xyz[0] = -q*cos(atan(dy/dx)); + mcube->stack_xyz[1] = -q*sin(atan(dy/dx)); + } + } } } @@ -175,20 +175,20 @@ Pad *pad = sgroot->getController(); if (pad->right.isHold()) { - node->xyz[0] += vacuum_speed; + node->xyz[0] += vacuum_speed; } else if (pad->left.isHold()) { - node->xyz[0] -= vacuum_speed; + node->xyz[0] -= vacuum_speed; } if (pad->up.isHold()) { - node->xyz[1] -= vacuum_speed; + node->xyz[1] -= vacuum_speed; } else if (pad->down.isHold()) { - node->xyz[1] += vacuum_speed; + node->xyz[1] += vacuum_speed; } if (pad->start.isPush()) { - node->xyz[0] = w/2; - node->xyz[1] = h*0.8; + node->xyz[0] = w/2; + node->xyz[1] = h*0.8; } }
--- a/TaskManager/Test/test_render/viewer.cpp Sun Mar 29 22:03:16 2009 +0900 +++ b/TaskManager/Test/test_render/viewer.cpp Wed May 06 15:49:30 2009 +0900 @@ -57,15 +57,15 @@ SDL_Event event; while(SDL_PollEvent(&event)) { - if (event.type==SDL_QUIT) { - return true; - } + if (event.type==SDL_QUIT) { + return true; + } } Uint8 *keys=SDL_GetKeyState(NULL); if (keys[SDLK_q] == SDL_PRESSED) { - return true; + return true; } return false; @@ -94,6 +94,7 @@ extern void init_position(int, int); extern void vacuum_init(int w, int h); extern void untitled_init(void); +extern void chain_init(int w, int h); void Viewer::run_init(const char *xml, int sg_number) { @@ -110,40 +111,43 @@ switch (sg_number) { case 0: case 1: - create_cube_split(sg_number); - break; + create_cube_split(sg_number); + break; case 2: case 3: case 4: - panel_init(sg_number); - break; + panel_init(sg_number); + break; case 5: - universe_init(); - break; + universe_init(); + break; case 6: - ieshoot_init(); - break; + ieshoot_init(); + break; case 7: - ball_bound_init(this->width, this->height); - break; + ball_bound_init(this->width, this->height); + break; case 8: - lcube_init(this->width, this->height); - break; + lcube_init(this->width, this->height); + break; case 9: - direction_init(); - break; + direction_init(); + break; case 10: - init_position(this->width, this->height); - break; + init_position(this->width, this->height); + break; case 11: - vacuum_init(this->width, this->height); - break; + vacuum_init(this->width, this->height); + break; case 12: untitled_init(); break; + case 13: + chain_init(this->width, this-> height); + break; default: - node_init(); - break; + node_init(); + break; } sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); @@ -166,14 +170,14 @@ /* 各 SPU が持つ、SpanPack の address list */ spackList_ptr = - (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); + (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); for (int i = 0; i < spackList_length; i++) { - spackList_ptr[i] = &spackList[i]; + spackList_ptr[i] = &spackList[i]; } for (int i = 1; i <= spackList_length; i++) { - spackList[i-1].init(i*split_screen_h); + spackList[i-1].init(i*split_screen_h); } task_next = manager->create_task(TASK_DUMMY); @@ -191,11 +195,11 @@ #endif for (int i = 0; i < spe_num; i++) { - task_tex = manager->create_task(TASK_INIT_TEXTURE); - /* ここはもう少しわかりやすい使い方がいいかもしれぬ。こんなもん? */ - task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); - task_next->wait_for(task_tex); - task_tex->spawn(); + task_tex = manager->create_task(TASK_INIT_TEXTURE); + /* ここはもう少しわかりやすい使い方がいいかもしれぬ。こんなもん? */ + task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + task_next->wait_for(task_tex); + task_tex->spawn(); } task_next->spawn(); @@ -212,15 +216,15 @@ quit_flg = quit_check(); if (quit_flg == true) { - this_time = get_ticks(); - run_finish(); - return; + 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); + spackList[i-1].reinit(i*split_screen_h); } task_next = manager->create_task(TASK_DUMMY); @@ -260,35 +264,35 @@ int range = (spackList_length + range_base - 1) / range_base; for (int i = 0; i < range_base; i++) { - int index_start = range*i; - int index_end = (index_start + range >= spackList_length) - ? spackList_length : index_start + range; + int index_start = range*i; + int index_end = (index_start + range >= spackList_length) + ? spackList_length : index_start + range; - task_create_sp = manager->create_task(TASK_CREATE_SPAN); - task_create_sp->add_inData(ppack, sizeof(PolygonPack)); - task_create_sp->add_inData(spackList_ptr, - sizeof(SpanPack*)*spackList_length_align); - task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); + task_create_sp = manager->create_task(TASK_CREATE_SPAN); + task_create_sp->add_inData(ppack, sizeof(PolygonPack)); + task_create_sp->add_inData(spackList_ptr, + sizeof(SpanPack*)*spackList_length_align); + task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); - task_create_sp->add_param(index_start); + task_create_sp->add_param(index_start); - /** - * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 - * [ 1.. 80] [ 81..160] [161..240] - * [241..320] [321..400] [401..480] - * - * ex. screen_height が 1080, spenum が 5 の場合、 - * [ 1..216] [217..432] [433..648] - * [649..864] [865..1080] - */ - task_create_sp->add_param(index_start*split_screen_h + 1); - task_create_sp->add_param(index_end*split_screen_h); + /** + * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 + * [ 1.. 80] [ 81..160] [161..240] + * [241..320] [321..400] [401..480] + * + * ex. screen_height が 1080, spenum が 5 の場合、 + * [ 1..216] [217..432] [433..648] + * [649..864] [865..1080] + */ + task_create_sp->add_param(index_start*split_screen_h + 1); + task_create_sp->add_param(index_end*split_screen_h); - task_next->wait_for(task_create_sp); - task_create_sp->wait_for(task_create_pp); + task_next->wait_for(task_create_sp); + task_create_sp->wait_for(task_create_pp); - task_create_sp->set_cpu(SPE_ANY); - task_create_sp->spawn(); + task_create_sp->set_cpu(SPE_ANY); + task_create_sp->spawn(); } task_create_pp->spawn(); @@ -300,65 +304,65 @@ { HTaskPtr task_next; HTaskPtr task_draw; - + task_next = manager->create_task(TASK_DUMMY); task_next->set_post(post2runLoop, NULL); - + ppack->clear(); for (int i = 0; i < spackList_length; i++) { - SpanPack *spack = &spackList[i]; - int startx = 1; - int endx = split_screen_w; + SpanPack *spack = &spackList[i]; + int startx = 1; + int endx = split_screen_w; - int starty = spack->info.y_top - split_screen_h + 1; - //int endy = spack->info.y_top; - int rangey = (starty + split_screen_h - 1 > this->height) - ? this->height - starty + 1 : split_screen_h; + int starty = spack->info.y_top - split_screen_h + 1; + //int endy = spack->info.y_top; + int rangey = (starty + split_screen_h - 1 > this->height) + ? this->height - starty + 1 : split_screen_h; - while (startx < this->width) { - if (spack->info.size > 0) { - // Draw SpanPack - task_draw = manager->create_task(TASK_DRAW_SPAN); - task_draw->add_inData(spack, sizeof(SpanPack)); - - task_draw->add_param( - (uint32)&pixels[(startx-1) + this->width*(starty-1)]); - task_draw->add_param(this->width); - } else { + while (startx < this->width) { + if (spack->info.size > 0) { + // Draw SpanPack + task_draw = manager->create_task(TASK_DRAW_SPAN); + task_draw->add_inData(spack, sizeof(SpanPack)); + + task_draw->add_param( + (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); + //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)); - } + 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; + 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 - } + } - task_draw->add_param(startx); - task_draw->add_param(endx); - task_draw->add_param(rangey); - task_draw->set_cpu(SPE_ANY); - task_next->wait_for(task_draw); - task_draw->spawn(); + task_draw->add_param(startx); + task_draw->add_param(endx); + task_draw->add_param(rangey); + task_draw->set_cpu(SPE_ANY); + task_next->wait_for(task_draw); + task_draw->spawn(); - startx += split_screen_w; - endx += split_screen_w; + startx += split_screen_w; + endx += split_screen_w; - if (endx > this->width) { - endx = this->width; - } - } + if (endx > this->width) { + endx = this->width; + } + } } task_next->spawn(); @@ -370,7 +374,7 @@ Viewer::run_finish(void) { if (this_time != start_time) { - printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); + printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); } delete sgroot;