Mercurial > hg > Members > kono > Cerium
comparison Renderer/Engine/SgChange.cc @ 656:d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
author | hiroki@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 25 Nov 2009 21:56:14 +0900 |
parents | |
children | 9d1bcc07734b b7376415fa5f |
comparison
equal
deleted
inserted
replaced
646:ffcc25c7c566 | 656:d0b8860c17f8 |
---|---|
1 #include <SDL.h> | |
2 #include "SgChange.h" | |
3 #include "viewer_types.h" | |
4 #include "SceneGraph.h" | |
5 #include "SceneGraphRoot.h" | |
6 #include "scene_graph_pack.h" | |
7 #include "sys.h" | |
8 #include "Func.h" | |
9 #include "error.h" | |
10 #include "TaskManager.h" | |
11 #include <wchar.h> | |
12 #include "Pad.h" | |
13 #include "Application.h" | |
14 #include "lindaapi.h" | |
15 | |
16 static void post2runLoop(SchedTask *s,void *viewer,void *s1); | |
17 | |
18 /* measure for FPS (Frame Per Second) */ | |
19 int start_time; | |
20 int this_time; | |
21 int frames; | |
22 | |
23 /* Data Pack sent to Other CPUs (ex. SPE) */ | |
24 SceneGraphPack *sgpack; | |
25 PolygonPack *ppack; | |
26 SpanPackPtr spackList; | |
27 SpanPackPtr *spackList_ptr; | |
28 | |
29 int spackList_length; | |
30 int spackList_length_align; | |
31 | |
32 /** | |
33 * | |
34 */ | |
35 | |
36 SgChange::SgChange(int b, int w, int h, int _num) | |
37 { | |
38 bpp = b; | |
39 width = w; | |
40 height = h; | |
41 spe_num = _num; | |
42 } | |
43 | |
44 int | |
45 SgChange::get_ticks(void) | |
46 { | |
47 int time; | |
48 time = SDL_GetTicks(); | |
49 return time; | |
50 } | |
51 | |
52 bool | |
53 SgChange::quit_check(void) | |
54 { | |
55 SDL_Event event; | |
56 | |
57 while(SDL_PollEvent(&event)) { | |
58 if (event.type==SDL_QUIT) { | |
59 return true; | |
60 } | |
61 } | |
62 | |
63 Uint8 *keys=SDL_GetKeyState(NULL); | |
64 | |
65 if (keys[SDLK_q] == SDL_PRESSED) { | |
66 return true; | |
67 } | |
68 | |
69 return false; | |
70 } | |
71 | |
72 void | |
73 SgChange::quit(void) | |
74 { | |
75 SDL_Quit(); | |
76 } | |
77 | |
78 void | |
79 SgChange::swap_buffers(void) | |
80 { | |
81 SDL_GL_SwapBuffers(); | |
82 } | |
83 | |
84 | |
85 void | |
86 SgChange::run_init(TaskManager *manager, Application *app) | |
87 { | |
88 this->manager = manager; | |
89 | |
90 start_time = get_ticks(); | |
91 this_time = 0; | |
92 frames = 0; | |
93 | |
94 // ココ! | |
95 sgroot_A = new SceneGraphRoot(this->width, this->height); | |
96 sgroot_A->tmanager = manager; | |
97 sgroot_B = new SceneGraphRoot(this->width, this->height); | |
98 sgroot_B->tmanager = manager; | |
99 | |
100 MainLoop *mainloop = app->init_only_sg(this, this->width, this->height); | |
101 | |
102 mainloop->mainLoop(); | |
103 } | |
104 | |
105 void | |
106 SgChange::mainLoop() | |
107 { | |
108 HTaskPtr task_next = manager->create_task(Dummy); | |
109 | |
110 task_next->set_post(&post2runLoop, (void *)this, 0); // set_post(function(this->run_loop()), NULL) | |
111 task_next->spawn(); | |
112 } | |
113 | |
114 static void | |
115 post2runLoop(SchedTask *s, void *viewer_, void *arg) | |
116 { | |
117 SgChange *viewer = (SgChange*)viewer_; | |
118 HTaskPtr task_next = viewer->manager->create_task(Dummy); | |
119 viewer->run_loop(task_next); | |
120 | |
121 psx_sync_n(); | |
122 } | |
123 | |
124 void | |
125 SgChange::exchange_sgroot() | |
126 { | |
127 SceneGraphRoot *tmp; | |
128 tmp = sgroot_A; | |
129 sgroot_A = sgroot_B; | |
130 sgroot_B = tmp; | |
131 } | |
132 | |
133 void | |
134 SgChange::run_loop(HTaskPtr task_next) | |
135 { | |
136 bool quit_flg; | |
137 quit_flg = quit_check(); | |
138 if (quit_flg == true) { | |
139 this_time = get_ticks(); | |
140 run_finish(); | |
141 return; | |
142 } | |
143 | |
144 sgroot_A->allExecute(width, height); | |
145 exchange_sgroot(); | |
146 | |
147 //printf("Sgroot = %x\n", sgroot_A); | |
148 | |
149 task_next->set_post(&post2runLoop, (void *)this, 0); | |
150 task_next->spawn(); | |
151 } | |
152 | |
153 | |
154 void | |
155 SgChange::run_finish(void) | |
156 { | |
157 if (this_time != start_time) { | |
158 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); | |
159 } | |
160 | |
161 delete sgroot_A; | |
162 delete sgroot_B; | |
163 quit(); | |
164 } | |
165 | |
166 /* end */ |