diff TaskManager/Test/simple_pack/viewer.cpp @ 68:35a6cf176c38

*** empty log message ***
author chiaki
date Sun, 17 Feb 2008 21:45:07 +0900
parents 0c8ae614d421
children c9b973f0673e
line wrap: on
line diff
--- a/TaskManager/Test/simple_pack/viewer.cpp	Sun Feb 17 19:04:29 2008 +0900
+++ b/TaskManager/Test/simple_pack/viewer.cpp	Sun Feb 17 21:45:07 2008 +0900
@@ -4,8 +4,6 @@
 #include <math.h>
 #include <unistd.h>
 #include "polygon.h"
-//#include "demonstration.h"
-//#include "scene.h"
 #include "viewer.h"
 #include "sys.h"
 using namespace std;
@@ -16,8 +14,8 @@
 #define alphaMask 0
 
 extern int create_sgp(Polygon *sg, SceneGraphPack *sgp);
-extern int update_sgp(SceneGraphPack *sgp, SceneGraphPack *_sgp);
-extern int create_pp(SceneGraphPack *sgp, PolygonPack *pp);
+//extern int update_sgp(SceneGraphPack *sgp, SceneGraphPack *_sgp);
+//extern int create_pp(SceneGraphPack *sgp, PolygonPack *pp);
 
 Viewer::Viewer(int b, int w, int h)
 {
@@ -72,31 +70,20 @@
 }
 
 
