comparison Renderer/Engine/SgChange.cc @ 691:9d1bcc07734b

Test/SgRootChange not work
author hiroki@localhost.localdomain
date Tue, 08 Dec 2009 16:48:01 +0900
parents d0b8860c17f8
children fc0227b5cb5a
comparison
equal deleted inserted replaced
687:e009805443ce 691:9d1bcc07734b
10 #include "TaskManager.h" 10 #include "TaskManager.h"
11 #include <wchar.h> 11 #include <wchar.h>
12 #include "Pad.h" 12 #include "Pad.h"
13 #include "Application.h" 13 #include "Application.h"
14 #include "lindaapi.h" 14 #include "lindaapi.h"
15 15 #include "global_alloc.h"
16 static void post2runLoop(SchedTask *s,void *viewer,void *s1); 16
17 static void post2runLoop(SchedTask *s, void *viewer, void *s1);
18 static void post2runDraw(SchedTask *s, void *viewer, void *s1);
17 19
18 /* measure for FPS (Frame Per Second) */ 20 /* measure for FPS (Frame Per Second) */
19 int start_time; 21 int start_time;
20 int this_time; 22 int this_time;
21 int frames; 23 int frames;
27 SpanPackPtr *spackList_ptr; 29 SpanPackPtr *spackList_ptr;
28 30
29 int spackList_length; 31 int spackList_length;
30 int spackList_length_align; 32 int spackList_length_align;
31 33
32 /**
33 *
34 */
35
36 SgChange::SgChange(int b, int w, int h, int _num) 34 SgChange::SgChange(int b, int w, int h, int _num)
37 { 35 {
38 bpp = b; 36 bpp = b;
39 width = w; 37 width = w;
40 height = h; 38 height = h;
82 } 80 }
83 81
84 82
85 void 83 void
86 SgChange::run_init(TaskManager *manager, Application *app) 84 SgChange::run_init(TaskManager *manager, Application *app)
87 { 85 {
88 this->manager = manager; 86 this->manager = manager;
89 87
90 start_time = get_ticks(); 88 start_time = get_ticks();
91 this_time = 0; 89 this_time = 0;
92 frames = 0; 90 frames = 0;
93 91
94 // ココ! 92 // ココ!
95 sgroot_A = new SceneGraphRoot(this->width, this->height); 93 sgroot_A = new SceneGraphRoot(this->width, this->height);
96 sgroot_A->tmanager = manager; 94 sgroot_A->tmanager = manager;
97 sgroot_B = new SceneGraphRoot(this->width, this->height); 95 //sgroot_B = new SceneGraphRoot(this->width, this->height);
98 sgroot_B->tmanager = manager; 96 //sgroot_B->tmanager = manager;
97
98 int size = 4;
99 light_xyz[0] = 0.0f;
100 light_xyz[1] = 0.0f;
101 light_xyz[2] = 0.0f;
102 light_xyz[3] = 0.0f;
103
104 HTaskPtr data_load;
105 for(int i = 0; i < spe_num; i++) {
106 data_load = manager->create_task(DataLoad);
107 data_load->set_param(0, (memaddr)size);
108 data_load->set_param(1, (memaddr)LOAD_ID);
109 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i));
110 data_load->spawn();
111 }
99 112
100 MainLoop *mainloop = app->init_only_sg(this, this->width, this->height); 113 MainLoop *mainloop = app->init_only_sg(this, this->width, this->height);
101 114
102 mainloop->mainLoop(); 115 mainloop->mainLoop();
103 } 116 }
104 117
118 HTaskPtr
119 SgChange::initLoop()
120 {
121 HTaskPtr task_next;
122 HTaskPtr task_tex;
123
124 sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack));
125 sgpack->init();
126 ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack));
127
128 spackList_length = (this->height + split_screen_h - 1) / split_screen_h;
129 spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length);
130
131 spackList_length_align = (spackList_length + 3)&(~3);
132
133 spackList_ptr =
134 (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align);
135
136 for (int i = 0; i < spackList_length; i++) {
137 spackList_ptr[i] = &spackList[i];
138 }
139
140 for (int i = 1; i <= spackList_length; i++) {
141 spackList[i-1].init(i*split_screen_h);
142 }
143
144 task_next = manager->create_task(Dummy);
145
146 for (int i = 0; i < spe_num; i++) {
147 task_tex = manager->create_task(LoadTexture);
148 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i));
149 task_next->wait_for(task_tex);
150 task_tex->spawn();
151 }
152
153 return task_next;
154 }
155
105 void 156 void
106 SgChange::mainLoop() 157 SgChange::mainLoop()
107 { 158 {
108 HTaskPtr task_next = manager->create_task(Dummy); 159 HTaskPtr task_next = initLoop();
109 160
110 task_next->set_post(&post2runLoop, (void *)this, 0); // set_post(function(this->run_loop()), NULL) 161 task_next->set_post(&post2runLoop, (void *)this, 0); // set_post(function(this->run_loop()), NULL)
111 task_next->spawn(); 162 task_next->spawn();
112 } 163 }
164
165
113 166
114 static void 167 static void
115 post2runLoop(SchedTask *s, void *viewer_, void *arg) 168 post2runLoop(SchedTask *s, void *viewer_, void *arg)
116 { 169 {
117 SgChange *viewer = (SgChange*)viewer_; 170 SgChange *viewer = (SgChange*)viewer_;
139 this_time = get_ticks(); 192 this_time = get_ticks();
140 run_finish(); 193 run_finish();
141 return; 194 return;
142 } 195 }
143 196
197 clean_pixels();
198
199 for (int i = 1; i <= spackList_length; i++) {
200 spackList[i-1].reinit(i*split_screen_h);
201 }
202
203 //exchange_sgroot();
204 sgroot_A->updateControllerState();
144 sgroot_A->allExecute(width, height); 205 sgroot_A->allExecute(width, height);
145 exchange_sgroot(); 206 light_xyz_stock = sgroot_A->getLightVector();
146 207
147 //printf("Sgroot = %x\n", sgroot_A); 208 //printf("Sgroot = %x\n", sgroot_A);
148 209 /*
149 task_next->set_post(&post2runLoop, (void *)this, 0); 210 task_next->set_post(&post2runLoop, (void *)this, 0);
150 task_next->spawn(); 211 task_next->spawn();
151 } 212 */
152 213 rendering(task_next);
214 }
215
216 void
217 SgChange::rendering(HTaskPtr task_next)
218 {
219 common_rendering(task_next);
220
221 task_next->set_post(post2runDraw, (void*)this, 0); // set_post(function(this->run_draw()), NULL)
222 task_next->spawn();
223 }
224
225 void
226 SgChange::common_rendering(HTaskPtr task_next)
227 {
228 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph);
229
230 //task_create_pp->set_param(0, (memaddr)sgroot_B->getDrawSceneGraph());
231 task_create_pp->set_param(0, (memaddr)sgroot_A->getDrawSceneGraph());
232 task_create_pp->set_param(1, (memaddr)ppack);
233
234 task_next->wait_for(task_create_pp);
235
236 int range_base = spe_num;
237 int range = (spackList_length + range_base - 1) / range_base;
238
239 for (int i = 0; i < range_base; i++) {
240 int index_start = range*i;
241 int index_end = (index_start + range >= spackList_length)
242 ? spackList_length : index_start + range;
243
244 HTaskPtr task_create_sp = manager->create_task(CreateSpan);
245
246 task_create_sp->set_param(0,index_start);
247
248 task_create_sp->set_param(1,index_start*split_screen_h + 1);
249 task_create_sp->set_param(2,index_end*split_screen_h);
250
251 task_create_sp->add_inData(ppack, sizeof(PolygonPack));
252 task_create_sp->add_inData(spackList_ptr,
253 sizeof(SpanPack*)*spackList_length_align);
254 task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack));
255
256 task_next->wait_for(task_create_sp);
257 task_create_sp->wait_for(task_create_pp);
258
259 task_create_sp->set_cpu(SPE_ANY);
260 task_create_sp->spawn();
261 }
262
263 task_create_pp->spawn();
264 }
265
266 static void
267 post2runDraw(SchedTask *s, void *viewer_, void *arg)
268 {
269 SgChange *viewer = (SgChange *)viewer_;
270 HTaskPtr task_next = viewer->manager->create_task(Dummy);
271 viewer->run_draw(task_next);
272 }
273
274 void
275 SgChange::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする
276 {
277 common_draw(task_next);
278
279 task_next->set_post(post2runLoop, (void*)this, 0); // set_post(function(this->run_loop()), NULL)
280 task_next->spawn();
281
282 frames++;
283 }
284
285 void
286 SgChange::common_draw(HTaskPtr task_next)
287 {
288 HTaskPtr task_draw;
289
290 //Light info update
291 HTaskPtr data_update;
292 HTaskPtr data_update_wait;
293 int size = 4;
294
295 light_xyz[0] = light_xyz_stock[0];
296 light_xyz[1] = light_xyz_stock[1];
297 light_xyz[2] = light_xyz_stock[2];
298 light_xyz[3] = light_xyz_stock[3];
299
300 data_update_wait = manager->create_task(DataUpdate);
301 data_update_wait->add_inData(light_xyz, sizeof(float)*size);
302 data_update_wait->set_param(0, size);
303 data_update_wait->set_param(1, LOAD_ID);
304 data_update_wait->set_cpu((CPU_TYPE)((int)SPE_0));
305
306 for (int i = 1; i < spe_num; i++) {
307 data_update = manager->create_task(DataUpdate);
308 data_update->add_inData(light_xyz, sizeof(float)*size);
309 data_update->set_param(0, size);
310 data_update->set_param(1, LOAD_ID);
311 data_update->set_cpu((CPU_TYPE)((int)SPE_0 + i));
312 data_update_wait->wait_for(data_update);
313 data_update->spawn();
314 }
315
316 data_update_wait->spawn();
317
318 ppack->clear();
319 for (int i = 0; i < spackList_length; i++) {
320 SpanPack *spack = &spackList[i];
321 int startx = 1;
322 int endx = split_screen_w;
323
324 int starty = spack->info.y_top - split_screen_h + 1;
325 //int endy = spack->info.y_top;
326 int rangey = (starty + split_screen_h - 1 > this->height)
327 ? this->height - starty + 1 : split_screen_h;
328
329 while (startx < this->width) {
330 if (spack->info.size > 0) {
331 // Draw SpanPack
332 task_draw = manager->create_task(DrawSpan);
333
334 task_draw->set_param(0,
335 (memaddr)&pixels[(startx-1) + this->width*(starty-1)]);
336 task_draw->set_param(1,this->width);
337 task_draw->set_param(2,startx);
338 task_draw->set_param(3,endx);
339 task_draw->set_param(4,rangey);
340
341 task_draw->add_inData(spack, sizeof(SpanPack));
342
343 for (int i = 0; i < rangey; i++) {
344 task_draw->add_outData(
345 &pixels[(startx-1) + this->width*(starty-1 + i) ],
346 (endx-startx+1)*sizeof(int));
347 }
348 } else {
349 // 7.7.3 SL1 Data Cache Range Set to Zero コマンド
350 // を使って、DMAでclearするべき... ということは、
351 // それもSPEでやる方が良い?
352 memset(&pixels[(startx-1)+this->width*(starty-1)],
353 0, (this->width)*sizeof(int)*rangey);
354 break;
355 }
356
357 task_draw->set_cpu(SPE_ANY);
358 task_next->wait_for(task_draw);
359 task_draw->wait_for(data_update_wait);
360 task_draw->spawn();
361
362 startx += split_screen_w;
363 endx += split_screen_w;
364
365 if (endx > this->width) {
366 endx = this->width;
367 }
368 }
369 }
370 }
153 371
154 void 372 void
155 SgChange::run_finish(void) 373 SgChange::run_finish(void)
156 { 374 {
157 if (this_time != start_time) { 375 if (this_time != start_time) {
158 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); 376 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0);
159 } 377 }
160 378
161 delete sgroot_A; 379 delete sgroot_A;
162 delete sgroot_B; 380 //delete sgroot_B;
163 quit(); 381 quit();
164 } 382 }
165 383
166 /* end */ 384 /* end */