Mercurial > hg > Game > Cerium
changeset 35:1e17e0b441a7
*** empty log message ***
author | gongo |
---|---|
date | Tue, 12 Feb 2008 19:19:06 +0900 |
parents | 34dd03a8a612 |
children | 650e46810d04 |
files | TaskManager/Test/simple_render/Makefile TaskManager/Test/simple_render/create_pp.cpp TaskManager/Test/simple_render/create_sgp.cpp TaskManager/Test/simple_render/main.cpp TaskManager/Test/simple_render/task/create_pp.cpp TaskManager/Test/simple_render/task/create_sgp.cpp TaskManager/Test/simple_render/task/task_init.cpp TaskManager/Test/simple_render/task/update_sgp.cpp TaskManager/Test/simple_render/update_sgp.cpp TaskManager/Test/simple_render/viewer.cpp |
diffstat | 10 files changed, 284 insertions(+), 268 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/simple_render/Makefile Tue Feb 12 19:14:00 2008 +0900 +++ b/TaskManager/Test/simple_render/Makefile Tue Feb 12 19:19:06 2008 +0900 @@ -1,11 +1,11 @@ CC = g++ CFLAGS = -g -Wall `sdl-config --cflags` `xml2-config --cflags`\ - -I../../../include/TaskManager + -I../../../include/TaskManager -I. LIBS = `sdl-config --libs` -lSDL_image -Wl,-framework,OpenGL `xml2-config --libs`\ -L../../ -lmanager TARGET = test_nogl #OBJS = scene.o demonstration.o sys.o base64_de.o pad.o texture.o xml.o polygon.o viewer.o main.o -OBJS = create_pp.o update_sgp.o create_sgp.o triangle.o vertex.o span.o sys.o base64_de.o pad.o texture.o xml.o polygon.o viewer.o main.o +OBJS = task/task_init.o task/create_pp.o task/update_sgp.o task/create_sgp.o triangle.o vertex.o span.o sys.o base64_de.o pad.o texture.o xml.o polygon.o viewer.o main.o all:$(TARGET)
--- a/TaskManager/Test/simple_render/create_pp.cpp Tue Feb 12 19:14:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -#include <iostream> -#include "polygon_pack.h" -#include "scene_graph_pack.h" -#include "sys.h" -using namespace std; - - -int create_pp(PolygonPack *pp, SceneGraphPack *sgp) -{ - float xyz1[4],xyz2[4],xyz3[4]; - - for (int i = 0; i < sgp->info.size; i++) { - SceneGraphNodePtr node = &sgp->node[i]; - - int n,nt,pt; - for(n=0,nt=0,pt=0; n<node->size*3; n+=9,nt+=6,pt++) { - 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); - - pp->tri[pt].x1 = xyz1[0]; - pp->tri[pt].y1 = xyz1[1]; - pp->tri[pt].z1 = xyz1[2]; - pp->tri[pt].tex_x1 = node->texture[nt]; - pp->tri[pt].tex_y1 = node->texture[nt+1]; - - pp->tri[pt].x2 = xyz2[0]; - pp->tri[pt].y2 = xyz2[1]; - pp->tri[pt].z2 = xyz2[2]; - pp->tri[pt].tex_x2 = node->texture[nt+2]; - pp->tri[pt].tex_y2 = node->texture[nt+2+1]; - - pp->tri[pt].x3 = xyz3[0]; - pp->tri[pt].y3 = xyz3[1]; - pp->tri[pt].z3 = xyz3[2]; - pp->tri[pt].tex_x3 = node->texture[nt+4]; - pp->tri[pt].tex_y3 = node->texture[nt+4+1]; - - } - pp->info.size = pt; - } - - return sizeof(PolygonPack); -}
--- a/TaskManager/Test/simple_render/create_sgp.cpp Tue Feb 12 19:14:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -#include <iostream> -#include "scene_graph_pack.h" -#include "polygon.h" -using namespace std; - - -int create_sgp(SceneGraphPack *sgp, Polygon *sg) -{ - int i = 0; - int nnpn = -1; - SceneGraphNodePtr node; - - Polygon *t; - t = sg; - - while(t) - { - node = &sgp->node[i]; - - node->size = t->size; - int d,tex; - for(d=0,tex=0; d<t->size*3; d+=3,tex+=2) - { - node->vertex[d] = t->data[d]; - node->vertex[d+1] = t->data[d+1]; - node->vertex[d+2] = t->data[d+2]; - node->texture[tex] = t->data[d+t->size*6]; - node->texture[tex+1] = t->data[d+t->size*6+1]; - } - - node->obj_pos[0] = 0; - node->obj_pos[1] = 0; - node->obj_pos[2] = 0; - node->obj_pos[3] = 1; - node->angle[0] = 0; - node->angle[1] = 0; - node->angle[2] = 0; - node->angle[3] = 1; - - for(int tm=0; tm<16; tm++) - { - node->translation[tm] = 0; - } - node->id = 0; - node->move = 0; - node->interaction = 0; - node->pn = nnpn; - - if(t->child != NULL) - { - nnpn = i; - t = t->child; - } - else if(t->brother != NULL) - { - nnpn = node->pn; - t = t->brother; - } - else - { - while(t) - { - if(t->brother != NULL) - { - t = t->brother; - break; - } - else - { - if(t->parent == NULL) - { - t = NULL; - break; - } - nnpn = sgp->node[nnpn].pn; - t = t->parent; - } - } - } - i++; - } - sgp->info.size = i; - - return sizeof(SceneGraphPack); -}
--- a/TaskManager/Test/simple_render/main.cpp Tue Feb 12 19:14:00 2008 +0900 +++ b/TaskManager/Test/simple_render/main.cpp Tue Feb 12 19:19:06 2008 +0900 @@ -15,6 +15,8 @@ TaskManager *manager; Viewer *screen; +extern void task_initialize(void); + struct init_arg { int bpp; int w; @@ -50,6 +52,9 @@ manager->set_task_depend(task_zrow_init, task_run); manager->set_task_depend(task_run, task_finish); + //task_sdl_init->set_depend(..); + //task_sdl_init->spawn(); + manager->spawn_task(task_sdl_init); manager->spawn_task(task_zrow_init); manager->spawn_task(task_run); @@ -113,6 +118,8 @@ manager = new TaskManager(1); manager->init(); + task_initialize(); + // 本当は、dlsym みたいなものを使いたいんだけど // 静的なやつはできないん? manager->set_symbol("init", (void*)init);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/task/create_pp.cpp Tue Feb 12 19:19:06 2008 +0900 @@ -0,0 +1,57 @@ +#include <iostream> +#include "polygon_pack.h" +#include "scene_graph_pack.h" +#include "sys.h" +using namespace std; + + +int create_pp(PolygonPack *pp, SceneGraphPack *sgp) +{ + float xyz1[4],xyz2[4],xyz3[4]; + + for (int i = 0; i < sgp->info.size; i++) { + SceneGraphNodePtr node = &sgp->node[i]; + + int n,nt,pt; + for(n=0,nt=0,pt=0; n<node->size*3; n+=9,nt+=6,pt++) { + 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); + + pp->tri[pt].x1 = xyz1[0]; + pp->tri[pt].y1 = xyz1[1]; + pp->tri[pt].z1 = xyz1[2]; + pp->tri[pt].tex_x1 = node->texture[nt]; + pp->tri[pt].tex_y1 = node->texture[nt+1]; + + pp->tri[pt].x2 = xyz2[0]; + pp->tri[pt].y2 = xyz2[1]; + pp->tri[pt].z2 = xyz2[2]; + pp->tri[pt].tex_x2 = node->texture[nt+2]; + pp->tri[pt].tex_y2 = node->texture[nt+2+1]; + + pp->tri[pt].x3 = xyz3[0]; + pp->tri[pt].y3 = xyz3[1]; + pp->tri[pt].z3 = xyz3[2]; + pp->tri[pt].tex_x3 = node->texture[nt+4]; + pp->tri[pt].tex_y3 = node->texture[nt+4+1]; + + } + pp->info.size = pt; + } + + return sizeof(PolygonPack); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/task/create_sgp.cpp Tue Feb 12 19:19:06 2008 +0900 @@ -0,0 +1,84 @@ +#include <iostream> +#include "scene_graph_pack.h" +#include "polygon.h" +using namespace std; + +int create_sgp(SceneGraphPack *sgp, Polygon *sg) +{ + int i = 0; + int nnpn = -1; + SceneGraphNodePtr node; + + Polygon *t; + t = sg; + + while(t) + { + node = &sgp->node[i]; + + node->size = t->size; + int d,tex; + for(d=0,tex=0; d<t->size*3; d+=3,tex+=2) + { + node->vertex[d] = t->data[d]; + node->vertex[d+1] = t->data[d+1]; + node->vertex[d+2] = t->data[d+2]; + node->texture[tex] = t->data[d+t->size*6]; + node->texture[tex+1] = t->data[d+t->size*6+1]; + } + + node->obj_pos[0] = 0; + node->obj_pos[1] = 0; + node->obj_pos[2] = 0; + node->obj_pos[3] = 1; + node->angle[0] = 0; + node->angle[1] = 0; + node->angle[2] = 0; + node->angle[3] = 1; + + for(int tm=0; tm<16; tm++) + { + node->translation[tm] = 0; + } + node->id = 0; + node->move = 0; + node->interaction = 0; + node->pn = nnpn; + + if(t->child != NULL) + { + nnpn = i; + t = t->child; + } + else if(t->brother != NULL) + { + nnpn = node->pn; + t = t->brother; + } + else + { + while(t) + { + if(t->brother != NULL) + { + t = t->brother; + break; + } + else + { + if(t->parent == NULL) + { + t = NULL; + break; + } + nnpn = sgp->node[nnpn].pn; + t = t->parent; + } + } + } + i++; + } + sgp->info.size = i; + + return sizeof(SceneGraphPack); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/task/task_init.cpp Tue Feb 12 19:19:06 2008 +0900 @@ -0,0 +1,16 @@ +#include "scene_graph_pack.h" +#include "polygon.h" +#include "TaskManager.h" + +extern TaskManager *manager; +extern int create_sgp(SceneGraphPack *sgp, Polygon *sg); +extern int update_sgp(SceneGraphPack *sgp, SceneGraphPack *_sgp); +extern int create_pp(PolygonPack *pp, SceneGraphPack *sgp); + +void +task_initialize() +{ + manager->set_symbol("CreateSGP", (void*)create_sgp); + manager->set_symbol("UpdateSGP", (void*)update_sgp); + manager->set_symbol("CreatePP", (void*)create_pp); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/task/update_sgp.cpp Tue Feb 12 19:19:06 2008 +0900 @@ -0,0 +1,92 @@ +#include <iostream> +#include <math.h> +#include "scene_graph_pack.h" +#include "sys.h" +using namespace std; + +/* +void matrix4x4(float *xyz, float *xyz1, float *xyz2) //xyz[16] +{ + for(int t=0; t<16; t+=4) + { + for(int i=0; i<4; i++) + { + xyz[t+i] = xyz1[t]*xyz2[i] + xyz1[t+1]*xyz2[4+i] + xyz1[t+2]*xyz2[8+i] + xyz1[t+3]*xyz2[12+i]; + } + } +} + +void get_matrix( float *matrix, float *rxyz, float *txyz, float *stack) +{ + float radx,rady,radz; + radx = rxyz[0]*3.14/180; + rady = rxyz[1]*3.14/180; + radz = rxyz[2]*3.14/180; + + float sinx = sin(radx); + float cosx = cos(radx); + float siny = sin(rady); + float cosy = cos(rady); + float sinz = sin(radz); + float cosz = cos(radz); + + matrix[0] = cosz*cosy+sinz*sinx*siny; + matrix[1] =sinz*cosx; + matrix[2] = -cosz*siny+sinz*sinx*cosy; + matrix[3] = 0; + matrix[4] = -sinz*cosy+cosz*sinx*siny; + matrix[5] = cosz*cosx; + matrix[6] = sinz*siny+cosz*sinx*cosy; + matrix[7] = 0; + matrix[8] = cosx*siny; + matrix[9] = -sinx; + matrix[10] = cosx*cosy; + matrix[11] = 0; + matrix[12] = txyz[0]; + matrix[13] = txyz[1]; + matrix[14] = txyz[2]; + matrix[15] = 1; + + float m[16]; + + for(int i=0; i<16; i++) + { + m[i] = matrix[i]; + } + + if(stack) + { + matrix4x4(matrix, m, stack); + } +} +*/ + +int +update_sgp(SceneGraphPack *_sgp, SceneGraphPack *sgp) +{ + SceneGraphNodePtr node; + + for (int i = 0; i < sgp->info.size; i++) { + //(*my_func[node->move])(node); + //(*my_func[node->interaction])(node, sgp); + + node = &sgp->node[i]; + + if (node->pn != -1) { + get_matrix(node->translation, + node->angle, node->obj_pos, + sgp->node[node->pn].translation); + } else { + get_matrix(node->translation, + node->angle, node->obj_pos, + NULL); + } + } + + // まあこれは多分駄目なんだけど。 + // in/out と update は分ける必要ある? + // それはユーザ側で in/out になるように書かせるもの? + memcpy(_sgp, sgp, sizeof(SceneGraphPack)); + + return sizeof(SceneGraphPack); +}
--- a/TaskManager/Test/simple_render/update_sgp.cpp Tue Feb 12 19:14:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -#include <iostream> -#include <math.h> -#include "scene_graph_pack.h" -#include "sys.h" -using namespace std; - -/* -void matrix4x4(float *xyz, float *xyz1, float *xyz2) //xyz[16] -{ - for(int t=0; t<16; t+=4) - { - for(int i=0; i<4; i++) - { - xyz[t+i] = xyz1[t]*xyz2[i] + xyz1[t+1]*xyz2[4+i] + xyz1[t+2]*xyz2[8+i] + xyz1[t+3]*xyz2[12+i]; - } - } -} - -void get_matrix( float *matrix, float *rxyz, float *txyz, float *stack) -{ - float radx,rady,radz; - radx = rxyz[0]*3.14/180; - rady = rxyz[1]*3.14/180; - radz = rxyz[2]*3.14/180; - - float sinx = sin(radx); - float cosx = cos(radx); - float siny = sin(rady); - float cosy = cos(rady); - float sinz = sin(radz); - float cosz = cos(radz); - - matrix[0] = cosz*cosy+sinz*sinx*siny; - matrix[1] =sinz*cosx; - matrix[2] = -cosz*siny+sinz*sinx*cosy; - matrix[3] = 0; - matrix[4] = -sinz*cosy+cosz*sinx*siny; - matrix[5] = cosz*cosx; - matrix[6] = sinz*siny+cosz*sinx*cosy; - matrix[7] = 0; - matrix[8] = cosx*siny; - matrix[9] = -sinx; - matrix[10] = cosx*cosy; - matrix[11] = 0; - matrix[12] = txyz[0]; - matrix[13] = txyz[1]; - matrix[14] = txyz[2]; - matrix[15] = 1; - - float m[16]; - - for(int i=0; i<16; i++) - { - m[i] = matrix[i]; - } - - if(stack) - { - matrix4x4(matrix, m, stack); - } -} -*/ - -int -update_sgp(SceneGraphPack *_sgp, SceneGraphPack *sgp) -{ - SceneGraphNodePtr node; - - for (int i = 0; i < sgp->info.size; i++) { - //(*my_func[node->move])(node); - //(*my_func[node->interaction])(node, sgp); - - node = &sgp->node[i]; - - if (node->pn != -1) { - get_matrix(node->translation, - node->angle, node->obj_pos, - sgp->node[node->pn].translation); - } else { - get_matrix(node->translation, - node->angle, node->obj_pos, - NULL); - } - } - - // まあこれは多分駄目なんだけど。 - // in/out と update は分ける必要ある? - // それはユーザ側で in/out になるように書かせるもの? - memcpy(_sgp, sgp, sizeof(SceneGraphPack)); - - return sizeof(SceneGraphPack); -}
--- a/TaskManager/Test/simple_render/viewer.cpp Tue Feb 12 19:14:00 2008 +0900 +++ b/TaskManager/Test/simple_render/viewer.cpp Tue Feb 12 19:19:06 2008 +0900 @@ -37,10 +37,6 @@ //manager = new TaskManager(1); //manager->init(); - - manager->set_symbol("CreateSGP", (void*)create_sgp); - manager->set_symbol("UpdateSGP", (void*)update_sgp); - manager->set_symbol("CreatePP", (void*)create_pp); } @@ -349,20 +345,9 @@ p->viewer = this; //p->screen = screen; - /* - p->next->viewer = this; - p->next->next->viewer = this; - p->next->next->next->viewer = this; - p->next->next->next->next->viewer = this; - p->next->next->next->next->next->viewer = this; - p->next->next->next->next->next->next->viewer = this; - p->next->next->next->next->next->next->next->viewer = this; - p->next->next->next->next->next->next->next->next->viewer = this; - p->next->next->next->next->next->next->next->next->next->viewer = this; - */ SceneGraphPack *sgp = new SceneGraphPack; - //create_sgp(sgp,p); + create_sgp(sgp,p); PolygonPack *pp = new PolygonPack; @@ -373,6 +358,10 @@ float y = 0; float z = 0; + bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32, + width*4, redMask, greenMask, + blueMask, alphaMask); + // Loop until done. while(1) { @@ -415,23 +404,25 @@ p->xyz[0] = x; p->xyz[1] = y; p->xyz[2] = z; - p->tree_draw(); + //p->tree_draw(); #if 0 - create_sgp(sgp, p); + //create_sgp(sgp, p); update_sgp(sgp, sgp); create_pp(pp, sgp); #else - fd_create_sgp = manager->open("CreateSGP"); + //fd_create_sgp = manager->open("CreateSGP"); fd_update_sgp = manager->open("UpdateSGP"); fd_create_pp = manager->open("CreatePP"); - task_create_sgp = - manager->create_task(fd_create_sgp, - sizeof(Polygon), - (unsigned int)p, - (unsigned int)sgp, - NULL); + /* + task_create_sgp = + manager->create_task(fd_create_sgp, + sizeof(Polygon), + (unsigned int)p, + (unsigned int)sgp, + NULL); + */ task_update_sgp = manager->create_task(fd_update_sgp, sizeof(SceneGraphPack), @@ -445,9 +436,9 @@ (unsigned int)pp, NULL); - manager->set_task_depend(task_create_sgp, task_update_sgp); - manager->set_task_depend(task_create_sgp, task_create_pp); - manager->spawn_task(task_create_sgp); + //manager->set_task_depend(task_create_sgp, task_update_sgp); + //manager->set_task_depend(task_create_sgp, task_create_pp); + //manager->spawn_task(task_create_sgp); manager->spawn_task(task_update_sgp); manager->spawn_task(task_create_pp); @@ -457,10 +448,13 @@ //p->draw(sgp); // test draw of SceneGraphPack p->draw(pp); // test draw of PolygonPack - bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32, - width*4, redMask, greenMask, - blueMask, alphaMask); - SDL_FillRect(screen, NULL, background); + // 一回のみ生成で、その後は再利用 + /* + bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32, + width*4, redMask, greenMask, + blueMask, alphaMask); + */ + //SDL_FillRect(screen, NULL, background); SDL_BlitSurface(bitmap, NULL, screen, NULL); SDL_UpdateRect(screen, 0, 0, 0, 0);