Mercurial > hg > Game > Cerium
changeset 728:c7afc21e448d draft
add Engine/ViewerDevice , SgRootChange not work
author | aaa |
---|---|
date | Sat, 19 Dec 2009 20:32:02 +0900 |
parents | ba00ee770616 |
children | 91e2c96be77b |
files | Renderer/Engine/Application.h Renderer/Engine/SgChange.cc Renderer/Engine/SgChange.h Renderer/Engine/SgMain.cc Renderer/Engine/ViewerDevice.cc Renderer/Engine/ViewerDevice.h Renderer/Engine/main.cc Renderer/Engine/sgchangeFB.cc Renderer/Engine/sgchangeFB.h Renderer/Engine/sgchangeSDL.cc Renderer/Engine/sgchangeSDL.h Renderer/Engine/viewer.cc Renderer/Engine/viewer.h Renderer/Engine/viewerFB.cc Renderer/Engine/viewerFB.h Renderer/Engine/viewerSDL.cc Renderer/Engine/viewerSDL.h Renderer/Test/SgRootChange.cc Renderer/Test/SgRootChange.h Renderer/Test/ball_bound.cc Renderer/Test/ball_bound.h |
diffstat | 21 files changed, 204 insertions(+), 688 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/Application.h Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/Application.h Sat Dec 19 20:32:02 2009 +0900 @@ -4,13 +4,11 @@ #include "SceneGraph.h" #include "MainLoop.h" #include "viewer.h" -#include "SgChange.h" typedef void (*Move_func)(SceneGraph* node, int screen_w, int screen_h); typedef void (*Coll_func)(SceneGraph* node, int screen_w, int screen_h, SceneGraphPtr tree); class Viewer; -class SgChange; class Application { public: @@ -18,7 +16,6 @@ virtual ~Application(); virtual MainLoopPtr init(Viewer *viewer, int w, int h) = 0; - virtual MainLoopPtr init_only_sg(SgChange *sgchange, int w, int h) = 0; }; #endif
--- a/Renderer/Engine/SgChange.cc Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/SgChange.cc Sat Dec 19 20:32:02 2009 +0900 @@ -33,121 +33,21 @@ extern int spackList_length; extern int spackList_length_align; -SgChange::SgChange(int b, int w, int h, int _num) -{ - bpp = b; - width = w; - height = h; - spe_num = _num; -} - -int -SgChange::get_ticks(void) -{ - int time; - time = SDL_GetTicks(); - return time; -} - -bool -SgChange::quit_check(void) -{ - SDL_Event event; - - while(SDL_PollEvent(&event)) { - if (event.type==SDL_QUIT) { - return true; - } - } - - Uint8 *keys=SDL_GetKeyState(NULL); - - if (keys[SDLK_q] == SDL_PRESSED) { - return true; - } - - return false; -} - void -SgChange::quit(void) -{ - SDL_Quit(); -} - - - -void -SgChange::run_init(TaskManager *manager, Application *app) +SgChange::run_init() { - this->manager = manager; - - start_time = get_ticks(); - this_time = 0; - frames = 0; - - // ココ! - sgroot_A = new SceneGraphRoot(this->width, this->height); - sgroot_A->tmanager = manager; - sgroot_B = new SceneGraphRoot(this->width, this->height); - sgroot_B->tmanager = manager; - - int size = sizeof(float)*4; - light_xyz[0] = 0.0f; - light_xyz[1] = 0.0f; - light_xyz[2] = 0.0f; - light_xyz[3] = 0.0f; - - HTaskPtr data_load; - for(int i = 0; i < spe_num; i++) { - data_load = manager->create_task(DataLoad); - data_load->set_param(0, (memaddr)size); - data_load->set_param(1, (memaddr)LOAD_ID); - data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); - data_load->spawn(); - } - - MainLoop *mainloop = app->init_only_sg(this, this->width, this->height); - - mainloop->mainLoop(); + int width = viewer->width; + int height = viewer->height; + sgroot_A = new SceneGraphRoot(width, height); + sgroot_A->tmanager = viewer->manager; + sgroot_B = new SceneGraphRoot(width, height); + sgroot_B->tmanager = viewer->manager; } HTaskPtr SgChange::initLoop() { - HTaskPtr task_next; - HTaskPtr task_tex; - - sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); - sgpack->init(); - ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); - - spackList_length = (this->height + split_screen_h - 1) / split_screen_h; - spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length); - - spackList_length_align = (spackList_length + 3)&(~3); - - spackList_ptr = - (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); - - for (int i = 0; i < spackList_length; i++) { - spackList_ptr[i] = &spackList[i]; - } - - for (int i = 1; i <= spackList_length; i++) { - spackList[i-1].init(i*split_screen_h); - } - - task_next = manager->create_task(Dummy); - - for (int i = 0; i < spe_num; i++) { - task_tex = manager->create_task(LoadTexture); - task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); - task_next->wait_for(task_tex); - task_tex->spawn(); - } - - return task_next; + return viewer->initLoop(); } void @@ -162,11 +62,11 @@ static void -post2runLoop(SchedTask *s, void *viewer_, void *arg) +post2runLoop(SchedTask *s, void *sgchange_, void *arg) { - SgChange *viewer = (SgChange*)viewer_; - HTaskPtr task_next = viewer->manager->create_task(Dummy); - viewer->run_loop(task_next); + SgChange *sgchange = (SgChange*)sgchange_; + HTaskPtr task_next = sgchange->manager->create_task(Dummy); + sgchange->run_loop(task_next); psx_sync_n(); } @@ -184,35 +84,24 @@ SgChange::run_loop(HTaskPtr task_next) { bool quit_flg; - quit_flg = quit_check(); + quit_flg = viewer->quit_check(); if (quit_flg == true) { - this_time = get_ticks(); - run_finish(); + this_time = viewer->get_ticks(); + viewer->run_finish(); return; } - clean_pixels(); + viewer->clean_pixels(); for (int i = 1; i <= spackList_length; i++) { spackList[i-1].reinit(i*split_screen_h); } -#if 0 - exchange_sgroot(); - light_xyz_stock = sgroot_A->getLightVector(); - - //printf("Sgroot = %x\n", sgroot_A); - - //task_next->set_post(&post2runLoop, (void *)this, 0); - //task_next->spawn(); - - rendering(task_next); -#else //exchange_sgroot(); sgroot_A->updateControllerState(); - sgroot_A->allExecute(width, height); - light_xyz_stock = sgroot_A->getLightVector(); + sgroot_A->allExecute(viewer->width, viewer->height); + viewer->light_xyz_stock = sgroot_A->getLightVector(); HTaskPtr loop_task = manager->create_task(Dummy); loop_task->set_post(post2runLoop, (void *)this, 0); @@ -225,14 +114,13 @@ HTaskPtr dummy_task = manager->create_task(Dummy); - this->dummy_task = dummy_task; - loop_task->wait_for(dummy_task); + draw_finish = dummy_task; + loop_task->wait_for(draw_finish); loop_task->wait_for(move_task); move_task->spawn(); draw_task->spawn(); loop_task->spawn(); -#endif } static void @@ -246,192 +134,47 @@ void SgChange::run_move(HTaskPtr task_next) { - //sgroot_A->updateControllerState(); - //sgroot_A->allExecute(width, height); + sgroot_A->updateControllerState(); + sgroot_A->allExecute(viewer->width, viewer->height); } static void -post2rendering(SchedTask *s, void *viewer_, void *arg) +post2rendering(SchedTask *s, void *sgchange_, void *arg) { - SgChange *viewer = (SgChange *)viewer_; - HTaskPtr task_next = viewer->manager->create_task(Dummy); - viewer->rendering(task_next); + SgChange *sgchange = (SgChange *)sgchange_; + HTaskPtr task_next = sgchange->manager->create_task(Dummy); + sgchange->rendering(task_next); } void SgChange::rendering(HTaskPtr task_next) { - common_rendering(task_next); + viewer->common_rendering(task_next, sgroot_A); task_next->set_post(post2runDraw, (void*)this, 0); task_next->spawn(); } -void -SgChange::common_rendering(HTaskPtr task_next) -{ - HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); - - //task_create_pp->set_param(0, (memaddr)sgroot_B->getDrawSceneGraph()); - task_create_pp->set_param(0, (memaddr)sgroot_A->getDrawSceneGraph()); - task_create_pp->set_param(1, (memaddr)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; - - HTaskPtr task_create_sp = manager->create_task(CreateSpan); - - task_create_sp->set_param(0,index_start); - - task_create_sp->set_param(1,index_start*split_screen_h + 1); - task_create_sp->set_param(2,index_end*split_screen_h); - - 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_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(); -} - static void -post2runDraw(SchedTask *s, void *viewer_, void *arg) +post2runDraw(SchedTask *s, void *sgchange_, void *arg) { - SgChange *viewer = (SgChange *)viewer_; - HTaskPtr task_next = viewer->manager->create_task(Dummy); - viewer->run_draw(task_next); + SgChange *sgchange = (SgChange *)sgchange_; + HTaskPtr task_next = sgchange->manager->create_task(Dummy); + sgchange->run_draw(task_next); } void SgChange::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする { - common_draw(task_next); + viewer->common_draw(task_next); -#if 0 - task_next->set_post(post2runLoop, (void*)this, 0); // set_post(function(this->run_loop()), NULL) + this->draw_finish->wait_for(task_next); task_next->spawn(); -#else - this->dummy_task->wait_for(task_next); - task_next->spawn(); - this->dummy_task->spawn(); -#endif + this->draw_finish->spawn(); frames++; } -void -SgChange::common_draw(HTaskPtr task_next) -{ - HTaskPtr task_draw; - - //Light info update - HTaskPtr data_update; - HTaskPtr data_update_wait; - int size = sizeof(float)*4; - - light_xyz[0] = light_xyz_stock[0]; - light_xyz[1] = light_xyz_stock[1]; - light_xyz[2] = light_xyz_stock[2]; - light_xyz[3] = light_xyz_stock[3]; - - data_update_wait = manager->create_task(DataUpdate); - data_update_wait->add_inData(light_xyz, size); - data_update_wait->set_param(0, size); - data_update_wait->set_param(1, LOAD_ID); - data_update_wait->set_cpu((CPU_TYPE)((int)SPE_0)); - - for (int i = 1; i < spe_num; i++) { - data_update = manager->create_task(DataUpdate); - data_update->add_inData(light_xyz, sizeof(float)*size); - data_update->set_param(0, size); - data_update->set_param(1, LOAD_ID); - data_update->set_cpu((CPU_TYPE)((int)SPE_0 + i)); - data_update_wait->wait_for(data_update); - data_update->spawn(); - } - - data_update_wait->spawn(); - - ppack->clear(); - for (int i = 0; i < spackList_length; i++) { - 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; - - while (startx < this->width) { - if (spack->info.size > 0) { - // Draw SpanPack - task_draw = manager->create_task(DrawSpan); - - task_draw->set_param(0, - (memaddr)&pixels[(startx-1) + this->width*(starty-1)]); - task_draw->set_param(1,this->width); - task_draw->set_param(2,startx); - task_draw->set_param(3,endx); - task_draw->set_param(4,rangey); - - task_draw->add_inData(spack, sizeof(SpanPack)); - - for (int i = 0; i < rangey; i++) { - task_draw->add_outData( - &pixels[(startx-1) + this->width*(starty-1 + i) ], - (endx-startx+1)*sizeof(int)); - } - } else { - // 7.7.3 SL1 Data Cache Range Set to Zero コマンド - // を使って、DMAでclearするべき... ということは、 - // それもSPEでやる方が良い? - memset(&pixels[(startx-1)+this->width*(starty-1)], - 0, (this->width)*sizeof(int)*rangey); - break; - } - - task_draw->set_cpu(SPE_ANY); - task_next->wait_for(task_draw); - task_draw->wait_for(data_update_wait); - task_draw->spawn(); - - startx += split_screen_w; - endx += split_screen_w; - - if (endx > this->width) { - endx = this->width; - } - } - } -} - -void -SgChange::run_finish(void) -{ - if (this_time != start_time) { - printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); - } - - delete sgroot_A; - //delete sgroot_B; - quit(); -} - /* end */
--- a/Renderer/Engine/SgChange.h Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/SgChange.h Sat Dec 19 20:32:02 2009 +0900 @@ -9,60 +9,39 @@ #include "MainLoop.h" #include "Application.h" #include "SceneGraphRoot.h" +#include "viewer.h" class SceneGraphRoot; - class Application; class SgChange : public MainLoop { public: - SgChange(int bpp, int width, int height, int spenum); + Viewer *viewer; + TaskManager *manager; + + SgChange(Viewer *v) { + viewer = v; + manager = v->manager; + } virtual ~SgChange() {} - Application *app; - - TaskManager *manager; - key_stat *keyPtr; - HTaskPtr dummy_task; SceneGraphRoot *sgroot_A; SceneGraphRoot *sgroot_B; - /* screen info */ - int width; - int height; - int bpp; - - int spe_num; - - float light_xyz[4] __attribute__((aligned(16))); - float *light_xyz_stock; - - int rgb_size[3]; - Uint32 video_flags; - Uint32 *pixels; + HTaskPtr draw_finish; - virtual void video_init(TaskManager *manager) = 0; - void init(); - - int get_ticks(); - bool quit_check(); - void quit(); - - virtual void clean_pixels() {} + void run_init(); + void run_loop(HTaskPtr task_next); + void run_move(HTaskPtr task_next); + void run_draw(HTaskPtr task_next); + void rendering(HTaskPtr task_next); + HTaskPtr initLoop(); - virtual void run_init(TaskManager *manager, Application *app); - virtual void run_loop(HTaskPtr task_next); - virtual void run_finish(); - virtual void run_draw(HTaskPtr task_next); - virtual void run_move(HTaskPtr task_next); virtual void exchange_sgroot(); - virtual void rendering(HTaskPtr task_next); - virtual void common_draw(HTaskPtr task_next); - virtual void common_rendering(HTaskPtr task_next); void mainLoop(); void createFromXMLfile(const char *file) @@ -99,16 +78,7 @@ { return sgroot_A->getLast(); } - - - - -private: - HTaskPtr initLoop(); }; -#define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK - - #endif
--- a/Renderer/Engine/SgMain.cc Sat Dec 19 17:11:43 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -#include "TaskManager.h" -#include "SgChange.h" -#include "sgchangeSDL.h" -#include "sgchangeFB.h" -#include "Application.h" - -/* prototype */ -extern void task_initialize(); -extern Application *application(); -extern int sg_init(TaskManager *manager, int argc, char *argv[]); - -int -sg_init(TaskManager *manager, int argc, char *argv[]) -{ - int bpp = 32; - int width = 640; - int height = 480; - int spenum = 1; - video_type vtype = VTYPE_SDL; - - for(int i = 1; argv[i]; ++i) - { - if (strcmp(argv[i], "-bpp") == 0) { - bpp = atoi(argv[++i]); - } - if (strcmp(argv[i], "-width") == 0) { - width = atoi(argv[++i]); - } - if (strcmp(argv[i], "-height") == 0) { - height = atoi(argv[++i]); - } - if (strcmp(argv[i], "-cpu") == 0) { - spenum = atoi(argv[++i]); - } - if (strcmp(argv[i], "-video") == 0) { - if (strcmp(argv[i+1], "sdl") == 0) { - vtype = VTYPE_SDL; - } else if (strcmp(argv[i+1], "fb") == 0) { - vtype = VTYPE_FB; - } - i++; - } - } - - /* - SgChange *screen = new SgChange(bpp, width, height, spenum); - screen->run_init(manager, application()); - */ - - SgChange *screen; - if (vtype == VTYPE_SDL) { - screen = new SgChangeSDL(manager, bpp, width, height, spenum); - } else if (vtype == VTYPE_FB) { - screen = new SgChangeFB(manager, bpp, width, height, spenum); - }else{ - screen = new SgChangeSDL(manager, bpp, width, height, spenum); - } - - screen->video_init(manager); - screen->run_init(manager, application()); - - return 0; -} - -#if 0 - -// These are defined in Application - -int -TMmain(TaskManager *manager, int argc, char *argv[]) -{ - task_initialize(); - manager->set_TMend(TMend); - return init(manager, argc, argv); - -} - -void -TMend(TaskManager *manager) -{ - printf("test_nogl end\n"); -} - -#endif - -/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/ViewerDevice.cc Sat Dec 19 20:32:02 2009 +0900 @@ -0,0 +1,9 @@ +#include "ViewerDevice.h" + +ViewerDevice::ViewerDevice() +{ +} + +ViewerDevice::~ViewerDevice() +{ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/ViewerDevice.h Sat Dec 19 20:32:02 2009 +0900 @@ -0,0 +1,21 @@ +#ifndef INCLUDED_VIEWER_DEV +#define INCLUDED_VIEWER_DEV + +#include "TaskManager.h" +#include "SDL.h" + +class ViewerDevice { +public: + ViewerDevice(); + virtual ~ViewerDevice(); + + ViewerDevice(TaskManager *m) {}; + + /* override function */ + virtual Uint32 *video_init(TaskManager *manager, int bpp, int width, int height) = 0; + virtual void clean_pixels() = 0; + virtual void clear_screen() = 0; + virtual void free_device() = 0; +}; + +#endif
--- a/Renderer/Engine/main.cc Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/main.cc Sat Dec 19 20:32:02 2009 +0900 @@ -63,17 +63,18 @@ Viewer *screen; if (vtype == VTYPE_SDL) { - screen = new ViewerSDL(manager, bpp, width, height, spenum); + ViewerDevice *dev = new ViewerSDL(manager); + screen = new Viewer(manager, dev, bpp, width, height, spenum); } else if (vtype == VTYPE_FB) { - screen = new ViewerFB(manager, bpp, width, height, spenum); + ViewerDevice *dev = new ViewerFB(manager); + screen = new Viewer(manager, dev, bpp, width, height, spenum); }else{ - screen = new ViewerSDL(manager, bpp, width, height, spenum); + ViewerDevice *dev = new ViewerSDL(manager); + screen = new Viewer(manager, dev, bpp, width, height, spenum); } - - screen->video_init(manager); + screen->run_init(manager, application()); - return 0; }
--- a/Renderer/Engine/sgchangeFB.cc Sat Dec 19 17:11:43 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -#include "sgchangeFB.h" -#include "Func.h" -#include "fb.h" - -//extern void post2runLoop(void *); - -void -SgChangeFB::video_init(TaskManager *manager) -{ - Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; - - if (SDL_Init(sdl_flag) < 0) { - fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError()); - exit(1); - } - - pixels = (Uint32*)get_fbdev_addr(); - - if (pixels == 0) { - pixels = (new Uint32[width*height*32/8]); - } -} - -void -SgChangeFB::clean_pixels() -{ - //bzero(pixels, sizeof(int)*width*height); - //memset(pixels, 0xFF, sizeof(int)*width*height); -}
--- a/Renderer/Engine/sgchangeFB.h Sat Dec 19 17:11:43 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#ifndef INCLUDED_SGCHANGE_FB -#define INCLUDED_SGCHANGE_FB - -#include "SgChange.h" - -class SgChangeFB : public SgChange { -public: -SgChangeFB(TaskManager *manager, int bpp, int width, int height, int spenum) - :SgChange(bpp, width, height, spenum) {} - - /* override function */ - void video_init(TaskManager *manager); - void clean_pixels(void); -}; - -#endif
--- a/Renderer/Engine/sgchangeSDL.cc Sat Dec 19 17:11:43 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -#include "sgchangeSDL.h" -#include "Func.h" -#include "TaskManager.h" - -extern void post2runLoop(void *); - -extern - -void -SgChangeSDL::video_init(TaskManager *manager) -{ - Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; - Uint32 *p; - - if (SDL_Init(sdl_flag) < 0) { - fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); - } - - screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE); - if (screen == NULL) { - fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); - SDL_Quit(); - exit(1); - } - - p = (Uint32*)manager->allocate(screen->pitch*height); - bitmap = SDL_CreateRGBSurfaceFrom((void *)p, - screen->w, screen->h, - screen->format->BitsPerPixel, - screen->pitch, - redMask, greenMask, blueMask, alphaMask); - - pixels = p; -} - -void -SgChangeSDL::clean_pixels() -{ - //bzero(pixels, sizeof(int)*width*height); - SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); -} - -void -SgChangeSDL::run_loop(HTaskPtr task_next) -{ - SDL_BlitSurface(bitmap, NULL, screen, NULL); - SDL_UpdateRect(screen, 0, 0, 0, 0); - - SgChange::run_loop(task_next); -} - -void -SgChangeSDL::run_finish() -{ - free(bitmap->pixels); - SDL_FreeSurface(bitmap); - - SgChange::run_finish(); -}
--- a/Renderer/Engine/sgchangeSDL.h Sat Dec 19 17:11:43 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#ifndef INCLUDED_SGCHANGE_SDL -#define INCLUDED_SGCHANGE_SDL - -#include "SgChange.h" - -class SgChangeSDL : public SgChange { -public: -SgChangeSDL(TaskManager* manager, int bpp, int width, int height, int spenum) - :SgChange(bpp, width, height, spenum) {} - - SDL_Surface *screen; - SDL_Surface *bitmap; - - /* override function */ - void video_init(TaskManager *manager); - void clean_pixels(); - void run_loop(HTaskPtr task_next); - void run_finish(); -}; - -#endif
--- a/Renderer/Engine/viewer.cc Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/viewer.cc Sat Dec 19 20:32:02 2009 +0900 @@ -44,12 +44,15 @@ * */ -Viewer::Viewer(int b, int w, int h, int _num) +Viewer::Viewer(TaskManager *m, ViewerDevice *vd, int b, int w, int h, int _num) { bpp = b; width = w; height = h; spe_num = _num; + manager = m; + dev = vd; + pixels = dev->video_init(manager, b, w, h); } @@ -258,16 +261,6 @@ } -#if 0 -static void -post2speRunLoop(void *viewer_) -{ - Viewer *viewer = (Viewer *)viewer_; - HTaskPtr task_next = viewer->manager->create_task(Dummy); - viewer->run_move(task_next); -} -#endif - void Viewer::mainLoop() { @@ -277,23 +270,35 @@ task_next->spawn(); } -#if 0 void -post2runMove(void *viewer_) +Viewer::run_loop(HTaskPtr task_next) { - Viewer *viewer = (Viewer*)viewer_; - HTaskPtr task_next = viewer->manager->create_task(Dummy); - viewer->run_move(task_next); + dev->clear_screen(); + + bool quit_flg; + quit_flg = quit_check(); + if (quit_flg == true) { + this_time = get_ticks(); + run_finish(); + return; + } + + dev->clean_pixels(); + + for (int i = 1; i <= spackList_length; i++) { + spackList[i-1].reinit(i*split_screen_h); + } + + sgroot->updateControllerState(); + sgroot->allExecute(width, height); + light_xyz_stock = sgroot->getLightVector(); + //sgroot->checkRemove(); + + // ここから下は Rendering という関数にする + rendering(task_next); } -#endif -void -Viewer::run_move(HTaskPtr task_next) -{ - sgroot->updateControllerState(); - sgroot->allExecute(width, height); -} void Viewer::run_collision() @@ -311,7 +316,7 @@ void Viewer::rendering(HTaskPtr task_next) { - common_rendering(task_next); + common_rendering(task_next, sgroot); // Barrier 同期 // run_draw() を呼ぶ post2runDraw @@ -331,33 +336,6 @@ psx_sync_n(); } -void -Viewer::run_loop(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); - } - - //run_move(task_next); - sgroot->updateControllerState(); - sgroot->allExecute(width, height); - light_xyz_stock = sgroot->getLightVector(); - //sgroot->checkRemove(); - - // ここから下は Rendering という関数にする - rendering(task_next); -} - static void post2runDraw(SchedTask *s, void *viewer_, void *arg) { @@ -379,17 +357,6 @@ frames++; } -void -Viewer::run_finish(void) -{ - if (this_time != start_time) { - printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); - } - - delete sgroot; -// delete sgroot_2; - quit(); -} static void post2speRendering(SchedTask *s, void *viewer_, void *arg) @@ -402,7 +369,7 @@ void Viewer::spe_rendering(HTaskPtr task_next) { - common_rendering(task_next); + common_rendering(task_next, sgroot); this->draw_dummy->wait_for(task_next); task_next->set_post(post2speDraw, (void*)this, 0); @@ -431,7 +398,7 @@ } void -Viewer::common_rendering(HTaskPtr task_next) +Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot) { HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); @@ -577,4 +544,17 @@ } +void +Viewer::run_finish() +{ + dev->free_device(); + if (this_time != start_time) { + printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); + } + + delete sgroot; +// delete sgroot_2; + quit(); +} + /* end */
--- a/Renderer/Engine/viewer.h Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/viewer.h Sat Dec 19 20:32:02 2009 +0900 @@ -9,6 +9,7 @@ #include "MainLoop.h" #include "Application.h" #include "SceneGraphRoot.h" +#include "ViewerDevice.h" class SceneGraphRoot; @@ -18,10 +19,11 @@ public: - Viewer(int bpp, int width, int height, int spenum); + Viewer(TaskManager *manager, ViewerDevice *dev, int bpp, int width, int height, int spenum); virtual ~Viewer() {} + ViewerDevice *dev; Application *app; TaskManager *manager; @@ -44,28 +46,29 @@ SceneGraphRoot *sgroot; - virtual void video_init(TaskManager *manager) = 0; + //Uint32 *video_init(TaskManager *manager, int bpp, int width, int height); void init(); int get_ticks(); bool quit_check(); void quit(); - - virtual void clean_pixels() {} + HTaskPtr initLoop(); - virtual void run_init(TaskManager *manager, Application *app); - virtual void run_loop(HTaskPtr task_next); - virtual void run_draw(HTaskPtr task_next); - virtual void run_finish(); - virtual void run_move(HTaskPtr task_next); - virtual void run_collision(); - virtual void rendering(HTaskPtr task_next); - virtual void common_draw(HTaskPtr task_next); - virtual void common_rendering(HTaskPtr task_next); + void clean_pixels() {} + + void run_init(TaskManager *manager, Application *app); + void run_loop(HTaskPtr task_next); + void run_draw(HTaskPtr task_next); + void run_finish(); + void run_move(HTaskPtr task_next); + void run_collision(); + void rendering(HTaskPtr task_next); + void common_draw(HTaskPtr task_next); + void common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot); - virtual void spe_rendering(HTaskPtr task_next); - virtual void spe_draw(HTaskPtr task_next); - //virtual void exchange_sgroot(TaskManager *manager); + void spe_rendering(HTaskPtr task_next); + void spe_draw(HTaskPtr task_next); + // void exchange_sgroot(TaskManager *manager); void getKey(); void get_send_controll(); @@ -116,12 +119,6 @@ return sgroot->getLast(); } - - - -private: - HTaskPtr initLoop(); - }; #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
--- a/Renderer/Engine/viewerFB.cc Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/viewerFB.cc Sat Dec 19 20:32:02 2009 +0900 @@ -1,11 +1,13 @@ #include "viewerFB.h" -#include "Func.h" #include "fb.h" +#define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK //extern void post2runLoop(void *); +ViewerFB::ViewerFB() {} +ViewerFB::~ViewerFB() {} -void -ViewerFB::video_init(TaskManager *manager) +Uint32 * +ViewerFB::video_init(TaskManager *manager, int bpp, int width, int height) { Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; @@ -14,11 +16,13 @@ exit(1); } - pixels = (Uint32*)get_fbdev_addr(); + Uint32 *pixels = (Uint32*)get_fbdev_addr(); if (pixels == 0) { - pixels = (new Uint32[width*height*32/8]); + pixels = (new Uint32[width*height*32/8]); } + + return pixels; } void @@ -27,3 +31,16 @@ //bzero(pixels, sizeof(int)*width*height); //memset(pixels, 0xFF, sizeof(int)*width*height); } + +void +ViewerFB::clear_screen() +{ +} + + +void +ViewerFB::free_device() +{ +} + +
--- a/Renderer/Engine/viewerFB.h Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/viewerFB.h Sat Dec 19 20:32:02 2009 +0900 @@ -1,16 +1,19 @@ #ifndef INCLUDED_VIEWER_FB #define INCLUDED_VIEWER_FB -#include "viewer.h" +#include "ViewerDevice.h" -class ViewerFB : public Viewer { +class ViewerFB : public ViewerDevice { public: -ViewerFB(TaskManager *manager, int bpp, int width, int height, int spenum) - :Viewer(bpp, width, height, spenum) {} + ViewerFB(TaskManager *manager) {}; + ViewerFB(); + virtual ~ViewerFB(); /* override function */ - void video_init(TaskManager *manager); + Uint32 *video_init(TaskManager *manager, int bpp, int width, int height); void clean_pixels(void); + void clear_screen(); + void free_device(); }; #endif
--- a/Renderer/Engine/viewerSDL.cc Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/viewerSDL.cc Sat Dec 19 20:32:02 2009 +0900 @@ -1,13 +1,17 @@ #include "viewerSDL.h" #include "Func.h" #include "TaskManager.h" +#include "viewer_types.h" extern void post2runLoop(void *); -extern +#define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK -void -ViewerSDL::video_init(TaskManager *manager) +ViewerSDL::ViewerSDL() {} +ViewerSDL::~ViewerSDL() {} + +Uint32 * +ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height) { Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; Uint32 *p; @@ -31,7 +35,7 @@ screen->pitch, redMask, greenMask, blueMask, alphaMask); - pixels = p; + return p; } void @@ -42,19 +46,15 @@ } void -ViewerSDL::run_loop(HTaskPtr task_next) +ViewerSDL::clear_screen() { SDL_BlitSurface(bitmap, NULL, screen, NULL); SDL_UpdateRect(screen, 0, 0, 0, 0); - - Viewer::run_loop(task_next); } void -ViewerSDL::run_finish() +ViewerSDL::free_device() { free(bitmap->pixels); SDL_FreeSurface(bitmap); - - Viewer::run_finish(); }
--- a/Renderer/Engine/viewerSDL.h Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Engine/viewerSDL.h Sat Dec 19 20:32:02 2009 +0900 @@ -1,21 +1,22 @@ #ifndef INCLUDED_VIEWER_SDL #define INCLUDED_VIEWER_SDL -#include "viewer.h" +#include "ViewerDevice.h" -class ViewerSDL : public Viewer { +class ViewerSDL : public ViewerDevice { public: -ViewerSDL(TaskManager* manager, int bpp, int width, int height, int spenum) - :Viewer(bpp, width, height, spenum) {} + ViewerSDL(TaskManager* manager) {}; + ViewerSDL(); + virtual ~ViewerSDL(); SDL_Surface *screen; SDL_Surface *bitmap; /* override function */ - void video_init(TaskManager *manager); + Uint32 *video_init(TaskManager *manager, int bpp, int width, int height); void clean_pixels(); - void run_loop(HTaskPtr task_next); - void run_finish(); + void clear_screen(); + void free_device(); }; #endif
--- a/Renderer/Test/SgRootChange.cc Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Test/SgRootChange.cc Sat Dec 19 20:32:02 2009 +0900 @@ -106,15 +106,11 @@ // prototype MainLoopPtr -SgRootChange::init(Viewer *sgroot, int screen_w, int screen_h) -{ - return sgroot; -} - -MainLoopPtr -SgRootChange::init_only_sg(SgChange *sgroot, int screen_w, int screen_h) -{ +SgRootChange::init(Viewer *viewer, int screen_w, int screen_h) +{ + SgChange *sgroot = new SgChange(viewer); SceneGraphPtr ball; + sgroot->run_init(); srandom(100); sgroot->createFromXMLfile("xml_file/Ball.xml"); @@ -140,7 +136,7 @@ const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; -extern int sg_init(TaskManager *manager, int argc, char *argv[]); +extern int init(TaskManager *manager, int argc, char *argv[]); extern void task_initialize(); static void TMend(TaskManager *manager); @@ -149,7 +145,7 @@ { task_initialize(); manager->set_TMend(TMend); - return sg_init(manager, argc, argv); + return init(manager, argc, argv); }
--- a/Renderer/Test/SgRootChange.h Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Test/SgRootChange.h Sat Dec 19 20:32:02 2009 +0900 @@ -3,10 +3,10 @@ #include "SceneGraphRoot.h" #include "Application.h" #include "MainLoop.h" +#include "SgChange.h" class SgRootChange : public Application { MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h); - MainLoopPtr init_only_sg(SgChange *viewer, int screen_w, int screen_h); };
--- a/Renderer/Test/ball_bound.cc Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Test/ball_bound.cc Sat Dec 19 20:32:02 2009 +0900 @@ -133,12 +133,6 @@ return sgroot; } -MainLoopPtr -ball_bound::init_only_sg(SgChange *sgroot, int screen_w, int screen_h) -{ - return sgroot; -} - extern Application * application() { return new ball_bound();
--- a/Renderer/Test/ball_bound.h Sat Dec 19 17:11:43 2009 +0900 +++ b/Renderer/Test/ball_bound.h Sat Dec 19 20:32:02 2009 +0900 @@ -7,5 +7,4 @@ class ball_bound : public Application { MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h); - MainLoopPtr init_only_sg(SgChange *viewer, int screen_w, int screen_h); };