Mercurial > hg > Game > Cerium
annotate Renderer/Engine/viewer.cc @ 1087:20f09564c586 draft
fix (not yet tested)
author | root@localhost.localdomain |
---|---|
date | Fri, 17 Dec 2010 18:34:29 +0900 |
parents | 9061d19b8550 |
children | 652791a4a324 c9d0683c9b39 |
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" | |
1050 | 7 #include "matrix_calc.h" |
539 | 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) */ | |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
23 static int start_time; |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
24 static int this_time; |
539 | 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 | |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
35 RederingData r[2]; |
539 | 36 |
994 | 37 int ppi, spi = 0; |
907 | 38 |
539 | 39 /** |
40 * | |
41 */ | |
42 | |
747 | 43 Viewer::Viewer(TaskManager *m, ViewerDevice *vd, int b, int w, int h, int _num) |
539 | 44 { |
45 spe_num = _num; | |
747 | 46 manager = m; |
895
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
47 |
747 | 48 dev = vd; |
49 pixels = dev->video_init(manager, b, w, h); | |
50 | |
895
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
51 width = dev->width; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
52 height = dev->height; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
53 bpp = dev->bpp; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
54 |
539 | 55 } |
56 | |
57 int | |
58 Viewer::get_ticks(void) | |
59 { | |
60 int time; | |
61 time = SDL_GetTicks(); | |
62 return time; | |
63 } | |
64 | |
65 bool | |
66 Viewer::quit_check(void) | |
67 { | |
68 SDL_Event event; | |
69 | |
70 while(SDL_PollEvent(&event)) { | |
71 if (event.type==SDL_QUIT) { | |
72 return true; | |
73 } | |
74 } | |
75 | |
76 Uint8 *keys=SDL_GetKeyState(NULL); | |
77 | |
78 if (keys[SDLK_q] == SDL_PRESSED) { | |
79 return true; | |
80 } | |
81 | |
82 return false; | |
83 } | |
84 | |
85 void | |
86 Viewer::quit(void) | |
87 { | |
88 SDL_Quit(); | |
89 } | |
90 | |
91 | |
92 void | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
93 Viewer::run_init(TaskManager *manager, Application *app) |
539 | 94 { |
95 this->manager = manager; | |
96 | |
747 | 97 if (spe_num == 0) spe_num = 1; |
98 | |
539 | 99 sgroot = new SceneGraphRoot(this->width, this->height); |
572 | 100 sgroot->tmanager = manager; |
792 | 101 |
102 int light_num = 4; | |
103 int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4) | |
761 | 104 int light_size = size / sizeof(float); |
747 | 105 |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
747
diff
changeset
|
106 light_xyz_stock = (float *)manager->allocate(size); |
747 | 107 light_xyz = (float *)manager->allocate(size); |
761 | 108 |
109 for (int i = 0; i < light_size ; i++) { | |
110 light_xyz[i] = 0.0f; | |
111 } | |
747 | 112 |
907 | 113 |
792 | 114 for(int i = 0; i < spe_num; i++) { |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
115 HTaskPtr data_load = manager->create_task(DataAllocate); |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
116 data_load->set_param(0,(memaddr)3); // num of allocate block |
988 | 117 data_load->set_param(1,(memaddr)(sizeof(float)*4*light_num)); // 1st allocate size |
118 data_load->set_param(2,(memaddr)Light); // 1st id | |
119 data_load->set_param(3,(memaddr)(light_num * sizeof(int))); // 2nd size | |
120 data_load->set_param(4,(memaddr)LightSwitch); // 2nd id | |
121 data_load->set_param(5,(memaddr)16); // 3rd size | |
122 data_load->set_param(6,(memaddr)LightSysSwitch); // 3rd id | |
747 | 123 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
124 data_load->spawn(); | |
125 } | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
126 |
792 | 127 light_switch = (int*)manager->allocate(size); |
793 | 128 |
792 | 129 for (int i = 0; i < light_num; i++) { |
130 light_switch[i] = 0; | |
131 } | |
132 | |
133 size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング | |
134 | |
793 | 135 light_sysswitch = (int*)manager->allocate(size); |
136 | |
843
de64695a7f02
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
842
diff
changeset
|
137 for (unsigned int i = 0; i < size / sizeof(int); i++) { |
793 | 138 light_sysswitch[i] = 0; |
139 } | |
140 | |
984 | 141 start_time = get_ticks(); |
142 this_time = 0; | |
143 frames = 0; | |
144 | |
1033
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1004
diff
changeset
|
145 this->app = app; |
543 | 146 MainLoop *mainloop = app->init(this, this->width, this->height); |
147 mainloop->mainLoop(); | |
539 | 148 } |
149 | |
150 | |
151 HTaskPtr | |
152 Viewer::initLoop() | |
153 { | |
154 HTaskPtr task_next; | |
155 HTaskPtr task_tex; | |
156 | |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
157 for(int i=0;i<2;i++) { |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
158 r[i].ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); |
989 | 159 r[i].ppack->next = 0; |
539 | 160 |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
161 r[i].spackList_length = (this->height + split_screen_h - 1) / split_screen_h; |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
162 r[i].spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*r[i].spackList_length); |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
163 // printf("spackList %0lx height %d\n",(unsigned long)r[i].spackList, this->height); |
539 | 164 |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
165 /** |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
166 * SPU に送る address list は 16 バイト倍数でないといけない。 |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
167 * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
168 * length_align を求めている。はみ出した部分は使われない |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
169 * (ex) spackList_length が 13 の場合 |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
170 * spackList_length_align = 16; |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
171 * 実際に送るデータは64バイトになるのでOK |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
172 * 14,15,16 の部分は何も入らない。 |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
173 */ |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
174 r[i].spackList_length_align = (r[i].spackList_length + 3)&(~3); |
539 | 175 |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
176 /* 各 SPU が持つ、SpanPack の address list */ |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
177 r[i].spackList_ptr = |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
178 (SpanPack**)manager->allocate(sizeof(SpanPack*)*r[i].spackList_length_align); |
539 | 179 |
988 | 180 for (int j = 0; j < r[i].spackList_length; j++) { |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
181 r[i].spackList_ptr[j] = &r[i].spackList[j]; |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
182 } |
539 | 183 |
988 | 184 for (int j = 1; j <= r[i].spackList_length; j++) { |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
185 r[i].spackList[j-1].init(j*split_screen_h); |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
186 } |
539 | 187 } |
188 | |
826 | 189 task_next = manager->create_task(Dummy,0,0,0,0); |
539 | 190 |
659 | 191 // ここは、Iterator を用意するべきだよね |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
192 for (int j = 0; j < spe_num; j++) { |
826 | 193 task_tex = manager->create_task(LoadTexture,0,0,0,0); |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
194 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + j)); |
826 | 195 task_next->wait_for(task_tex); |
747 | 196 task_tex->spawn(); |
539 | 197 } |
198 | |
792 | 199 |
539 | 200 return task_next; |
201 } | |
202 | |
203 | |
204 void | |
205 Viewer::getKey() | |
206 { | |
207 Pad *pad = sgroot->getController(); | |
208 if (pad->right.isHold()) { | |
209 keyPtr->right = HOLD; | |
210 } else if (pad->right.isPush()) { | |
211 keyPtr->right = PUSH; | |
212 } else { | |
213 keyPtr->right = NONE; | |
214 } | |
215 | |
216 if (pad->left.isHold()) { | |
217 keyPtr->left = HOLD; | |
218 } else if (pad->left.isPush()) { | |
219 keyPtr->left = PUSH; | |
220 } else { | |
221 keyPtr->left = NONE; | |
222 } | |
223 | |
224 if (pad->up.isHold()) { | |
225 keyPtr->up = HOLD; | |
226 } else if (pad->up.isPush()) { | |
227 keyPtr->up = PUSH; | |
228 } else { | |
229 keyPtr->up = NONE; | |
230 } | |
231 | |
232 if (pad->down.isHold()) { | |
233 keyPtr->down = HOLD; | |
234 } else if (pad->down.isPush()) { | |
235 keyPtr->down = PUSH; | |
236 } else { | |
237 keyPtr->down = NONE; | |
238 } | |
239 | |
240 if (pad->circle.isHold()) { | |
241 keyPtr->circle = HOLD; | |
242 } else if (pad->circle.isPush()) { | |
243 keyPtr->circle = PUSH; | |
244 } else { | |
245 keyPtr->circle = NONE; | |
246 } | |
247 } | |
248 | |
249 static void | |
550 | 250 post2runMoveDrawLoop(SchedTask *m, void *viewer_, void *arg) |
539 | 251 { |
252 Viewer *viewer = (Viewer*)viewer_; | |
253 | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
254 // 同じ PPE 上なので sgroot(ポインタ) を set_param で送る。 |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
255 //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
|
256 //send_key_task->set_param((int)sgroot); |
539 | 257 // set input data -> viewer keyPtr |
258 viewer->getKey(); | |
826 | 259 //HTaskPtr update_key = viewer->manager->create_task(UpdateKey,viewer->keyPtr, sizeof(key_stat),0,0); |
260 HTaskPtr update_key = viewer->manager->create_task(UpdateKey,0,0,0,0); | |
539 | 261 update_key->add_inData(viewer->keyPtr, sizeof(key_stat)); |
747 | 262 //update_key->set_cpu(SPE_0); |
539 | 263 update_key->spawn(); |
264 | |
265 /* TASK_MOVE は外から引数で取ってくるべき */ | |
266 //HTaskPtr move_task = viewer->manager->create_task(viewer->app->move_taskid); | |
965
e0427cdee770
removing user task from Renderer Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
926
diff
changeset
|
267 // 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
|
268 //move_task->set_param(sgroot); |
539 | 269 |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
270 //HTaskPtr draw_task = viewer->manager->create_task(Draw); |
539 | 271 |
272 /* rendering task test */ | |
826 | 273 HTaskPtr draw_task = viewer->manager->create_task(Dummy,0,0,0,0); |
274 HTaskPtr draw_dummy = viewer->manager->create_task(Dummy,0,0,0,0); | |
539 | 275 |
826 | 276 HTaskPtr switch_task = viewer->manager->create_task(Switch,0,0,0,0); |
539 | 277 viewer->draw_dummy = draw_dummy; |
278 switch_task->wait_for(draw_dummy); | |
550 | 279 draw_task->set_post(post2speRendering, (void*)viewer, 0); |
539 | 280 |
965
e0427cdee770
removing user task from Renderer Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
926
diff
changeset
|
281 // switch_task->wait_for(move_task); |
539 | 282 switch_task->wait_for(draw_task); |
965
e0427cdee770
removing user task from Renderer Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
926
diff
changeset
|
283 // move_task->spawn(); |
539 | 284 draw_task->spawn(); |
285 | |
550 | 286 switch_task->set_post(post2runMoveDrawLoop, (void*)viewer, 0); |
539 | 287 switch_task->spawn(); |
288 | |
289 } | |
290 | |
291 void | |
292 Viewer::mainLoop() | |
293 { | |
294 HTaskPtr task_next = initLoop(); | |
295 | |
994 | 296 task_next->set_post(&post2runLoop, (void *)this, (void*)pixels); // set_post(function(this->run_loop()), NULL) |
539 | 297 task_next->spawn(); |
298 } | |
299 | |
300 void | |
747 | 301 Viewer::run_loop(HTaskPtr task_next) |
539 | 302 { |
1045
11a9bc9928d0
mainLoop is not a part of mainLoop in viwer.... move application_task
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1043
diff
changeset
|
303 task_next = app->application_task(task_next, this); |
747 | 304 dev->clear_screen(); |
305 | |
306 bool quit_flg; | |
307 quit_flg = quit_check(); | |
308 if (quit_flg == true) { | |
309 this_time = get_ticks(); | |
310 run_finish(); | |
311 return; | |
312 } | |
313 | |
314 dev->clean_pixels(); | |
994 | 315 |
981
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
969
diff
changeset
|
316 pixels = dev->flip_screen(pixels); |
747 | 317 sgroot->updateControllerState(); |
1043
3a49a0825963
Merged ( app_loop should return 1, if you want to use allExecute )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
diff
changeset
|
318 if (app->app_loop(this)) { |
1042
d0bb27bf985b
AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1035
diff
changeset
|
319 //TaskArray を使うか使わないか |
d0bb27bf985b
AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1035
diff
changeset
|
320 if (sgroot->gtask_array != NULL) { |
d0bb27bf985b
AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1035
diff
changeset
|
321 sgroot->create_task_array(); |
d0bb27bf985b
AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1035
diff
changeset
|
322 sgroot->allExecute(width, height); |
d0bb27bf985b
AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1035
diff
changeset
|
323 sgroot->task_array_finish(); |
d0bb27bf985b
AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1035
diff
changeset
|
324 } else { |
d0bb27bf985b
AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1035
diff
changeset
|
325 sgroot->allExecute(width, height); |
d0bb27bf985b
AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1035
diff
changeset
|
326 } |
1003
37842bbd35f0
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
327 } |
37842bbd35f0
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
328 |
747 | 329 light_xyz_stock = sgroot->getLightVector(); |
792 | 330 light_switch_stock = sgroot->getLightSwitch(); |
793 | 331 light_sysswitch_stock = sgroot->getLightSysSwitch(); |
747 | 332 //sgroot->checkRemove(); |
333 | |
334 // ここから下は Rendering という関数にする | |
335 rendering(task_next); | |
539 | 336 } |
337 | |
338 | |
339 | |
340 void | |
341 Viewer::run_collision() | |
342 { | |
343 } | |
344 | |
345 void | |
550 | 346 post2rendering(SchedTask *s, void *viewer_, void *arg) |
539 | 347 { |
348 Viewer *viewer = (Viewer *)viewer_; | |
826 | 349 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 350 viewer->rendering(task_next); |
351 } | |
352 | |
353 void | |
354 Viewer::rendering(HTaskPtr task_next) | |
355 { | |
747 | 356 common_rendering(task_next, sgroot); |
539 | 357 |
358 // Barrier 同期 | |
359 // run_draw() を呼ぶ post2runDraw | |
550 | 360 task_next->set_post(post2runDraw, (void*)this, 0); // set_post(function(this->run_draw()), NULL) |
539 | 361 task_next->spawn(); |
362 | |
363 // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ | |
364 } | |
365 | |
366 static void | |
550 | 367 post2runLoop(SchedTask *s, void *viewer_, void *arg) |
539 | 368 { |
994 | 369 |
370 | |
539 | 371 Viewer *viewer = (Viewer*)viewer_; |
826 | 372 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 373 viewer->run_loop(task_next); |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
374 psx_sync_n(); |
539 | 375 } |
376 | |
377 static void | |
550 | 378 post2runDraw(SchedTask *s, void *viewer_, void *arg) |
539 | 379 { |
380 Viewer *viewer = (Viewer*)viewer_; | |
826 | 381 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 382 viewer->run_draw(task_next); |
383 | |
384 } | |
385 | |
386 void | |
387 Viewer::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする | |
388 { | |
389 common_draw(task_next); | |
390 | |
994 | 391 task_next->set_post(post2runLoop, (void*)this, (void*)pixels); // set_post(function(this->run_loop()), NULL) |
539 | 392 task_next->spawn(); |
393 // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ | |
394 | |
395 frames++; | |
396 } | |
397 | |
398 | |
399 static void | |
550 | 400 post2speRendering(SchedTask *s, void *viewer_, void *arg) |
539 | 401 { |
402 Viewer *viewer = (Viewer*)viewer_; | |
826 | 403 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 404 viewer->spe_rendering(task_next); |
405 } | |
406 | |
407 void | |
408 Viewer::spe_rendering(HTaskPtr task_next) | |
409 { | |
747 | 410 common_rendering(task_next, sgroot); |
539 | 411 |
412 this->draw_dummy->wait_for(task_next); | |
550 | 413 task_next->set_post(post2speDraw, (void*)this, 0); |
539 | 414 task_next->spawn(); |
415 | |
416 } | |
417 | |
418 static void | |
550 | 419 post2speDraw(SchedTask *s, void *viewer_, void *arg) |
539 | 420 { |
421 Viewer *viewer = (Viewer*)viewer_; | |
826 | 422 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
539 | 423 viewer->spe_draw(task_next); |
424 } | |
425 | |
426 void | |
427 Viewer::spe_draw(HTaskPtr task_next) | |
428 { | |
429 common_draw(task_next); | |
430 | |
431 this->draw_dummy->wait_for(task_next); | |
432 task_next->spawn(); | |
433 this->draw_dummy->spawn(); | |
434 | |
435 frames++; | |
436 } | |
437 | |
907 | 438 |
915
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
439 |
908 | 440 void |
915
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
441 coord_allocate(int &cur_point, float *coord_pack, int spe_num, |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
442 int alloc_size, HTaskPtr alloc_wait, TaskManager *manager) |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
443 { |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
444 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
445 for (int i = 0; i < spe_num; i++) { |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
446 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
447 HTaskPtr data_alloc = manager->create_task(DataAllocate); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
448 //data_alloc->set_inData(0, &coord_pack[cur_point], alloc_size); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
449 data_alloc->set_param(0,(memaddr)alloc_size); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
450 data_alloc->set_param(1,(memaddr)SG_COORD); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
451 data_alloc->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
452 alloc_wait->wait_for(data_alloc); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
453 data_alloc->spawn(); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
454 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
455 } |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
456 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
457 cur_point += alloc_size / sizeof(float); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
458 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
459 } |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
460 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
461 void |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
462 coord_free(int spe_num, TaskManager *manager, HTaskPtr alloc_wait) |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
463 { |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
464 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
465 for (int i = 0; i < spe_num; i++) { |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
466 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
467 HTaskPtr data_free = manager->create_task(DataFree); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
468 data_free->set_param(0,(memaddr)SG_COORD); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
469 data_free->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
470 data_free->wait_for(alloc_wait); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
471 data_free->spawn(); |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
472 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
473 } |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
474 |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
475 } |
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
476 |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
477 /* flag_drawable な Scenegraph の総数を求める */ |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
478 int |
1020 | 479 sg_drawable_num(SceneGraphPtr scenegraph) |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
480 { |
1020 | 481 SceneGraphPtr sg = scenegraph; |
482 | |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
483 int sg_count = 0; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
484 while (sg) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
485 if (sg->flag_drawable) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
486 sg_count++; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
487 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
488 if (sg->children != NULL) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
489 sg = sg->children; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
490 } else if (sg->brother != NULL) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
491 sg = sg->brother; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
492 } else { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
493 while (sg) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
494 if (sg->brother != NULL) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
495 sg = sg->brother; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
496 break; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
497 } else { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
498 if (sg->parent == NULL) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
499 sg = NULL; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
500 break; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
501 } else { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
502 sg = sg->parent; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
503 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
504 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
505 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
506 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
507 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
508 return sg_count; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
509 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
510 |
915
aa9728394194
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
511 void |
1028 | 512 create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next, SceneGraphRootPtr sgroot) |
907 | 513 { |
514 | |
1013 | 515 /* |
516 * SceneGraph を辿って coord_xyz, coord_tex, normal, matrix, real_matrix 及び、 | |
517 * PolygonPack の TrianglePack (空) を送る。pp->info.size の計算もここで。 | |
518 * | |
519 */ | |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
520 |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
521 int sg_num = sg_drawable_num(sg); |
1020 | 522 int sg_division = sg_num / spe_num; |
523 int residue = sg_num % spe_num; | |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
524 |
1020 | 525 HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num); |
526 Task **pptask = (Task**)manager->allocate(sizeof(Task*)*spe_num); | |
527 | |
528 for (int k = 0; k < spe_num-1; k++) { | |
529 task_array[k] = manager->create_task_array(CreatePolygonFromSceneGraph,sg_division,4,6,1); | |
530 pptask[k] = 0; | |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
531 } |
1020 | 532 |
533 task_array[spe_num] = manager->create_task_array(CreatePolygonFromSceneGraph, | |
534 sg_division+residue,4,6,1); | |
535 pptask[spe_num] = 0; | |
536 | |
537 int k = 0; | |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
538 |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
539 while (sg) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
540 if (sg->flag_drawable) { |
1028 | 541 if(k < spe_num * sg_division) { |
1020 | 542 k %= spe_num-1; |
543 } else { | |
544 k = spe_num; | |
545 } | |
546 pptask[k] = task_array[k]->next_task_array(CreatePolygonFromSceneGraph,pptask[k]); | |
1035 | 547 |
548 pptask[k]->set_inData(0, &sg->coord_xyz, sizeof(float)*sg->size); | |
549 pptask[k]->set_inData(1, &sg->coord_tex, sizeof(float)*sg->size); | |
550 pptask[k]->set_inData(2, &sg->normal , sizeof(float)*sg->size); | |
551 pptask[k]->set_inData(3, &sg->matrix , sizeof(float)*16); | |
552 pptask[k]->set_inData(4, &sg->real_matrix, sizeof(float)*12); | |
553 pptask[k]->set_inData(5, &sg->texture_info.pixels, sizeof(uint32)); // 4 byte | |
554 | |
555 // 4 byte * 4 = 16 byte | |
556 pptask[k]->set_param(0,(memaddr)sg->size); // 4byte | |
1020 | 557 pptask[k]->set_param(1,(memaddr)sg->texture_info.t_w); |
558 pptask[k]->set_param(2,(memaddr)sg->texture_info.t_h); | |
559 pptask[k]->set_param(3,(memaddr)sg->texture_info.scale_max); | |
560 | |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
561 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
562 if (sg->children != NULL) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
563 sg = sg->children; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
564 } else if (sg->brother != NULL) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
565 sg = sg->brother; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
566 } else { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
567 while (sg) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
568 if (sg->brother != NULL) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
569 sg = sg->brother; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
570 break; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
571 } else { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
572 if (sg->parent == NULL) { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
573 sg = NULL; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
574 break; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
575 } else { |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
576 sg = sg->parent; |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
577 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
578 } |
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
579 } |
1020 | 580 } |
1026 | 581 k++; |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
582 } |
1026 | 583 for (int k = 0; k < spe_num; k++) { |
584 task_array[k]->spawn_task_array(pptask[k]->next()); | |
585 task_array[k]->set_cpu(SPE_ANY); | |
586 task_array[k]->spawn(); | |
587 if (sgroot->gtask_array != NULL) { | |
588 HTaskPtr game_task_array = sgroot->gtask_array->get_task_array(); | |
1028 | 589 task_array[k]->wait_for(game_task_array); |
1026 | 590 } |
1028 | 591 task_next->wait_for(task_array[k]); |
1026 | 592 } |
907 | 593 } |
594 | |
860 | 595 void |
747 | 596 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot) |
539 | 597 { |
860 | 598 |
599 #if SPE_CREATE_POLYGON | |
600 | |
907 | 601 SceneGraphPtr sg = sgroot->getDrawSceneGraph(); |
602 | |
1028 | 603 create_pp_task(sg, manager, spe_num, task_next, sgroot); |
907 | 604 |
908 | 605 #if SPE_CREATE_POLYGON_CHECK |
606 check_matrix(matrix_info,sg); | |
607 #endif | |
909 | 608 |
609 #else | |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
610 //SceneGraphPtr sg = sgroot->getDrawSceneGraph(); |
1035 | 611 //printf("sg->size = %lld\n", sizeof(pixels)); |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
612 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); |
539 | 613 // SceneGraph(木構造) -> PolygonPack |
614 | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
615 task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
616 task_create_pp->set_param(1,(memaddr)r[ppi].ppack); |
1003
37842bbd35f0
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
617 |
37842bbd35f0
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
618 /* GameTask の処理の終了を待ってからポリゴンを作る */ |
37842bbd35f0
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
619 if (sgroot->gtask_array != NULL) { |
37842bbd35f0
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
620 HTaskPtr game_task_array = sgroot->gtask_array->get_task_array(); |
37842bbd35f0
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
621 task_create_pp->wait_for(game_task_array); |
37842bbd35f0
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
622 } |
539 | 623 task_next->wait_for(task_create_pp); |
747 | 624 |
909 | 625 #endif |
626 | |
747 | 627 int range_base = spe_num; |
628 | |
539 | 629 // 切り上げのつもり |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
630 int range = (r[spi].spackList_length + range_base - 1) / range_base; |
539 | 631 |
632 for (int i = 0; i < range_base; i++) { | |
633 int index_start = range*i; | |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
634 int index_end = (index_start + range >= r[spi].spackList_length) |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
635 ? r[spi].spackList_length : index_start + range; |
1056
4955cedb17e5
endy overflow in common rendering
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1050
diff
changeset
|
636 int starty = index_start*split_screen_h + 1; |
4955cedb17e5
endy overflow in common rendering
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1050
diff
changeset
|
637 int endy = index_end*split_screen_h; |
4955cedb17e5
endy overflow in common rendering
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1050
diff
changeset
|
638 if (starty<=0) starty = 1; |
4955cedb17e5
endy overflow in common rendering
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1050
diff
changeset
|
639 if (endy>height) endy = height; |
539 | 640 |
659 | 641 HTaskPtr task_create_sp = manager->create_task(CreateSpan); |
539 | 642 |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
643 task_create_sp->set_param(0,index_start); |
747 | 644 |
539 | 645 /** |
646 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 | |
647 * [ 1.. 80] [ 81..160] [161..240] | |
648 * [241..320] [321..400] [401..480] | |
649 * | |
650 * ex. screen_height が 1080, spenum が 5 の場合、 | |
651 * [ 1..216] [217..432] [433..648] | |
652 * [649..864] [865..1080] | |
653 */ | |
747 | 654 |
1056
4955cedb17e5
endy overflow in common rendering
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1050
diff
changeset
|
655 task_create_sp->set_param(1,starty); |
4955cedb17e5
endy overflow in common rendering
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1050
diff
changeset
|
656 task_create_sp->set_param(2,endy); |
539 | 657 |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
658 task_create_sp->add_inData(r[ppi].ppack, sizeof(PolygonPack)); |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
659 task_create_sp->add_inData(r[spi].spackList_ptr, |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
660 sizeof(SpanPack*)*r[spi].spackList_length_align); |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
661 task_create_sp->add_inData(&r[spi].spackList[index_start], sizeof(SpanPack)); |
659 | 662 |
539 | 663 task_next->wait_for(task_create_sp); |
664 task_create_sp->wait_for(task_create_pp); | |
665 | |
747 | 666 task_create_sp->set_cpu(SPE_ANY); |
1085 | 667 // task_create_sp->set_cpu(CPU_PPE); |
539 | 668 task_create_sp->spawn(); |
669 } | |
670 | |
860 | 671 task_create_pp->spawn(); |
539 | 672 } |
673 | |
792 | 674 |
539 | 675 void |
676 Viewer::common_draw(HTaskPtr task_next) | |
677 { | |
678 | |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
679 //task_next = manager->create_task(Dummy); |
539 | 680 //task_next->set_post(post2runLoop, (void*)this); |
681 | |
792 | 682 //Light info update |
747 | 683 |
792 | 684 int light_num = 4; |
685 int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4) | |
761 | 686 int light_size = size / sizeof(float); |
747 | 687 |
761 | 688 for (int i = 0; i < light_size; i++) { |
792 | 689 light_xyz[i] = light_xyz_stock[i]; |
761 | 690 } |
792 | 691 |
692 for (int i = 0; i < light_num; i++) { | |
693 light_switch[i] = light_switch_stock[i]; | |
694 } | |
793 | 695 |
696 light_sysswitch[0] = light_sysswitch_stock; | |
985 | 697 |
698 | |
699 HTask *data_update_wait = 0; | |
700 for (int i = 0; i < spe_num; i++) { | |
701 data_update_wait = manager->create_task(DataUpdate); | |
702 data_update_wait->set_param(0,3); | |
703 data_update_wait->set_param(1,Light); // GlobalSet ID base | |
704 data_update_wait->set_inData(0,light_xyz,size); // Light | |
705 data_update_wait->set_inData(1,light_switch,light_num * sizeof(int)); // LightSwitch = Light+1 | |
706 data_update_wait->set_inData(2,light_sysswitch,16); // LightSysSwitch = Light+2 | |
707 data_update_wait->set_cpu((CPU_TYPE)(SPE_0+i)); | |
708 data_update_wait->spawn(); | |
792 | 709 } |
710 | |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
711 ppi ^= 1; |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
712 r[ppi].ppack->clear(); |
914 | 713 |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
714 for (int i = 0; i < r[spi].spackList_length; i++) { |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
715 SpanPack *spack = &r[spi].spackList[i]; |
539 | 716 int startx = 1; |
717 int endx = split_screen_w; | |
718 | |
719 int starty = spack->info.y_top - split_screen_h + 1; | |
720 //int endy = spack->info.y_top; | |
721 int rangey = (starty + split_screen_h - 1 > this->height) | |
722 ? this->height - starty + 1 : split_screen_h; | |
723 | |
889
5f5301028e29
minor fix. Redering Engine not worked yet.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
885
diff
changeset
|
724 #if 1 |
857 | 725 |
914 | 726 // mem_flag は spe 側で黒い部分を 0 で埋めるフラグ |
727 if(spack->info.size > 0 || mem_flag == 1) { | |
838 | 728 |
857 | 729 int array_task_num = (this->width + split_screen_w - 1) / split_screen_w; |
730 HTaskPtr task_draw_array = manager->create_task_array(DrawSpan, array_task_num, 6, 1, rangey); | |
731 Task *task_draw = 0; | |
732 | |
733 while (startx < this->width) { | |
734 | |
839 | 735 // Draw SpanPack |
857 | 736 |
839 | 737 task_draw = task_draw_array->next_task_array(DrawSpan,task_draw); |
738 task_draw->set_param(0,(memaddr)&pixels[(startx-1) + this->width*(starty-1)]); | |
739 task_draw->set_param(1,this->width); | |
740 task_draw->set_param(2,startx); | |
741 task_draw->set_param(3,endx); | |
742 task_draw->set_param(4,rangey); | |
743 task_draw->set_param(5,spack->info.size); | |
838 | 744 |
839 | 745 task_draw->set_inData(0,spack, sizeof(SpanPack)); |
746 | |
747 for (int i = 0; i < rangey; i++) { | |
857 | 748 task_draw->set_outData(i, |
749 &pixels[(startx-1) + this->width*(starty-1 + i) ], | |
750 (endx-startx+1)*sizeof(int)); | |
839 | 751 } |
752 | |
753 startx += split_screen_w; | |
754 endx += split_screen_w; | |
755 | |
756 if (endx > this->width) { | |
757 endx = this->width; | |
758 } | |
759 | |
857 | 760 } |
761 | |
762 task_draw_array->spawn_task_array(task_draw->next()); | |
763 task_draw_array->set_cpu(SPE_ANY); | |
764 task_next->wait_for(task_draw_array); | |
765 task_draw_array->spawn(); | |
854 | 766 |
857 | 767 |
914 | 768 |
769 } else { | |
770 | |
857 | 771 memset(&pixels[(startx-1)+this->width*(starty-1)], |
772 0, (this->width)*sizeof(int)*rangey); | |
838 | 773 |
914 | 774 } |
775 | |
857 | 776 |
777 #else | |
838 | 778 |
779 HTaskPtr task_draw; | |
780 | |
539 | 781 while (startx < this->width) { |
857 | 782 if (spack->info.size > 0) { |
539 | 783 // Draw SpanPack |
615
184d6d3f0cd9
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
784 task_draw = manager->create_task(DrawSpan); |
539 | 785 |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
617
diff
changeset
|
786 task_draw->set_param(0, |
603
57ec231bc8ac
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
787 (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
|
788 task_draw->set_param(1,this->width); |
659 | 789 task_draw->set_param(2,startx); |
790 task_draw->set_param(3,endx); | |
791 task_draw->set_param(4,rangey); | |
838 | 792 task_draw->set_param(5,spack->info.size); |
659 | 793 |
794 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
|
795 |
617
df618a956eb9
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
796 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
|
797 task_draw->add_outData( |
617
df618a956eb9
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
798 &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
|
799 (endx-startx+1)*sizeof(int)); |
616
350b9b8c985f
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
800 } |
838 | 801 |
857 | 802 } else { |
539 | 803 // 7.7.3 SL1 Data Cache Range Set to Zero コマンド |
804 // を使って、DMAでclearするべき... ということは、 | |
805 // それもSPEでやる方が良い? | |
857 | 806 memset(&pixels[(startx-1)+this->width*(starty-1)], |
807 0, (this->width)*sizeof(int)*rangey); | |
808 break; | |
809 } | |
539 | 810 |
747 | 811 task_draw->set_cpu(SPE_ANY); |
539 | 812 task_next->wait_for(task_draw); |
813 task_draw->spawn(); | |
814 | |
815 startx += split_screen_w; | |
816 endx += split_screen_w; | |
817 | |
818 if (endx > this->width) { | |
819 endx = this->width; | |
820 } | |
821 } | |
838 | 822 #endif |
823 | |
792 | 824 } |
986
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
825 spi ^= 1; |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
826 for (int i = 1; i <= r[spi].spackList_length; i++) { |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
827 r[spi].spackList[i-1].reinit(i*split_screen_h); |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
828 } |
b3a8545eb2fa
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
829 |
792 | 830 |
925
292bb8c79cdb
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
831 if (profile) { |
983 | 832 if (frames % 50 == 49) { |
998 | 833 manager->show_profile(); |
983 | 834 this_time = get_ticks(); |
835 if (this_time != start_time) { | |
984 | 836 printf("\n%f FPS\n", ((((float)frames)*1000.0)/(this_time-start_time))); |
983 | 837 start_time = this_time; frames = 0; |
838 } | |
982
9f5e6bfb1c09
avoid WAIT in virtual console
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
981
diff
changeset
|
839 } |
925
292bb8c79cdb
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
840 } |
747 | 841 } |
842 | |
843 void | |
844 Viewer::run_finish() | |
845 { | |
846 dev->free_device(); | |
847 if (this_time != start_time) { | |
848 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); | |
849 } | |
925
292bb8c79cdb
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
850 if (profile) { |
292bb8c79cdb
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
851 manager->show_profile(); |
292bb8c79cdb
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
852 } |
747 | 853 |
854 delete sgroot; | |
855 // delete sgroot_2; | |
856 quit(); | |
539 | 857 } |
858 | |
859 /* end */ |