Mercurial > hg > Game > Cerium
changeset 351:10c1f6970f6a draft
add move,collision task
author | admin@mcbk.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 10 Jul 2009 18:20:26 +0900 |
parents | 628cb162be88 |
children | 9738837c225c |
files | example/scenegraph/xml/task/collision.cpp example/scenegraph/xml/task/collision_task1.cpp example/scenegraph/xml/task/move.cpp example/scenegraph/xml/task/move_task1.cpp example/scenegraph/xml/task/tree_walk_collision.cpp example/scenegraph/xml/task/tree_walk_move.cpp |
diffstat | 6 files changed, 137 insertions(+), 368 deletions(-) [+] |
line wrap: on
line diff
--- a/example/scenegraph/xml/task/collision.cpp Fri Jul 10 16:41:20 2009 +0900 +++ b/example/scenegraph/xml/task/collision.cpp Fri Jul 10 18:20:26 2009 +0900 @@ -1,196 +1,38 @@ /** - * SceneGraph が増えてくると動かなくなるかもしれない。 - * 一応 mainMem とかで動くようになるとは思うけど。 - * だめだったら、そこら辺が怪しいと思うべき + * 前もって collision する対象を task の global に登録しておく task が必要 + * SceneGraph を読み込んで + * 衝突判定を行う node を確保する + * node の型に対応する collision 関数を呼び出す + * 新しい SceneGraoh を生成する + * 登録してある global を解放する task を用意する + * */ // #define DEBUG #include "error.h" - -#include "CreatePolygon.h" -#include "polygon_pack.h" #include "scene_graph_pack.h" -SchedDefineTask(CreatePolygon); - -#define SG_PACK_LOAD 10 -#define SG_NODE_LOAD 11 -#define PP_LOAD 12 -#define PP_STORE 13 - -/** - * あとで直す - */ -static void -rotate(float *xyz, float *matrix) -{ - float abc[4]; - - abc[0] = xyz[0]; - abc[1] = xyz[1]; - abc[2] = xyz[2]; - abc[3] = xyz[3]; - - for(int i=0; i<4; i++) - { - xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; - } -} - -int -CreatePolygon::run(void *rbuf, void *wbuf) -{ - __debug_spe("CreatePolygon\n"); - - float xyz1[4],xyz2[4],xyz3[4]; - - SceneGraphPackPtr sgp = (SceneGraphPack*)smanager->get_input(0); - SceneGraphPackPtr next_sgp = - (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack)); - SceneGraphPackPtr free_sgp = next_sgp; - SceneGraphPackPtr tmp_sgp; - - SceneGraphNodePtr node; - SceneGraphNodePtr next_node - = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode)); - SceneGraphNodePtr free_node = next_node; - SceneGraphNodePtr tmp_node; +// 本来は tasks.xml に書く +SchedDefineTask(SceneGraphCollision); - PolygonPackPtr pp - = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); - PolygonPackPtr send_pp - = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); - PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(0); - PolygonPackPtr tmp_pp; - - pp->init(); - send_pp->init(); - - do { - if (sgp->next != NULL) { - smanager->dma_load(next_sgp, (uint32)sgp->next, - sizeof(SceneGraphPack), SG_PACK_LOAD); - } else { - next_sgp = NULL; - } - - for (int i = 0; i < sgp->info.size; i++) { - node = &sgp->node[i]; - - do { - if (node->next != NULL) { - smanager->dma_load(next_node, (uint32)node->next, - sizeof(SceneGraphNode), SG_NODE_LOAD); - } else { - next_node = NULL; - } - - for (int n = 0, nt = 0; n < node->size*3; n+=9, nt+=6) { - - if (pp->info.size >= MAX_SIZE_TRIANGLE) { - PolygonPackPtr next; - - // smanager から Task を作る、0 ではなく PolygonPack->task_id が良い - smanager->mainMem_alloc(0, sizeof(PolygonPack)); - smanager->mainMem_wait(); - next = (PolygonPackPtr)smanager->mainMem_get(0); - - pp->next = next; // この部分は TaskManager 側でやるべき - - tmp_pp = pp; - pp = send_pp; - send_pp = tmp_pp; +int +move::run(void *rbuf, void *wbuf) +{ + __debug_spe("SceneGraphCollision\n"); - smanager->dma_wait(PP_STORE); - smanager->dma_store(send_pp, (uint32)pp_addr, - sizeof(PolygonPack), PP_STORE); - - pp_addr = next; - - smanager->dma_wait(PP_LOAD); // 多分不要 - smanager->dma_load(pp, (uint32)pp_addr, - sizeof(PolygonPack), PP_LOAD); - // 次の dma_wait のコストが高いのでパイプラインで隠す必要がある - - smanager->dma_wait(PP_LOAD); - pp->init(); - - } - - TrianglePack *triangle = &pp->tri[pp->info.size++]; + SceneGraphPackPtr cur = (SceneGraphPack*) rbuf; + int collision_task_id = cur->collision_task; + // next は Mainmemory 上のアドレス + SceneGraphPackPtr next = + (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack)); - xyz1[0] = node->vertex[n]; - xyz1[1] = node->vertex[n+1]; - xyz1[2] = node->vertex[n+2]*-1; - xyz1[3] = 1; - xyz2[0] = node->vertex[n+3]; - xyz2[1] = node->vertex[n+3+1]; - xyz2[2] = node->vertex[n+3+2]*-1; - xyz2[3] = 1; - xyz3[0] = node->vertex[n+6]; - xyz3[1] = node->vertex[n+6+1]; - xyz3[2] = node->vertex[n+6+2]*-1; - xyz3[3] = 1; - - rotate(xyz1, node->translation); - rotate(xyz2, node->translation); - rotate(xyz3, node->translation); - - triangle->ver1.x = xyz1[0]; - triangle->ver1.y = xyz1[1]; - triangle->ver1.z = xyz1[2]; - triangle->ver1.tex_x = node->texture[nt]; - triangle->ver1.tex_y = node->texture[nt+1]; - - triangle->ver2.x = xyz2[0]; - triangle->ver2.y = xyz2[1]; - triangle->ver2.z = xyz2[2]; - triangle->ver2.tex_x = node->texture[nt+2]; - triangle->ver2.tex_y = node->texture[nt+2+1]; - - triangle->ver3.x = xyz3[0]; - triangle->ver3.y = xyz3[1]; - triangle->ver3.z = xyz3[2]; - triangle->ver3.tex_x = node->texture[nt+4]; - triangle->ver3.tex_y = node->texture[nt+4+1]; - -#if 1 - triangle->tex_info.addr = node->tex_addr; - triangle->tex_info.width = node->tex_width; - triangle->tex_info.height = node->tex_height; -#else - triangle->tex_info.addr = node->texture_info.pixels; - triangle->tex_info.width = node->texture_info.t_w; - triangle->tex_info.height = node->texture_info.t_h; -#endif - } - - smanager->dma_wait(SG_NODE_LOAD); - - tmp_node = node; - node = next_node; - next_node = tmp_node; - } while (node); - - next_node = free_node; - } - - smanager->dma_wait(SG_PACK_LOAD); - - tmp_sgp = sgp; - sgp = next_sgp; - next_sgp = tmp_sgp; - } while (sgp); - - smanager->dma_wait(PP_STORE); - smanager->dma_store(pp, (uint32)pp_addr, - sizeof(PolygonPack), PP_STORE); - smanager->dma_wait(PP_STORE); - - free(pp); - free(send_pp); - free(free_node); - free(free_sgp); + if (smanager->call_task(collision_task_id, (void*)cur, (void*)next)) { + // 次の状態があって、新しく node を確保してそこを確保する + smanager->write(cur, next, sizeof(SceneGraphPack)); + } else { + // この node は消滅 + smanager->free(next); + } return 0; -} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/scenegraph/xml/task/collision_task1.cpp Fri Jul 10 18:20:26 2009 +0900 @@ -0,0 +1,29 @@ +/** + * node の衝突判定を行う + * + */ + +// #define DEBUG +#include "error.h" +#include "scene_graph_pack.h" + +// 本来は tasks.xml に書く +SchedDefineTask(SceneGraphMove); + +int +move::run(void *rbuf, void *wbuf) +{ + __debug_spe("SceneGraphMove\n"); + + SceneGraphPackPtr cur = (SceneGraphPack*) rbuf; + //SceneGraphPackPtr next = (SceneGraphPackPtr*)wbuf; + SceneGraphPackPtr next = cur; + //memcpy((void*)rbuf, (void*)wbuf, sizeof(SceneGtaphPack)); + + SceneGraphPackPtr col = + (SceneGraphPackPtr*)smanager->global_get(cur->collision); + if (cur->x == col->x) { + next->move_function_id = Next; + } + return 1; +}
--- a/example/scenegraph/xml/task/move.cpp Fri Jul 10 16:41:20 2009 +0900 +++ b/example/scenegraph/xml/task/move.cpp Fri Jul 10 18:20:26 2009 +0900 @@ -1,196 +1,36 @@ /** - * SceneGraph が増えてくると動かなくなるかもしれない。 - * 一応 mainMem とかで動くようになるとは思うけど。 - * だめだったら、そこら辺が怪しいと思うべき + * SceneGraph を読み込んで + * node の型に対応する move 関数を呼び出す + * move 関数が無かったら load する + * 新しい SceneGraoh を生成する + * */ // #define DEBUG #include "error.h" - -#include "CreatePolygon.h" -#include "polygon_pack.h" #include "scene_graph_pack.h" -SchedDefineTask(CreatePolygon); - -#define SG_PACK_LOAD 10 -#define SG_NODE_LOAD 11 -#define PP_LOAD 12 -#define PP_STORE 13 - -/** - * あとで直す - */ -static void -rotate(float *xyz, float *matrix) -{ - float abc[4]; - - abc[0] = xyz[0]; - abc[1] = xyz[1]; - abc[2] = xyz[2]; - abc[3] = xyz[3]; - - for(int i=0; i<4; i++) - { - xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; - } -} - -int -CreatePolygon::run(void *rbuf, void *wbuf) -{ - __debug_spe("CreatePolygon\n"); - - float xyz1[4],xyz2[4],xyz3[4]; - - SceneGraphPackPtr sgp = (SceneGraphPack*)smanager->get_input(0); - SceneGraphPackPtr next_sgp = - (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack)); - SceneGraphPackPtr free_sgp = next_sgp; - SceneGraphPackPtr tmp_sgp; - - SceneGraphNodePtr node; - SceneGraphNodePtr next_node - = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode)); - SceneGraphNodePtr free_node = next_node; - SceneGraphNodePtr tmp_node; +// 本来は tasks.xml に書く +SchedDefineTask(SceneGraphMove); - PolygonPackPtr pp - = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); - PolygonPackPtr send_pp - = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); - PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(0); - PolygonPackPtr tmp_pp; - - pp->init(); - send_pp->init(); - - do { - if (sgp->next != NULL) { - smanager->dma_load(next_sgp, (uint32)sgp->next, - sizeof(SceneGraphPack), SG_PACK_LOAD); - } else { - next_sgp = NULL; - } - - for (int i = 0; i < sgp->info.size; i++) { - node = &sgp->node[i]; - - do { - if (node->next != NULL) { - smanager->dma_load(next_node, (uint32)node->next, - sizeof(SceneGraphNode), SG_NODE_LOAD); - } else { - next_node = NULL; - } - - for (int n = 0, nt = 0; n < node->size*3; n+=9, nt+=6) { - - if (pp->info.size >= MAX_SIZE_TRIANGLE) { - PolygonPackPtr next; - - // smanager から Task を作る、0 ではなく PolygonPack->task_id が良い - smanager->mainMem_alloc(0, sizeof(PolygonPack)); - smanager->mainMem_wait(); - next = (PolygonPackPtr)smanager->mainMem_get(0); - - pp->next = next; // この部分は TaskManager 側でやるべき - - tmp_pp = pp; - pp = send_pp; - send_pp = tmp_pp; +int +move::run(void *rbuf, void *wbuf) +{ + __debug_spe("SceneGraphMove\n"); - smanager->dma_wait(PP_STORE); - smanager->dma_store(send_pp, (uint32)pp_addr, - sizeof(PolygonPack), PP_STORE); - - pp_addr = next; - - smanager->dma_wait(PP_LOAD); // 多分不要 - smanager->dma_load(pp, (uint32)pp_addr, - sizeof(PolygonPack), PP_LOAD); - // 次の dma_wait のコストが高いのでパイプラインで隠す必要がある - - smanager->dma_wait(PP_LOAD); - pp->init(); - - } - - TrianglePack *triangle = &pp->tri[pp->info.size++]; + SceneGraphPackPtr cur = (SceneGraphPack*) rbuf; + int move_task_id = cur->move_task; + // next は Mainmemory 上のアドレス + SceneGraphPackPtr next = + (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack)); - xyz1[0] = node->vertex[n]; - xyz1[1] = node->vertex[n+1]; - xyz1[2] = node->vertex[n+2]*-1; - xyz1[3] = 1; - xyz2[0] = node->vertex[n+3]; - xyz2[1] = node->vertex[n+3+1]; - xyz2[2] = node->vertex[n+3+2]*-1; - xyz2[3] = 1; - xyz3[0] = node->vertex[n+6]; - xyz3[1] = node->vertex[n+6+1]; - xyz3[2] = node->vertex[n+6+2]*-1; - xyz3[3] = 1; - - rotate(xyz1, node->translation); - rotate(xyz2, node->translation); - rotate(xyz3, node->translation); - - triangle->ver1.x = xyz1[0]; - triangle->ver1.y = xyz1[1]; - triangle->ver1.z = xyz1[2]; - triangle->ver1.tex_x = node->texture[nt]; - triangle->ver1.tex_y = node->texture[nt+1]; - - triangle->ver2.x = xyz2[0]; - triangle->ver2.y = xyz2[1]; - triangle->ver2.z = xyz2[2]; - triangle->ver2.tex_x = node->texture[nt+2]; - triangle->ver2.tex_y = node->texture[nt+2+1]; - - triangle->ver3.x = xyz3[0]; - triangle->ver3.y = xyz3[1]; - triangle->ver3.z = xyz3[2]; - triangle->ver3.tex_x = node->texture[nt+4]; - triangle->ver3.tex_y = node->texture[nt+4+1]; - -#if 1 - triangle->tex_info.addr = node->tex_addr; - triangle->tex_info.width = node->tex_width; - triangle->tex_info.height = node->tex_height; -#else - triangle->tex_info.addr = node->texture_info.pixels; - triangle->tex_info.width = node->texture_info.t_w; - triangle->tex_info.height = node->texture_info.t_h; -#endif - } - - smanager->dma_wait(SG_NODE_LOAD); - - tmp_node = node; - node = next_node; - next_node = tmp_node; - } while (node); - - next_node = free_node; - } - - smanager->dma_wait(SG_PACK_LOAD); - - tmp_sgp = sgp; - sgp = next_sgp; - next_sgp = tmp_sgp; - } while (sgp); - - smanager->dma_wait(PP_STORE); - smanager->dma_store(pp, (uint32)pp_addr, - sizeof(PolygonPack), PP_STORE); - smanager->dma_wait(PP_STORE); - - free(pp); - free(send_pp); - free(free_node); - free(free_sgp); + if (smanager->call_task(move_task_id, (void*)cur, (void*)next)) { + // 次の状態があって、新しく node を確保してそこを確保する + smanager->write(cur, next, sizeof(SceneGraphPack)); + } else { + // この node は消滅 + smanager->free(next); + } return 0; -} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/scenegraph/xml/task/move_task1.cpp Fri Jul 10 18:20:26 2009 +0900 @@ -0,0 +1,26 @@ +/** + * node の状態を変化させる + * + */ + +// #define DEBUG +#include "error.h" +#include "scene_graph_pack.h" + +// 本来は tasks.xml に書く +SchedDefineTask(SceneGraphMove); + +int +move::run(void *rbuf, void *wbuf) +{ + __debug_spe("SceneGraphMove\n"); + + SceneGraphPackPtr cur = (SceneGraphPack*) rbuf; + //SceneGraphPackPtr next = (SceneGraphPackPtr*)wbuf; + SceneGraphPackPtr next = cur; + //memcpy((void*)rbuf, (void*)wbuf, sizeof(SceneGtaphPack)); + + next->x = cur->x + 1; + + return 1; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/scenegraph/xml/task/tree_walk_collision.cpp Fri Jul 10 18:20:26 2009 +0900 @@ -0,0 +1,5 @@ +/*! + tree_walk cell の場合は spe がデータを作成して送り込む + SPE が出力した tree を DMA 転送するのに必要なデータ構造を作成する + + */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/scenegraph/xml/task/tree_walk_move.cpp Fri Jul 10 18:20:26 2009 +0900 @@ -0,0 +1,27 @@ +/*! + tree_walk cell の場合は spe がデータを作成して送り込む + SPE が出力した tree を DMA 転送するのに必要なデータ構造を作成する + + */ + +// #define DEBUG +#include "error.h" +#include "scene_graph_pack.h" + +// 本来は tasks.xml に書く +SchedDefineTask(TreeWalkMove); + +int +tree_walk_move::run(void *rbuf, void *wbuf) +{ + __debug_spe("TreeWalkMove\n"); + + SceneGraphPackPtr cur = (SceneGraphPack*) rbuf; + //SceneGraphPackPtr next = (SceneGraphPackPtr*)wbuf; + SceneGraphPackPtr next = cur; + //memcpy((void*)rbuf, (void*)wbuf, sizeof(SceneGtaphPack)); + + next->x = cur->x + 1; + + return 1; +}