Mercurial > hg > Game > Cerium
annotate Renderer/Engine/viewer.cc @ 857:2fa8943d989a draft
DrawSpan taskArray bug fix
author | yutaka@localhost.localdomain |
---|---|
date | Thu, 10 Jun 2010 23:21:51 +0900 |
parents | 293fcceaac36 |
children | 63a08f3a468a |
rev | line source |
---|---|
539 | 1 #include <SDL.h> |
2 #include "viewer.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" | |
543 | 13 #include "Application.h" |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
14 #include "lindaapi.h" |
539 | 15 |
555 | 16 static void post2runLoop(SchedTask *s,void *viewer,void *s1); |
17 static void post2runDraw(SchedTask *s,void *viewer,void *s1); | |
18 static void post2speRendering(SchedTask *s,void *viewer,void *s1); | |
19 static void post2speDraw(SchedTask *s,void *viewer,void *s1); | |
20 static void post2runMoveDrawLoop(SchedTask *s,void *viewer,void *s1); | |
539 | 21 |
22 /* measure for FPS (Frame Per Second) */ | |
23 int start_time; | |
24 int this_time; | |
25 int frames; | |
550 | 26 // static void post2speRunLoop(void *viewer); |
27 //static void post2runMove(void *viewer); | |
28 //static void post2exchange_sgroot(void *viewer); | |
29 //static void post2speRunLoop(void *viewer); | |
539 | 30 |
31 //SceneGraphRootPtr sgroot_2; | |
32 | |
33 /* Data Pack sent to Other CPUs (ex. SPE) */ | |
34 SceneGraphPack *sgpack; | |
35 PolygonPack *ppack; | |
36 SpanPackPtr spackList; | |
37 SpanPackPtr *spackList_ptr; | |
38 | |
39 int spackList_length; | |
40 int spackList_length_align; | |
41 | |
42 /** | |
43 * | |
44 */ | |
45 | |
747 | 46 Viewer::Viewer(TaskManager *m, ViewerDevice *vd, int b, int w, int h, int _num) |
539 | 47 { |
48 bpp = b; | |
49 width = w; | |
50 height = h; | |
51 spe_num = _num; | |
747 | 52 manager = m; |
53 dev = vd; | |
54 pixels = dev->video_init(manager, b, w, h); | |
55 | |
539 | 56 } |
57 | |
58 int | |
59 Viewer::get_ticks(void) | |
60 { | |
61 int time; | |
62 time = SDL_GetTicks(); | |
63 return time; | |
64 } | |
65 | |
66 bool | |
67 Viewer::quit_check(void) | |
68 { | |
69 SDL_Event event; | |
70 | |
71 while(SDL_PollEvent(&event)) { | |
72 if (event.type==SDL_QUIT) { | |
73 return true; | |
74 } | |
75 } | |
76 | |
77 Uint8 *keys=SDL_GetKeyState(NULL); | |
78 | |
79 if (keys[SDLK_q] == SDL_PRESSED) { | |
80 return true; | |
81 } | |
82 | |
83 return false; | |
84 } | |
85 | |
86 void | |
87 Viewer::quit(void) | |
88 { | |
89 SDL_Quit(); | |
90 } | |
91 | |
92 | |
93 void | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
94 Viewer::run_init(TaskManager *manager, Application *app) |
539 | 95 { |
96 this->manager = manager; | |
97 | |
98 start_time = get_ticks(); | |
99 this_time = 0; | |
100 frames = 0; | |
101 | |
747 | 102 if (spe_num == 0) spe_num = 1; |
103 | |
539 | 104 sgroot = new SceneGraphRoot(this->width, this->height); |
572 | 105 sgroot->tmanager = manager; |
792 | 106 |
107 | |
108 int light_num = 4; | |
109 int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4) | |
761 | 110 int light_size = size / sizeof(float); |
747 | 111 |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
747
diff
changeset
|
112 light_xyz_stock = (float *)manager->allocate(size); |
747 | 113 light_xyz = (float *)manager->allocate(size); |
761 | 114 |
115 for (int i = 0; i < light_size ; i++) { | |
116 light_xyz[i] = 0.0f; | |
117 } | |
747 | 118 |
792 | 119 for(int i = 0; i < spe_num; i++) { |
826 | 120 |
792 | 121 HTaskPtr data_load = manager->create_task(DataLoad); |
747 | 122 data_load->set_param(0,(memaddr)size); |
123 data_load->set_param(1,(memaddr)Light); | |
124 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
125 data_load->spawn(); | |
126 } | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
127 |
792 | 128 size = light_num * sizeof(int); |
129 light_switch = (int*)manager->allocate(size); | |
793 | 130 |
792 | 131 for (int i = 0; i < light_num; i++) { |
132 light_switch[i] = 0; | |
133 } | |
134 | |
135 for(int i = 0; i < spe_num; i++) { | |
136 HTaskPtr data_load = manager->create_task(DataLoad); | |
137 data_load->set_param(0,(memaddr)size); | |
138 data_load->set_param(1,(memaddr)LightSwitch); | |
139 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
140 data_load->spawn(); | |
141 } | |
142 | |
143 size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング | |
144 | |
793 | 145 light_sysswitch = (int*)manager->allocate(size); |
146 | |
843
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
842
diff
changeset
|
147 for (unsigned int i = 0; i < size / sizeof(int); i++) { |
793 | 148 light_sysswitch[i] = 0; |
149 } | |
150 | |
792 | 151 for(int i = 0; i < spe_num; i++) { |
152 HTaskPtr data_load = manager->create_task(DataLoad); | |
153 data_load->set_param(0,(memaddr)size); | |
154 data_load->set_param(1,(memaddr)LightSysSwitch); | |
155 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
156 data_load->spawn(); | |
157 } | |
158 | |
543 | 159 MainLoop *mainloop = app->init(this, this->width, this->height); |
160 mainloop->mainLoop(); | |
539 | 161 } |
162 | |
163 | |
164 HTaskPtr | |
165 Viewer::initLoop() | |
166 { | |
167 HTaskPtr task_next; | |
168 HTaskPtr task_tex; | |
169 | |
170 sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); | |
171 sgpack->init(); | |
172 ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); | |
173 | |
174 spackList_length = (this->height + split_screen_h - 1) / split_screen_h; | |
175 spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length); | |
176 | |
177 /** | |
178 * SPU に送る address list は 16 バイト倍数でないといけない。 | |
179 * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような | |
180 * length_align を求めている。はみ出した部分は使われない | |
181 * (ex) spackList_length が 13 の場合 | |
182 * spackList_length_align = 16; | |
183 * 実際に送るデータは64バイトになるのでOK | |
184 * 14,15,16 の部分は何も入らない。 | |
185 */ | |
186 spackList_length_align = (spackList_length + 3)&(~3); | |
187 | |
188 /* 各 SPU が持つ、SpanPack の address list */ | |
189 spackList_ptr = | |
190 (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); | |
191 | |
192 for (int i = 0; i < spackList_length; i++) { | |
193 spackList_ptr[i] = &spackList[i]; | |
194 } | |
195 | |
196 for (int i = 1; i <= spackList_length; i++) { | |
197 spackList[i-1].init(i*split_screen_h); | |
198 } | |
199 | |
826 | 200 task_next = manager->create_task(Dummy,0,0,0,0); |
539 | 201 |
659 | 202 // ここは、Iterator を用意するべきだよね |
539 | 203 for (int i = 0; i < spe_num; i++) { |
826 | 204 task_tex = manager->create_task(LoadTexture,0,0,0,0); |
205 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); | |
206 task_next->wait_for(task_tex); | |
747 | 207 task_tex->spawn(); |
539 | 208 } |
209 | |
792 | 210 |
539 | 211 return task_next; |
212 } | |
213 | |
214 | |
215 void | |
216 Viewer::getKey() | |
217 { | |
218 Pad *pad = sgroot->getController(); | |
219 if (pad->right.isHold()) { | |
220 keyPtr->right = HOLD; | |
221 } else if (pad->right.isPush()) { | |
222 keyPtr->right = PUSH; | |
223 } else { | |
224 keyPtr->right = NONE; | |
225 } | |
226 | |
227 if (pad->left.isHold()) { | |
228 keyPtr->left = HOLD; | |
229 } else if (pad->left.isPush()) { | |
230 keyPtr->left = PUSH; | |
231 } else { | |
232 keyPtr->left = NONE; | |
233 } | |
234 | |
235 if (pad->up.isHold()) { | |
236 keyPtr->up = HOLD; | |
237 } else if (pad->up.isPush()) { | |
238 keyPtr->up = PUSH; | |
239 } else { | |
240 keyPtr->up = NONE; | |
241 } | |
242 | |
243 if (pad->down.isHold()) { | |
244 keyPtr->down = HOLD; | |
245 } else if (pad->down.isPush()) { | |
246 keyPtr->down = PUSH; | |
247 } else { | |
248 keyPtr->down = NONE; | |
249 } | |
250 | |
251 if (pad->circle.isHold()) { | |
252 keyPtr->circle = HOLD; | |
253 } else if (pad->circle.isPush()) { | |
254 keyPtr->circle = PUSH; | |
255 } else { | |
256 keyPtr->circle = NONE; | |
257 } | |
258 } | |
259 | |
260 static void | |
550 | 261 post2runMoveDrawLoop(SchedTask *m, void *viewer_, void *arg) |
539 | 262 { |
263 Viewer *viewer = (Viewer*)viewer_; | |
264 | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
265 // 同じ PPE 上なので sgroot(ポインタ) を set_param で送る。 |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
266 //HTaskPtr send_key_task = viewer->manager->create_task(SendKey); |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
267 //send_key_task->set_param((int)sgroot); |
539 | 268 // set input data -> viewer keyPtr |
269 viewer->getKey(); | |
826 | 270 //HTaskPtr update_key = viewer->manager->create_task(UpdateKey,viewer->keyPtr, sizeof(key_stat),0,0); |
271 HTaskPtr update_key = viewer->manager->create_task(UpdateKey,0,0,0,0); | |
539 | 272 update_key->add_inData(viewer->keyPtr, sizeof(key_stat)); |
747 | 273 //update_key->set_cpu(SPE_0); |
539 | 274 update_key->spawn(); |
275 | |
276 /* TASK_MOVE は外から引数で取ってくるべき */ | |
277 //HTaskPtr move_task = viewer->manager->create_task(viewer->app->move_taskid); | |
826 | 278 HTaskPtr move_task = viewer->manager->create_task(Move,0,0,0,0); |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
279 //move_task->set_param(sgroot); |
539 | 280 |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
281 //HTaskPtr draw_task = viewer->manager->create_task(Draw); |
539 | 282 |
283 /* rendering task test */ | |
826 | 284 HTaskPtr draw_task = viewer->manager->create_task(Dummy,0,0,0,0); |
285 HTaskPtr draw_dummy = viewer->manager->create_task(Dummy,0,0,0,0); | |
539 | 286 |
826 | 287 HTaskPtr switch_task = viewer->manager->create_task(Switch,0,0,0,0); |
539 | 288 viewer->draw_dummy = draw_dummy; |
289 switch_task->wait_for(draw_dummy); | |
550 | 290 draw_task->set_post(post2speRendering, (void*)viewer, 0); |
539 | 291 |
292 switch_task->wait_for(move_task); | |
293 switch_task->wait_for(draw_task); | |
294 move_task->spawn(); | |
295 draw_task->spawn(); | |
296 | |
550 | 297 switch_task->set_post(post2runMoveDrawLoop, (void*)viewer, 0); |
539 | 298 switch_task->spawn(); |
299 | |
300 } | |
301 | |
302 void | |
303 Viewer::mainLoop() | |
304 { | |
305 HTaskPtr task_next = initLoop(); | |
306 | |
550 | 307 task_next->set_post(&post2runLoop, (void *)this, 0); // set_post(function(this->run_loop()), NULL) |
539 | 308 task_next->spawn(); |
309 } | |
310 | |
311 void | |
747 | 312 Viewer::run_loop(HTaskPtr task_next) |
539 | 313 { |
747 | 314 dev->clear_screen(); |
315 | |
316 bool quit_flg; | |
317 quit_flg = quit_check(); | |
318 if (quit_flg == true) { | |
319 this_time = get_ticks(); | |
320 run_finish(); | |
321 return; | |
322 } | |
323 | |
324 dev->clean_pixels(); | |
325 | |
326 for (int i = 1; i <= spackList_length; i++) { | |
327 spackList[i-1].reinit(i*split_screen_h); | |
328 } | |
329 | |
330 sgroot->updateControllerState(); | |
331 sgroot->allExecute(width, height); | |
332 light_xyz_stock = sgroot->getLightVector(); | |
792 | 333 light_switch_stock = sgroot->getLightSwitch(); |
793 | 334 light_sysswitch_stock = sgroot->getLightSysSwitch(); |
747 | 335 //sgroot->checkRemove(); |
336 | |
337 // ここから下は Rendering という関数にする | |
338 rendering(task_next); | |
539 | 339 } |
340 | |
341 | |
342 | |
343 void | |
344 Viewer::run_collision() | |
345 { | |
346 } | |
347 | |
348 void | |
550 | 349 post2rendering(SchedTask *s, void *viewer_, void *arg) |
539 | 350 { |
351 Viewer *viewer = (Viewer *)viewer_; | |
826 | 352 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 353 viewer->rendering(task_next); |
354 } | |
355 | |
356 void | |
357 Viewer::rendering(HTaskPtr task_next) | |
358 { | |
747 | 359 common_rendering(task_next, sgroot); |
539 | 360 |
361 // Barrier 同期 | |
362 // run_draw() を呼ぶ post2runDraw | |
550 | 363 task_next->set_post(post2runDraw, (void*)this, 0); // set_post(function(this->run_draw()), NULL) |
539 | 364 task_next->spawn(); |
365 | |
366 // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ | |
367 } | |
368 | |
369 static void | |
550 | 370 post2runLoop(SchedTask *s, void *viewer_, void *arg) |
539 | 371 { |
372 Viewer *viewer = (Viewer*)viewer_; | |
826 | 373 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 374 viewer->run_loop(task_next); |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
375 psx_sync_n(); |
539 | 376 } |
377 | |
378 static void | |
550 | 379 post2runDraw(SchedTask *s, void *viewer_, void *arg) |
539 | 380 { |
381 Viewer *viewer = (Viewer*)viewer_; | |
826 | 382 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 383 viewer->run_draw(task_next); |
384 | |
385 } | |
386 | |
387 void | |
388 Viewer::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする | |
389 { | |
390 common_draw(task_next); | |
391 | |
550 | 392 task_next->set_post(post2runLoop, (void*)this, 0); // set_post(function(this->run_loop()), NULL) |
539 | 393 task_next->spawn(); |
394 // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ | |
395 | |
396 frames++; | |
397 } | |
398 | |
399 | |
400 static void | |
550 | 401 post2speRendering(SchedTask *s, void *viewer_, void *arg) |
539 | 402 { |
403 Viewer *viewer = (Viewer*)viewer_; | |
826 | 404 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 405 viewer->spe_rendering(task_next); |
406 } | |
407 | |
408 void | |
409 Viewer::spe_rendering(HTaskPtr task_next) | |
410 { | |
747 | 411 common_rendering(task_next, sgroot); |
539 | 412 |
413 this->draw_dummy->wait_for(task_next); | |
550 | 414 task_next->set_post(post2speDraw, (void*)this, 0); |
539 | 415 task_next->spawn(); |
416 | |
417 } | |
418 | |
419 static void | |
550 | 420 post2speDraw(SchedTask *s, void *viewer_, void *arg) |
539 | 421 { |
422 Viewer *viewer = (Viewer*)viewer_; | |
826 | 423 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 424 viewer->spe_draw(task_next); |
425 } | |
426 | |
427 void | |
428 Viewer::spe_draw(HTaskPtr task_next) | |
429 { | |
430 common_draw(task_next); | |
431 | |
432 this->draw_dummy->wait_for(task_next); | |
433 task_next->spawn(); | |
434 this->draw_dummy->spawn(); | |
435 | |
436 frames++; | |
437 } | |
438 | |
439 void | |
747 | 440 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot) |
539 | 441 { |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
442 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); |
539 | 443 |
444 // SceneGraph(木構造) -> PolygonPack | |
445 | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
446 task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); |
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
447 task_create_pp->set_param(1,(memaddr)ppack); |
539 | 448 |
449 task_next->wait_for(task_create_pp); | |
747 | 450 |
451 int range_base = spe_num; | |
452 | |
539 | 453 // 切り上げのつもり |
454 int range = (spackList_length + range_base - 1) / range_base; | |
455 | |
456 for (int i = 0; i < range_base; i++) { | |
457 int index_start = range*i; | |
458 int index_end = (index_start + range >= spackList_length) | |
459 ? spackList_length : index_start + range; | |
460 | |
659 | 461 HTaskPtr task_create_sp = manager->create_task(CreateSpan); |
539 | 462 |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
463 task_create_sp->set_param(0,index_start); |
747 | 464 |
539 | 465 /** |
466 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 | |
467 * [ 1.. 80] [ 81..160] [161..240] | |
468 * [241..320] [321..400] [401..480] | |
469 * | |
470 * ex. screen_height が 1080, spenum が 5 の場合、 | |
471 * [ 1..216] [217..432] [433..648] | |
472 * [649..864] [865..1080] | |
473 */ | |
747 | 474 |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
475 task_create_sp->set_param(1,index_start*split_screen_h + 1); |
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
476 task_create_sp->set_param(2,index_end*split_screen_h); |
539 | 477 |
659 | 478 task_create_sp->add_inData(ppack, sizeof(PolygonPack)); |
479 task_create_sp->add_inData(spackList_ptr, | |
480 sizeof(SpanPack*)*spackList_length_align); | |
481 task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); | |
482 | |
539 | 483 task_next->wait_for(task_create_sp); |
484 task_create_sp->wait_for(task_create_pp); | |
485 | |
747 | 486 task_create_sp->set_cpu(SPE_ANY); |
539 | 487 task_create_sp->spawn(); |
488 } | |
489 | |
747 | 490 |
539 | 491 task_create_pp->spawn(); |
492 } | |
493 | |
792 | 494 HTaskPtr |
495 Viewer::update_task_create(void *data, int size, | |
496 int load_id, int spe_id, HTaskPtr wait) | |
497 { | |
498 | |
499 HTaskPtr data_update = manager->create_task(DataUpdate); | |
500 data_update->add_inData(data,size); | |
501 data_update->set_param(0,size); | |
502 data_update->set_param(1,load_id); | |
503 data_update->set_cpu((CPU_TYPE)(spe_id)); | |
504 if (wait != NULL) { | |
505 wait->wait_for(data_update); | |
506 } | |
507 data_update->spawn(); | |
508 | |
509 return data_update; | |
510 | |
511 } | |
512 | |
539 | 513 void |
514 Viewer::common_draw(HTaskPtr task_next) | |
515 { | |
516 | |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
517 //task_next = manager->create_task(Dummy); |
539 | 518 //task_next->set_post(post2runLoop, (void*)this); |
519 | |
792 | 520 //Light info update |
747 | 521 |
793 | 522 //HTaskPtr data_update; |
747 | 523 HTaskPtr data_update_wait; |
792 | 524 int light_num = 4; |
525 int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4) | |
761 | 526 int light_size = size / sizeof(float); |
747 | 527 |
761 | 528 for (int i = 0; i < light_size; i++) { |
792 | 529 light_xyz[i] = light_xyz_stock[i]; |
761 | 530 } |
792 | 531 |
532 for (int i = 0; i < light_num; i++) { | |
533 light_switch[i] = light_switch_stock[i]; | |
534 } | |
793 | 535 |
536 light_sysswitch[0] = light_sysswitch_stock; | |
792 | 537 |
747 | 538 data_update_wait = manager->create_task(DataUpdate); |
539 data_update_wait->add_inData(light_xyz,size); | |
540 data_update_wait->set_param(0,size); | |
541 data_update_wait->set_param(1,Light); | |
542 data_update_wait->set_cpu((CPU_TYPE)((int)SPE_0)); | |
792 | 543 |
747 | 544 for (int i = 1; i < spe_num; i++) { |
792 | 545 update_task_create(light_xyz,size,Light,(int)SPE_0+i,data_update_wait); |
546 } | |
547 | |
548 size = light_num * sizeof(int); | |
549 | |
550 for (int i = 0; i < spe_num; i++) { | |
793 | 551 update_task_create(light_switch,size,LightSwitch,(int)SPE_0+i,data_update_wait); |
792 | 552 } |
553 | |
554 size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング | |
555 | |
556 for (int i = 0; i < spe_num; i++) { | |
793 | 557 update_task_create(light_sysswitch,size,LightSysSwitch,(int)SPE_0+i,data_update_wait); |
747 | 558 } |
559 | |
539 | 560 ppack->clear(); |
561 for (int i = 0; i < spackList_length; i++) { | |
562 SpanPack *spack = &spackList[i]; | |
563 int startx = 1; | |
564 int endx = split_screen_w; | |
565 | |
566 int starty = spack->info.y_top - split_screen_h + 1; | |
567 //int endy = spack->info.y_top; | |
568 int rangey = (starty + split_screen_h - 1 > this->height) | |
569 ? this->height - starty + 1 : split_screen_h; | |
570 | |
857 | 571 #if 1 |
572 | |
573 if(spack->info.size > 0) { | |
838 | 574 |
857 | 575 int array_task_num = (this->width + split_screen_w - 1) / split_screen_w; |
576 HTaskPtr task_draw_array = manager->create_task_array(DrawSpan, array_task_num, 6, 1, rangey); | |
577 Task *task_draw = 0; | |
578 | |
579 while (startx < this->width) { | |
580 | |
839 | 581 // Draw SpanPack |
857 | 582 |
839 | 583 task_draw = task_draw_array->next_task_array(DrawSpan,task_draw); |
584 task_draw->set_param(0,(memaddr)&pixels[(startx-1) + this->width*(starty-1)]); | |
585 task_draw->set_param(1,this->width); | |
586 task_draw->set_param(2,startx); | |
587 task_draw->set_param(3,endx); | |
588 task_draw->set_param(4,rangey); | |
589 task_draw->set_param(5,spack->info.size); | |
838 | 590 |
839 | 591 task_draw->set_inData(0,spack, sizeof(SpanPack)); |
592 | |
593 for (int i = 0; i < rangey; i++) { | |
857 | 594 task_draw->set_outData(i, |
595 &pixels[(startx-1) + this->width*(starty-1 + i) ], | |
596 (endx-startx+1)*sizeof(int)); | |
839 | 597 } |
598 | |
599 startx += split_screen_w; | |
600 endx += split_screen_w; | |
601 | |
602 if (endx > this->width) { | |
603 endx = this->width; | |
604 } | |
605 | |
857 | 606 } |
607 | |
608 task_draw_array->spawn_task_array(task_draw->next()); | |
609 task_draw_array->set_cpu(SPE_ANY); | |
610 task_next->wait_for(task_draw_array); | |
611 task_draw_array->wait_for(data_update_wait); | |
612 task_draw_array->spawn(); | |
854 | 613 |
857 | 614 } else { |
615 | |
616 memset(&pixels[(startx-1)+this->width*(starty-1)], | |
617 0, (this->width)*sizeof(int)*rangey); | |
838 | 618 |
857 | 619 } |
620 | |
621 #else | |
838 | 622 |
623 HTaskPtr task_draw; | |
624 | |
539 | 625 while (startx < this->width) { |
857 | 626 if (spack->info.size > 0) { |
539 | 627 // Draw SpanPack |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
628 task_draw = manager->create_task(DrawSpan); |
539 | 629 |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
630 task_draw->set_param(0, |
603
57ec231bc8ac
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
631 (memaddr)&pixels[(startx-1) + this->width*(starty-1)]); |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
632 task_draw->set_param(1,this->width); |
659 | 633 task_draw->set_param(2,startx); |
634 task_draw->set_param(3,endx); | |
635 task_draw->set_param(4,rangey); | |
838 | 636 task_draw->set_param(5,spack->info.size); |
659 | 637 |
638 task_draw->add_inData(spack, sizeof(SpanPack)); | |
616
350b9b8c985f
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
639 |
617
df618a956eb9
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
640 for (int i = 0; i < rangey; i++) { |
616
350b9b8c985f
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
641 task_draw->add_outData( |
617
df618a956eb9
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
642 &pixels[(startx-1) + this->width*(starty-1 + i) ], |
df618a956eb9
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
643 (endx-startx+1)*sizeof(int)); |
616
350b9b8c985f
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
644 } |
838 | 645 |
857 | 646 } else { |
539 | 647 // 7.7.3 SL1 Data Cache Range Set to Zero コマンド |
648 // を使って、DMAでclearするべき... ということは、 | |
649 // それもSPEでやる方が良い? | |
857 | 650 memset(&pixels[(startx-1)+this->width*(starty-1)], |
651 0, (this->width)*sizeof(int)*rangey); | |
652 break; | |
653 } | |
539 | 654 |
747 | 655 task_draw->set_cpu(SPE_ANY); |
539 | 656 task_next->wait_for(task_draw); |
747 | 657 task_draw->wait_for(data_update_wait); |
539 | 658 task_draw->spawn(); |
659 | |
660 startx += split_screen_w; | |
661 endx += split_screen_w; | |
662 | |
663 if (endx > this->width) { | |
664 endx = this->width; | |
665 } | |
666 } | |
838 | 667 #endif |
668 | |
792 | 669 } |
670 | |
671 data_update_wait->spawn(); | |
747 | 672 |
673 } | |
674 | |
675 void | |
676 Viewer::run_finish() | |
677 { | |
678 dev->free_device(); | |
679 if (this_time != start_time) { | |
680 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); | |
681 } | |
682 | |
683 delete sgroot; | |
684 // delete sgroot_2; | |
685 quit(); | |
539 | 686 } |
687 | |
688 /* end */ |