changeset 399:4bea73c83c35

fix viewer.cc (run_loop)
author game@henri.cr.ie.u-ryukyu.ac.jp
date Mon, 21 Sep 2009 18:03:31 +0900
parents e621024b6ef1
children 00fe05184a02 c29cbad1150d
files TaskManager/Test/test_render/viewer.cpp TaskManager/Test/test_render/viewer.h TaskManager/Test/test_render/viewerSDL.h
diffstat 3 files changed, 183 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/viewer.cpp	Sun Sep 20 19:21:04 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.cpp	Mon Sep 21 18:03:31 2009 +0900
@@ -11,12 +11,9 @@
 #include <wchar.h>
 #include "Pad.h"
 
-private void Viewer::initLoop();
-private void Viewer::mainLoop();
-private void Viewer::speLoop();
 static void post2runLoop(void *viewer);
 static void post2runDraw(void *viewer);
-static void post2runMove(void *viewer);
+//static void post2runMove(void *viewer);
 //static void post2exchange_sgroot(void *viewer);
 
 
@@ -26,7 +23,7 @@
 int frames;
 
 SceneGraphRootPtr sgroot;
-SceneGraphRootPtr sgroot_2;
+//SceneGraphRootPtr sgroot_2;
 
 /* Data Pack sent to Other CPUs (ex. SPE) */
 SceneGraphPack *sgpack;
@@ -43,6 +40,7 @@
 
 Viewer::Viewer(int b, int w, int h, int _num)
 {
+    //this->manager = manager;
     bpp = b;
     width = w;
     height = h;
@@ -115,7 +113,7 @@
     frames     = 0;
 
     sgroot = new SceneGraphRoot(this->width, this->height);
-    sgroot_2 = new SceneGraphRoot(this->width, this->height);
+    //sgroot_2 = new SceneGraphRoot(this->width, this->height);
     //sgroot->createFromXMLFile(xml);
 
     switch (sg_number) {
@@ -164,7 +162,7 @@
     case 16:
         chain_init(manager, this->width, this-> height);
 	speLoop();
-	return 1;
+	return;
         break;
     default:
         node_init(manager);
@@ -175,7 +173,7 @@
 }
 
 
-static void
+HTaskPtr
 Viewer::initLoop()
 {
     HTaskPtr task_next;
@@ -212,19 +210,7 @@
     }
 
     task_next = manager->create_task(TASK_DUMMY);
-
-
-#if 0
-    // 諸事情で、今は SceneGraphPack を作らずに
-    // そのまま SceneGraph でやっています
-    HTaskPtr task_sgp;
-    task_sgp = manager->create_task(TASK_CREATE_SGP);
-    task_sgp->add_param((uint32)scene_graph);
-    task_sgp->add_param((uint32)sgpack);
-    task_next->wait_for(task_sgp);
-    task_sgp->spawn();
-#endif
-
+    
     for (int i = 0; i < spe_num; i++) {
         task_tex = manager->create_task(TASK_INIT_TEXTURE);
         /*
@@ -234,24 +220,27 @@
         task_next->wait_for(task_tex);
         task_tex->spawn();
     }
+
+    return task_next;
 }
 
-static void
+void
 Viewer::speLoop()
 {
-    initLoop();
+    HTaskPtr task_next = initLoop();
 
-    task_next->set_post(&post2runLoop, (void *)this); // set_post(function(this->run_loop()), NULL)
+    // post2runLoop は旧バージョン用なので post2runspeLoop の様なものを別につくるべき
+    task_next->set_post(post2runLoop, (void *)this); // set_post(function(this->run_loop()), NULL)
     task_next->spawn();
     // TASK_INIT_TEXTURE が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ
 }
 
-static void
+void
 Viewer::mainLoop()
 {
-    initLoop();
+    HTaskPtr task_next = initLoop();
 
-    task_next->set_post(&post2runLoop, (void *)this); // set_post(function(this->run_loop()), NULL)
+    task_next->set_post(post2runLoop, (void *)this); // set_post(function(this->run_loop()), NULL)
     task_next->spawn();
     // TASK_INIT_TEXTURE が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ
 
@@ -264,7 +253,7 @@
     
     task_next->wait_for(RUN_MOVE_TASK);
     task_next->wait_for(RUN_DRAW_TASK);
-    task_next->set_post(&post2runExchange, (void *)this);
+    task_next->set_post(post2runExchange, (void *)this);
     task_next->spawn();
     */
 }
@@ -313,20 +302,23 @@
 void 
 Viewer::rendering(HTaskPtr task_next)
 {
+    printf("start rendering\n");
     HTaskPtr task_create_pp = NULL;
     HTaskPtr task_create_sp = NULL;
     
     // SceneGraph(木構造) -> PolygonPack
     task_create_pp = manager->create_task(TASK_CREATE_PP2);
-    task_create_pp->add_param((uint32)sgroot_2->getDrawSceneGraph());
+    task_create_pp->add_param((uint32)sgroot->getDrawSceneGraph());
     task_create_pp->add_param((uint32)ppack);
 
-    //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;
 
+    printf("rendering 1\n");
+
     for (int i = 0; i < range_base; i++) {
         int index_start = range*i;
         int index_end = (index_start + range >= spackList_length)
@@ -364,7 +356,9 @@
     // Barrier 同期
     // run_draw() を呼ぶ post2runDraw
     task_next->set_post(post2runDraw, (void*)this); // set_post(function(this->run_draw()), NULL)
+    printf("rendering 2\n");
     task_next->spawn();
+    printf("task_next\n");
     // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ
 }
 
@@ -394,18 +388,160 @@
         spackList[i-1].reinit(i*split_screen_h);
     }
         
-    run_move(task_next);
-    //sgroot->updateControllerState();
-    //sgroot->allExecute(width, height);
+    //run_move(task_next);
+    sgroot->updateControllerState();
+    sgroot->allExecute(width, height);
     //sgroot->checkRemove();
 
     // ここから下は Rendering という関数にする
+    printf("run_loop\n");
     rendering(task_next);
 }
 