-void Viewer::write_pixel(int x, int y,float z, Uint32 rgb) {
+void
+Viewer::write_pixel(int x, int y,float z, Uint32 rgb)
+{
     SDL_PixelFormat *pf;
     pf = screen->format;
-    //printf("x:%d y:%d z:%d\n",x,y,z);
-
-    //cout << "write_pixel" << endl;
-    //cout << x << "  " << y << endl;
-
-    //cout << SDL_MapRGB(pf,0,0,150) << endl;
-
     x += width/2;
     y += height/2;
 
     static int diffz,diffz1;
+
     diffz1 = diffz;
     diffz = (zRow[x][y]>z);
-    if(diffz != diffz1) {
-	//printf("diffz :%d zRow[%d][%d] = %f z = %f\n",diffz,x,y,zRow[x][y],z);
-    }
-    //printf("x:%d,y:%d,z:%f,zRow:%f\n",x,y,z,zRow[x][y]);
-    if(z < zRow[x][y]) { 
-//	 printf("x:%d,y:%d,z:%d\n",x,y,z,zRow);
-	if(x < width && x > 0 && y > 0 && y < height)
-	{
-	    //pixels[width*y + x] = SDL_MapRGB(pf,70,70,71);
+    if (z < zRow[x][y]) { 
+	if (x < width && x > 0 && y > 0 && y < height) {
 	    zRow[x][y] = z;
 	    y = height - y;
 	    pixels[width*y + x] = rgb;
@@ -104,14 +91,10 @@
     }
 }
 
-void Viewer::write_line(float x1, float y1, float x2, float y2, Uint32 rgb)
+void
+Viewer::write_line(float x1, float y1, float x2, float y2, Uint32 rgb)
 {
-    //cout << "write_line("<< x1 << "," << y1 << "," << x2 << "," << y2 << ")"<< endl;
-
-    //Uint32 rgb = 9830400;
-
-    if(x1 > x2)
-    {
+    if (x1 > x2) {
 	float x=0;
 	float y=0;
 	x=x1;
@@ -121,71 +104,56 @@
 	x2 = x;
 	y2 = y;
     }
+
     float s = y1;
 
-    if((int)x1 == (int)x2)
-    {
-	if(y1 > y2)
-	{
+    if ((int)x1 == (int)x2) {
+	if (y1 > y2) {
 	    float y=0;
 	    y = y1;
 	    y1 = y2;
 	    y2 = y;
 	}
-	for(float i=y1; i<y2; i++)
-	{
+
+	for (float i=y1; i<y2; i++) {
 	    //write_pixel((int)x1,(int)i);
 	    write_pixel((int)x1,(int)i,0,rgb);
 	}
-    }
-    else 
-    {
+    } else {
 	float t = (y2 - y1)/(x2 - x1);
-	if(t < -1)
-	{
+	if (t < -1) {
 	    float f = 0;
-	    for(float i=x1; i<x2; i++)
-	    {
-		for(float a=(int)t; a<0; a++)
-		{
-		    //write_pixel((int)i,(int)s);
+	    for (float i=x1; i<x2; i++) {
+		for (float a=(int)t; a<0; a++) {
 		    write_pixel((int)i,(int)s,0,rgb);
 		    s--;
 		}
+
 		f += t-(int)t;
-		if(f <= -1)
-		{
-		    //write_pixel((int)i,(int)s);
+
+		if (f <= -1) {
 		    write_pixel((int)i,(int)s,0,rgb);
 		    f = 0;
 		    s--;
 		}
 	    }
-	}
-	else if(t <= 1)
-	{
-	    for(float i=x1; i<x2; i++)
-	    {
+	} else if (t <= 1) {
+	    for(float i=x1; i<x2; i++) {
 		//write_pixel((int)i,(int)s);
 		write_pixel((int)i,(int)s,0,rgb);
 		s += t;
 	    }
-	}
-	else
-	{
+	} else {
 	    float f = 0;
-	    for(float i=x1; i<x2; i++)
-	    {
-		for(float a=0; a<(int)t; a++)
-		{
-		    //write_pixel((int)i,(int)s);
+	    for (float i=x1; i<x2; i++) {
+		for (float a=0; a<(int)t; a++) {
 		    write_pixel((int)i,(int)s,0,rgb);
 		    s++;
 		}
+
 		f += t-(int)t;
-		if(f >= 1)
-		{
-		    //write_pixel((int)i,(int)s);
+
+		if (f >= 1) {
 		    write_pixel((int)i,(int)s,0,rgb);
 		    f = 0;
 		    s++;
@@ -234,15 +202,24 @@
 
 
 struct run_arg_t {
-    int start_time;
-    int this_time;
-    int frames;
-    SDL_Surface *bitmap;
-    SDL_PixelFormat *pf;
-    Uint32 background;
-    Polygon *p;
-    SceneGraphPack *sgp;
-    PolygonPack *pp;    
+  int start_time;
+  int this_time;
+  int frames;
+  SDL_Surface *bitmap;
+  SDL_PixelFormat *pf;
+  Uint32 background;
+  Polygon *p;
+  SceneGraphPack *sgp;
+  PolygonPack *pp;
+  SPANPACKLIST *spl;
+  SPANPACK *sp;
+  SPANPACK sps[135];
+  SPAN s1[250];
+  SPAN s2[250];
+  SPAN s3[250];
+  SPAN s4[250];
+  SPAN s5[250];
+  SPAN s6[250];
 };
 
 struct run_arg_t *arg;
@@ -254,9 +231,10 @@
     HTaskPtr task;
     int fd;
 
-    fprintf(stderr, " **  %s  **\n", __FUNCTION__);
+    arg->start_time = get_ticks();
+    arg->this_time  = 0;
+    arg->frames     = 0;
 
-    arg->start_time = get_ticks();
     arg->pf         = screen->format;
     arg->background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
     arg->p          = new Polygon;
@@ -265,9 +243,30 @@
     arg->sgp        = new SceneGraphPack;
     create_sgp(arg->p, arg->sgp);
     arg->pp         = new PolygonPack;
+    arg->sp         = new SPANPACK;
+    arg->spl        = new SPANPACKLIST;
+    arg->spl->size = 6;
+    //cout << "run_init   :spl->size = " << arg->spl->size << endl;
+    //arg->spl->dline = arg->sps;
+    /*
+    arg->spl->dline[0].span = arg->s1;
+    arg->spl->dline[1].span = arg->s2;
+    arg->spl->dline[2].span = arg->s3;
+    arg->spl->dline[3].span = arg->s4;
+    arg->spl->dline[4].span = arg->s5;
+    arg->spl->dline[5].span = arg->s6;
+    */
+    //cout << "run_init   :spl->dline[0].span = " << arg->spl->dline[0].span << endl;
+    
+    /*
+    for(int i=0; i<arg->spl->size; i++)
+      {
+	arg->spl->dline[i] = new SPANPACK;
+      }
+    */
 
     pixels = new Uint32[width*height];
-    
+
     graph_line();
 
     arg->bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32,
@@ -279,22 +278,41 @@
     manager->spawn_task(task);
 }
 
+/*
+void distribute_polygon_pack(int spu_num, PolygonPackList *ppl, PolygonPack *pp)
+{
+  ppl->list[0].info.size = 0;
+  ppl->list[1].info.size = 0;
+  ppl->list[2].info.size = 0;
+  ppl->list[3].info.size = 0;
+  ppl->list[4].info.size = 0;
+  ppl->list[5].info.size = 0;
+
+  for(int i=0; i<pp->info.size; i++)
+    {
+      int num = i%spu_num;
+      int mysize = ppl->list[num].info.size;
+      ppl->list[num].tri[mysize] = pp->tri[i];
+      ppl->list[num].info.size++;
+    }
+}
+*/
+
 void
 Viewer::run_loop(void)
 {
     HTaskPtr task_update_sgp = NULL;
     HTaskPtr task_create_pp = NULL;
+    HTaskPtr task_create_sp = NULL;
     HTaskPtr task_finish = NULL;
     int fd_update_sgp;
     int fd_create_pp;
+    int fd_create_sp;
     int fd_finish;
 
     HTaskPtr task;
     int fd;
 
-    fprintf(stderr, " **  %s  **\n", __FUNCTION__);
-
-
     if (quit_check()) {
 	arg->this_time = get_ticks();
 	fd_finish = manager->open("ViewerRunFinish");
@@ -310,6 +328,7 @@
 
     fd_update_sgp = manager->open("UpdateSGP");
     fd_create_pp  = manager->open("CreatePP");
+    fd_create_sp  = manager->open("CreateSP");
     fd = manager->open("ViewerRunDraw");
     task_update_sgp = manager->create_task(fd_update_sgp,
 					   sizeof(SceneGraphPack),
@@ -321,13 +340,23 @@
 					  (unsigned int)arg->sgp,
 					  (unsigned int)arg->pp,
 					  NULL);
+    //cout << "run_loop   :spl->size = " << arg->spl->size << endl;
+    //cout << "run_loop   :spl->dline[0].span = " << arg->spl->dline[0].span << endl;
+    task_create_sp = manager->create_task(fd_create_sp,
+					  sizeof(PolygonPack),
+					  (unsigned int)arg->pp,
+					  (unsigned int)arg->spl,
+					  NULL);
     task = manager->create_task(fd, 0, 0, 0, NULL);
 
     manager->set_task_depend(task_update_sgp, task);
     manager->set_task_depend(task_create_pp, task);
+    manager->set_task_depend(task_create_pp, task_create_sp);
+    manager->set_task_depend(task_create_sp, task);
 
     manager->spawn_task(task_update_sgp);
     manager->spawn_task(task_create_pp);
+    manager->spawn_task(task_create_sp);
     manager->spawn_task(task);
 }
 
@@ -337,15 +366,18 @@
     HTaskPtr task;
     int fd;
 
-
-    fprintf(stderr, " **  %s  **\n", __FUNCTION__);
+    //cout << "size = " << arg->sp->info.size << endl;
+    //cout << "span x = " << arg->sp->span[0].x << endl;
+    //printf("run_draw     x:%d y:%d end:%d z:%f zpos:%f\n", arg->sp->span[0].x, arg->sp->span[0].y, arg->sp->span[0].length_x, arg->sp->span[0].start_z , arg->sp->span[0].end_z);
+    //cout << endl;
 
-    arg->p->draw(arg->pp);    // test draw of PolygonPack
-	
+    //arg->p->draw(arg->pp);    // test draw of PolygonPack
+    //arg->p->draw(arg->sp);    // test draw of SpanPack
+    arg->p->draw(&arg->spl->dline[0]);    // test draw of SpanPackList
+
     SDL_BlitSurface(arg->bitmap, NULL, screen, NULL);
     SDL_UpdateRect(screen, 0, 0, 0, 0);    
 
-    //swap_buffers();
     arg->frames++;
 
     fd = manager->open("ViewerRunLoop");
@@ -356,10 +388,8 @@
 void
 Viewer::run_finish(void)
 {
-    fprintf(stderr, " **   %s   **\n", __FUNCTION__);
-
     if (arg->this_time != arg->start_time) {
-	cout<< ((float)arg->frames/(arg->this_time-arg->start_time))*1000.0 << " FPS\n";
+	cout<< (((float)arg->frames)/(arg->this_time-arg->start_time))*1000.0 << " FPS\n";
     }
 
     SDL_FreeSurface(arg->bitmap);
@@ -368,151 +398,13 @@
     delete arg->p;
     delete arg->sgp;
     delete arg->pp;
+    delete arg->spl;
+    delete arg->sp;
     quit();
 
     delete arg;
 }
 
-#if 0
-void Viewer::run()
-{
-    int frames = 0;
-    int start_time, this_time;
-
-    HTaskPtr task_create_sgp = NULL;
-    HTaskPtr task_update_sgp = NULL;
-    HTaskPtr task_create_pp = NULL;
-    int fd_create_sgp;
-    int fd_update_sgp;
-    int fd_create_pp;
-
-    start_time = get_ticks();
-
-    SDL_Surface *bitmap = NULL;
-    SDL_PixelFormat *pf;
-    pf = screen->format;
-
-    Uint32 background;
-    background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
-
-    pixels = new Uint32[width*height];
-
-    Polygon *p = new Polygon;
-    p->set_data("cube.xml");
-    //p->set_data("cube-p.xml");
-
-    p->viewer = this;
-    //p->screen = screen;
-
-    SceneGraphPack *sgp = new SceneGraphPack;
-    create_sgp(p, sgp);
-
-    PolygonPack *pp = new PolygonPack;
-
-    graph_line();
-
-    float r = 0;
-    float x = 0;
-    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)
-    {
-	// Destroy our GL context, etc.
-	//if(quit_check() || scene->action_scene==NULL)
-	if(quit_check())
-	{
-	    this_time = get_ticks();
-	    if (this_time != start_time) 
-	    {
-		cout<<((float)frames/(this_time-start_time))*1000.0<<" FPS\n";
-	    }
-	    SDL_FreeSurface(bitmap);
-	    delete pixels;
-	    p->delete_data();
-	    delete p;
-	    delete sgp;
-	    delete pp;
-	    quit();
-	    break;
-	}
-	/////////////////////
-	clean_pixels();
-
-	this->zRow_init();
-	graph_line();
-
-#if 0 // ここは update_sgp
-	if(r > 360) r = 0;
-	r+= 1.0;
-	// r= 0;
-	p->angle[0] = 0;
-	p->angle[1] = r;
-	p->angle[2] = 0;
-	//p->child->angle[1] = r*2;
-	//p->child->brother->angle[1] = r*3;
-	//p->child->brother->child->angle[1] = r*4;
-	x += 0.5;
-	y += 0.5;
-	z += 0.5;
-	p->xyz[0] = x;
-	p->xyz[1] = y;
-	p->xyz[2] = z;
-	//p->tree_draw();
-#endif
-
-#if 0
-	update_sgp(sgp, sgp);
-	create_pp(pp, sgp);
-#else
-	fd_update_sgp = manager->open("UpdateSGP");
-	fd_create_pp  = manager->open("CreatePP");
-	task_update_sgp =
-	    manager->create_task(fd_update_sgp,
-				 sizeof(SceneGraphPack),
-				 (unsigned int)sgp,
-				 (unsigned int)sgp,
-				 NULL);      
-	task_create_pp =
-	    manager->create_task(fd_create_pp,
-				 sizeof(SceneGraphPack),
-				 (unsigned int)sgp,
-				 (unsigned int)pp,
-				 NULL);
-
-	manager->spawn_task(task_update_sgp);
-	manager->spawn_task(task_create_pp);
-	manager->run();
-#endif
-
-	//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);
-	SDL_BlitSurface(bitmap, NULL, screen, NULL);
-	SDL_UpdateRect(screen, 0, 0, 0, 0);
-	
-
-	/////////////////////
-
-	//swap_buffers();
-	++frames;
-    }
-}
-#else
-void Viewer::run() {}
-#endif
-
 void
 Viewer::zRow_init()
 {