Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/viewer.cpp @ 374:1c09c7e9284b
CHAIN ADDED
author | kazz@kazzone.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 06 May 2009 15:49:30 +0900 |
parents | 4bfa24811786 |
children | 7c2923fa31ff |
rev | line source |
---|---|
140 | 1 #include <SDL.h> |
109 | 2 #include "viewer.h" |
120 | 3 #include "viewer_types.h" |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
4 #include "SceneGraph.h" |
195 | 5 #include "SceneGraphRoot.h" |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
6 #include "scene_graph_pack.h" |
109 | 7 #include "sys.h" |
8 #include "Func.h" | |
9 #include "error.h" | |
10 #include "TaskManager.h" | |
212 | 11 #include <wchar.h> |
221 | 12 #include "Pad.h" |
212 | 13 |
109 | 14 |
15 extern void post2runLoop(void *); | |
16 extern void post2runDraw(void *); | |
17 | |
18 /* measure for FPS (Frame Per Second) */ | |
19 int start_time; | |
20 int this_time; | |
21 int frames; | |
22 | |
198
57921c8d21c5
rename snake_bg to panel
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
195
diff
changeset
|
23 SceneGraphRootPtr sgroot; |
109 | 24 |
176 | 25 /* Data Pack sent to Other CPUs (ex. SPE) */ |
109 | 26 SceneGraphPack *sgpack; |
27 PolygonPack *ppack; | |
28 SpanPackPtr spackList; | |
29 SpanPackPtr *spackList_ptr; | |
210 | 30 |
109 | 31 int spackList_length; |
32 int spackList_length_align; | |
33 | |
140 | 34 /** |
176 | 35 * |
36 */ | |
37 | |
109 | 38 Viewer::Viewer(int b, int w, int h, int _num) |
39 { | |
40 bpp = b; | |
41 width = w; | |
42 height = h; | |
43 spe_num = _num; | |
44 } | |
45 | |
46 int | |
229 | 47 Viewer::get_ticks(void) |
109 | 48 { |
49 int time; | |
50 time = SDL_GetTicks(); | |
51 return time; | |
52 } | |
53 | |
54 bool | |
229 | 55 Viewer::quit_check(void) |
109 | 56 { |
57 SDL_Event event; | |
58 | |
59 while(SDL_PollEvent(&event)) { | |
374 | 60 if (event.type==SDL_QUIT) { |
61 return true; | |
62 } | |
109 | 63 } |
64 | |
65 Uint8 *keys=SDL_GetKeyState(NULL); | |
66 | |
67 if (keys[SDLK_q] == SDL_PRESSED) { | |
374 | 68 return true; |
109 | 69 } |
70 | |
71 return false; | |
72 } | |
73 | |
74 void | |
229 | 75 Viewer::quit(void) |
109 | 76 { |
77 SDL_Quit(); | |
78 } | |
79 | |
80 void | |
229 | 81 Viewer::swap_buffers(void) |
109 | 82 { |
83 SDL_GL_SwapBuffers(); | |
84 } | |
85 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
86 extern void node_init(void); |
144 | 87 extern void create_cube_split(int); |
198
57921c8d21c5
rename snake_bg to panel
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
195
diff
changeset
|
88 extern void panel_init(int); |
199
eb20274baa7c
add SceneGraph(ieshoot), add SystemSceneGraph(Camera)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
198
diff
changeset
|
89 extern void universe_init(void); |
eb20274baa7c
add SceneGraph(ieshoot), add SystemSceneGraph(Camera)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
198
diff
changeset
|
90 extern void ieshoot_init(void); |
210 | 91 extern void ball_bound_init(int, int); |
212 | 92 extern void lcube_init(int, int); |
93 extern void direction_init(void); | |
213
159519cdca1f
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
94 extern void init_position(int, int); |
222 | 95 extern void vacuum_init(int w, int h); |
231
4bfa24811786
test program add (-sg 12)
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
229
diff
changeset
|
96 extern void untitled_init(void); |
374 | 97 extern void chain_init(int w, int h); |
109 | 98 void |
180
5cde66c926b4
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
177
diff
changeset
|
99 Viewer::run_init(const char *xml, int sg_number) |
109 | 100 { |
101 HTaskPtr task_next; | |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
102 HTaskPtr task_tex; |
109 | 103 |
104 start_time = get_ticks(); | |
105 this_time = 0; | |
106 frames = 0; | |
107 | |
221 | 108 sgroot = new SceneGraphRoot(this->width, this->height); |
195 | 109 //sgroot->createFromXMLFile(xml); |
140 | 110 |
144 | 111 switch (sg_number) { |
112 case 0: | |
113 case 1: | |
374 | 114 create_cube_split(sg_number); |
115 break; | |
144 | 116 case 2: |
153
c8c8bb4e9e58
画像のサイズテストを加える -sg = [2,3,4]
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
150
diff
changeset
|
117 case 3: |
c8c8bb4e9e58
画像のサイズテストを加える -sg = [2,3,4]
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
150
diff
changeset
|
118 case 4: |
374 | 119 panel_init(sg_number); |
120 break; | |
153
c8c8bb4e9e58
画像のサイズテストを加える -sg = [2,3,4]
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
150
diff
changeset
|
121 case 5: |
374 | 122 universe_init(); |
123 break; | |
158 | 124 case 6: |
374 | 125 ieshoot_init(); |
126 break; | |
210 | 127 case 7: |
374 | 128 ball_bound_init(this->width, this->height); |
129 break; | |
212 | 130 case 8: |
374 | 131 lcube_init(this->width, this->height); |
132 break; | |
212 | 133 case 9: |
374 | 134 direction_init(); |
135 break; | |
213
159519cdca1f
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
136 case 10: |
374 | 137 init_position(this->width, this->height); |
138 break; | |
222 | 139 case 11: |
374 | 140 vacuum_init(this->width, this->height); |
141 break; | |
231
4bfa24811786
test program add (-sg 12)
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
229
diff
changeset
|
142 case 12: |
4bfa24811786
test program add (-sg 12)
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
229
diff
changeset
|
143 untitled_init(); |
4bfa24811786
test program add (-sg 12)
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
229
diff
changeset
|
144 break; |
374 | 145 case 13: |
146 chain_init(this->width, this-> height); | |
147 break; | |
144 | 148 default: |
374 | 149 node_init(); |
150 break; | |
144 | 151 } |
142 | 152 |
217 | 153 sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); |
109 | 154 sgpack->init(); |
217 | 155 ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); |
109 | 156 |
157 spackList_length = (this->height + split_screen_h - 1) / split_screen_h; | |
217 | 158 spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length); |
109 | 159 |
176 | 160 /** |
161 * SPU に送る address list は 16 バイト倍数でないといけない。 | |
162 * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような | |
163 * length_align を求めている。はみ出した部分は使われない | |
164 * (ex) spackList_length が 13 の場合 | |
165 * spackList_length_align = 16; | |
166 * 実際に送るデータは64バイトになるのでOK | |
167 * 14,15,16 の部分は何も入らない。 | |
168 */ | |
109 | 169 spackList_length_align = (spackList_length + 3)&(~3); |
170 | |
171 /* 各 SPU が持つ、SpanPack の address list */ | |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
172 spackList_ptr = |
374 | 173 (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); |
109 | 174 |
175 for (int i = 0; i < spackList_length; i++) { | |
374 | 176 spackList_ptr[i] = &spackList[i]; |
109 | 177 } |
178 | |
126
7635f223fc7d
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
179 for (int i = 1; i <= spackList_length; i++) { |
374 | 180 spackList[i-1].init(i*split_screen_h); |
126
7635f223fc7d
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
181 } |
7635f223fc7d
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
182 |
109 | 183 task_next = manager->create_task(TASK_DUMMY); |
184 task_next->set_post(&post2runLoop, NULL); | |
185 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
186 #if 0 |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
187 // 諸事情で、今は SceneGraphPack を作らずに |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
188 // そのまま SceneGraph でやっています |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
189 HTaskPtr task_sgp; |
109 | 190 task_sgp = manager->create_task(TASK_CREATE_SGP); |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
191 task_sgp->add_param((uint32)scene_graph); |
109 | 192 task_sgp->add_param((uint32)sgpack); |
193 task_next->wait_for(task_sgp); | |
194 task_sgp->spawn(); | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
195 #endif |
109 | 196 |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
197 for (int i = 0; i < spe_num; i++) { |
374 | 198 task_tex = manager->create_task(TASK_INIT_TEXTURE); |
199 /* ここはもう少しわかりやすい使い方がいいかもしれぬ。こんなもん? */ | |
200 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
201 task_next->wait_for(task_tex); | |
202 task_tex->spawn(); | |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
203 } |
120 | 204 |
109 | 205 task_next->spawn(); |
206 } | |
207 | |
208 void | |
209 Viewer::run_loop(void) | |
210 { | |
211 HTaskPtr task_create_pp = NULL; | |
212 HTaskPtr task_create_sp = NULL; | |
213 HTaskPtr task_next; | |
214 bool quit_flg; | |
215 | |
216 quit_flg = quit_check(); | |
217 | |
218 if (quit_flg == true) { | |
374 | 219 this_time = get_ticks(); |
220 run_finish(); | |
221 return; | |
109 | 222 } |
223 | |
222 | 224 clean_pixels(); |
109 | 225 |
226 for (int i = 1; i <= spackList_length; i++) { | |
374 | 227 spackList[i-1].reinit(i*split_screen_h); |
109 | 228 } |
229 | |
230 task_next = manager->create_task(TASK_DUMMY); | |
231 task_next->set_post(post2runDraw, NULL); | |
232 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
233 #if 0 |
157 | 234 // SceneGraphPack の update |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
235 HTaskPtr task_update_sgp = NULL; |
109 | 236 task_update_sgp = manager->create_task(TASK_UPDATE_SGP); |
237 task_update_sgp->add_inData(sgpack, sizeof(SceneGraphPack)); | |
238 task_update_sgp->add_outData(sgpack, sizeof(SceneGraphPack)); | |
239 task_update_sgp->add_param(width); | |
240 task_update_sgp->add_param(height); | |
241 task_next->wait_for(task_update_sgp); | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
242 task_update_sgp->spawn(); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
243 #else |
195 | 244 sgroot->updateControllerState(); |
245 sgroot->allExecute(width, height); | |
219
0f1ff7b06157
allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents:
217
diff
changeset
|
246 //sgroot->checkRemove(); |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
247 #endif |
109 | 248 |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
249 #if 0 |
157 | 250 // SceneGraphPack(配列) -> PolygonPack |
109 | 251 task_create_pp = manager->create_task(TASK_CREATE_PP); |
252 task_create_pp->add_inData(sgpack, sizeof(SceneGraphPack)); | |
253 task_create_pp->add_param((uint32)ppack); | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
254 #else |
157 | 255 // SceneGraph(木構造) -> PolygonPack |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
256 task_create_pp = manager->create_task(TASK_CREATE_PP2); |
195 | 257 task_create_pp->add_param((uint32)sgroot->getDrawSceneGraph()); |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
258 task_create_pp->add_param((uint32)ppack); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
259 #endif |
109 | 260 task_next->wait_for(task_create_pp); |
261 | |
262 int range_base = spe_num; | |
263 // 切り上げのつもり | |
264 int range = (spackList_length + range_base - 1) / range_base; | |
265 | |
266 for (int i = 0; i < range_base; i++) { | |
374 | 267 int index_start = range*i; |
268 int index_end = (index_start + range >= spackList_length) | |
269 ? spackList_length : index_start + range; | |
109 | 270 |
374 | 271 task_create_sp = manager->create_task(TASK_CREATE_SPAN); |
272 task_create_sp->add_inData(ppack, sizeof(PolygonPack)); | |
273 task_create_sp->add_inData(spackList_ptr, | |
274 sizeof(SpanPack*)*spackList_length_align); | |
275 task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); | |
109 | 276 |
374 | 277 task_create_sp->add_param(index_start); |
109 | 278 |
374 | 279 /** |
280 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 | |
281 * [ 1.. 80] [ 81..160] [161..240] | |
282 * [241..320] [321..400] [401..480] | |
283 * | |
284 * ex. screen_height が 1080, spenum が 5 の場合、 | |
285 * [ 1..216] [217..432] [433..648] | |
286 * [649..864] [865..1080] | |
287 */ | |
288 task_create_sp->add_param(index_start*split_screen_h + 1); | |
289 task_create_sp->add_param(index_end*split_screen_h); | |
109 | 290 |
374 | 291 task_next->wait_for(task_create_sp); |
292 task_create_sp->wait_for(task_create_pp); | |
109 | 293 |
374 | 294 task_create_sp->set_cpu(SPE_ANY); |
295 task_create_sp->spawn(); | |
109 | 296 } |
297 | |
298 task_create_pp->spawn(); | |
299 task_next->spawn(); | |
300 } | |
301 | |
302 void | |
303 Viewer::run_draw(void) | |
304 { | |
305 HTaskPtr task_next; | |
306 HTaskPtr task_draw; | |
374 | 307 |
109 | 308 task_next = manager->create_task(TASK_DUMMY); |
309 task_next->set_post(post2runLoop, NULL); | |
374 | 310 |
109 | 311 ppack->clear(); |
312 for (int i = 0; i < spackList_length; i++) { | |
374 | 313 SpanPack *spack = &spackList[i]; |
314 int startx = 1; | |
315 int endx = split_screen_w; | |
109 | 316 |
374 | 317 int starty = spack->info.y_top - split_screen_h + 1; |
318 //int endy = spack->info.y_top; | |
319 int rangey = (starty + split_screen_h - 1 > this->height) | |
320 ? this->height - starty + 1 : split_screen_h; | |
109 | 321 |
374 | 322 while (startx < this->width) { |
323 if (spack->info.size > 0) { | |
324 // Draw SpanPack | |
325 task_draw = manager->create_task(TASK_DRAW_SPAN); | |
326 task_draw->add_inData(spack, sizeof(SpanPack)); | |
327 | |
328 task_draw->add_param( | |
329 (uint32)&pixels[(startx-1) + this->width*(starty-1)]); | |
330 task_draw->add_param(this->width); | |
331 } else { | |
200 | 332 #if 0 |
374 | 333 //break; |
334 // Draw Background (現在は塗りつぶし) | |
335 task_draw = manager->create_task(TASK_DRAW_BACK); | |
336 task_draw->add_param(0xffffffff); | |
205 | 337 |
374 | 338 for (int k = 0; k < rangey; k++) { |
339 task_draw->add_outData( | |
340 &pixels[(startx-1)+this->width*(k+starty-1)], | |
341 (endx - startx + 1)*sizeof(int)); | |
342 } | |
200 | 343 #else |
374 | 344 memset(&pixels[(startx-1)+this->width*(starty-1)], |
345 0, (this->width)*sizeof(int)*rangey); | |
346 //wmemset((wchar_t*)&pixels[(startx-1)+this->width*(starty-1)], | |
347 //0xFFFFFFFF, (this->width)*sizeof(int)*rangey/sizeof(wchar_t)); | |
348 break; | |
200 | 349 #endif |
374 | 350 } |
109 | 351 |
374 | 352 task_draw->add_param(startx); |
353 task_draw->add_param(endx); | |
354 task_draw->add_param(rangey); | |
355 task_draw->set_cpu(SPE_ANY); | |
356 task_next->wait_for(task_draw); | |
357 task_draw->spawn(); | |
109 | 358 |
374 | 359 startx += split_screen_w; |
360 endx += split_screen_w; | |
109 | 361 |
374 | 362 if (endx > this->width) { |
363 endx = this->width; | |
364 } | |
365 } | |
109 | 366 } |
367 | |
368 task_next->spawn(); | |
369 | |
370 frames++; | |
371 } | |
372 | |
373 void | |
374 Viewer::run_finish(void) | |
375 { | |
376 if (this_time != start_time) { | |
374 | 377 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); |
109 | 378 } |
379 | |
219
0f1ff7b06157
allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents:
217
diff
changeset
|
380 delete sgroot; |
0f1ff7b06157
allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents:
217
diff
changeset
|
381 |
109 | 382 quit(); |
383 } |