-static void
+/*
+void
+Viewer::run_loop(HTaskPtr task_next)
+{
+    HTaskPtr task_create_pp  = NULL;
+    HTaskPtr task_create_sp  = NULL;
+    //HTaskPtr task_next;
+    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);
+
+    // 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)ppack);
+
+    task_next->wait_for(task_create_pp);
+    int range_base = spe_num;
+    // 切り上げのつもり                                                                                                     
+    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;
+
+        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*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_create_sp->set_cpu(SPE_ANY);
+        task_create_sp->spawn();
+    }
+
+    task_create_pp->spawn();
+
+    // Barrier 同期                                                                                                         
+    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_loop(HTaskPtr task_next)
+{
+    HTaskPtr task_create_pp  = NULL;
+    HTaskPtr task_create_sp  = NULL;
+    HTaskPtr task_next;
+    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);
+
+    // 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)ppack);
+
+    task_next->wait_for(task_create_pp);
+
+    int range_base = spe_num;
+    // 切り上げのつもり               
+    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;
+
+        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*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_create_sp->set_cpu(SPE_ANY);
+        task_create_sp->spawn();
+    }
+
+    task_create_pp->spawn();
+
+    // Barrier 同期                                                                                                         
+    task_next->set_post(post2runDraw, NULL); // set_post(function(this->run_draw()), NULL)                                  
+    task_next->spawn();
+    // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ                                            
+}
+*/
+
+static void 
 post2runDraw(void *viewer_)
 {
+    printf("post2runDraw 1\n");
     Viewer *viewer = (Viewer*)viewer_;
     HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY);
     viewer->run_draw(task_next);
@@ -415,10 +551,11 @@
 void
 Viewer::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする
 {
+    printf("start run_draw\n");
     HTaskPtr task_draw;
 
     //task_next = manager->create_task(TASK_DUMMY);
-    //task_next->set_post(post2runLoop, NULL);
+    //task_next->set_post(post2runLoop, (void*)this);
 
     ppack->clear();
     for (int i = 0; i < spackList_length; i++) {
@@ -446,7 +583,6 @@
 		break;
             }
 
-
 	    task_next->spawn();
             task_draw->add_param(startx);
             task_draw->add_param(endx);
@@ -466,10 +602,11 @@
     
 
     task_next->set_post(post2runLoop, (void*)this); // set_post(function(this->run_loop()), NULL)
-    task_next->spawn(); 
-    // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ
+    task_next->spawn();
+    // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ    
 
     frames++;
+    printf("end run_draw\n");
 }
 
 void
@@ -480,6 +617,6 @@
     }
 
     delete sgroot;
-    delete sgroot_2;
+    //delete sgroot_2;
     quit();
 }
--- a/TaskManager/Test/test_render/viewer.h	Sun Sep 20 19:21:04 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.h	Mon Sep 21 18:03:31 2009 +0900
@@ -8,6 +8,7 @@
 
 class Viewer {
 public:
+    //Viewer(TaskManager *manager, int bpp, int width, int height, int spenum);
     Viewer(int bpp, int width, int height, int spenum);
 
     virtual ~Viewer(void) {}
@@ -43,6 +44,11 @@
     virtual void run_collision();
     virtual void rendering(HTaskPtr task_next);
     //virtual void exchange_sgroot(TaskManager *manager);
+private:
+    HTaskPtr initLoop();
+    void mainLoop();
+    void speLoop();
+
 };
 
 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
--- a/TaskManager/Test/test_render/viewerSDL.h	Sun Sep 20 19:21:04 2009 +0900
+++ b/TaskManager/Test/test_render/viewerSDL.h	Mon Sep 21 18:03:31 2009 +0900
@@ -5,7 +5,7 @@
 
 class ViewerSDL : public Viewer {
 public:
-ViewerSDL(TaskManager *manager, int bpp, int width, int height, int spenum)
+ViewerSDL(TaskManager* manager, int bpp, int width, int height, int spenum)
     :Viewer(bpp, width, height, spenum) {}
 
     SDL_Surface *screen;