Mercurial > hg > Game > Cerium
comparison TaskManager/Test/simple_render/viewer.cpp @ 42:aa11038dbdc1
*** empty log message ***
author | gongo |
---|---|
date | Thu, 14 Feb 2008 18:27:37 +0900 |
parents | babf9a330418 |
children | 70a0ac46133e |
comparison
equal
deleted
inserted
replaced
41:68fb5bfee6b7 | 42:aa11038dbdc1 |
---|---|
314 pixels[i*width+yl] = 0xff; | 314 pixels[i*width+yl] = 0xff; |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 | 318 |
319 struct run_arg_t { | |
320 int start_time; | |
321 int this_time; | |
322 int frames; | |
323 SDL_Surface *bitmap; | |
324 SDL_PixelFormat *pf; | |
325 Uint32 background; | |
326 Polygon *p; | |
327 SceneGraphPack *sgp; | |
328 PolygonPack *pp; | |
329 }; | |
330 | |
331 #if 0 | |
332 void | |
333 Viewer::run_init() | |
334 { | |
335 struct run_arg_t *arg = new run_arg_t; | |
336 HTaskPtr task; | |
337 int fd; | |
338 | |
339 arg->start_time = get_ticks(); | |
340 arg->pf = screen->format; | |
341 arg->background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); | |
342 arg->p = new Polygon; | |
343 arg->p->set_data("cube.xml"); | |
344 arg->p->viewer = this; | |
345 arg->sgp = new SceneGraphPack; | |
346 create_sgp(arg->sgp, arg->p); | |
347 arg->pp = new PolygonPack; | |
348 | |
349 pixels = new Uint32[width*height]; | |
350 | |
351 graph_line(); | |
352 | |
353 arg->bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32, | |
354 width*4, redMask, greenMask, | |
355 blueMask, alphaMask); | |
356 | |
357 fd = manager->open("ViewerRunLoop"); | |
358 task = manager->create_task(fd, sizeof(struct run_arg_t), | |
359 (unsigned int)arg, 0, NULL); | |
360 manager->spawn_task(task_create_pp); | |
361 //manager->run(); | |
362 } | |
363 | |
364 void | |
365 Viewer::run_loop(struct run_arg_t *arg) | |
366 { | |
367 HTaskPtr task_update_sgp = NULL; | |
368 HTaskPtr task_create_pp = NULL; | |
369 HTaskPtr task_finish = NULL; | |
370 int fd_update_sgp; | |
371 int fd_create_pp; | |
372 int fd_finish; | |
373 | |
374 if (quit_check()) { | |
375 arg->this_time = get_ticks(); | |
376 fd_finish = manager->open("ViewerRunFinish"); | |
377 task_finish = manager->create(fd_finish, sizeof(struct run_arg_t), | |
378 (unsigned int)arg, 0, NULL); | |
379 manager->spawn_task(task_finish); | |
380 return; | |
381 } | |
382 | |
383 clean_pixels(); | |
384 | |
385 this->zRow_init(); | |
386 graph_line(); | |
387 | |
388 fd_update_sgp = manager->open("UpdateSGP"); | |
389 fd_create_pp = manager->open("CreatePP"); | |
390 task_update_sgp = | |
391 manager->create_task(fd_update_sgp, | |
392 sizeof(SceneGraphPack), | |
393 (unsigned int)arg->sgp, | |
394 (unsigned int)arg->sgp, | |
395 NULL); | |
396 task_create_pp = | |
397 manager->create_task(fd_create_pp, | |
398 sizeof(SceneGraphPack), | |
399 (unsigned int)arg->sgp, | |
400 (unsigned int)arg->pp, | |
401 NULL); | |
402 | |
403 manager->spawn_task(task_update_sgp); | |
404 manager->spawn_task(task_create_pp); | |
405 manager->run(); | |
406 | |
407 arg->p->draw(pp); // test draw of PolygonPack | |
408 | |
409 SDL_BlitSurface(arg->bitmap, NULL, screen, NULL); | |
410 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
411 | |
412 //swap_buffers(); | |
413 arg->frames++; | |
414 } | |
415 | |
416 void | |
417 Viewer::run_finish(struct run_arg_t *arg) | |
418 { | |
419 if (arg->this_time != arg->start_time) { | |
420 cout<< ((float)arg->frames/(this_time-start_time))*1000.0 << " FPS\n"; | |
421 } | |
422 | |
423 SDL_FreeSurface(arg->bitmap); | |
424 delete [] pixels; | |
425 arg->p->delete_data(); | |
426 delete arg->p; | |
427 delete arg->sgp; | |
428 delete arg->pp; | |
429 quit(); | |
430 | |
431 delete arg; | |
432 } | |
433 #endif | |
434 | |
319 void Viewer::run() | 435 void Viewer::run() |
320 { | 436 { |
321 int frames = 0; | 437 int frames = 0; |
322 int start_time, this_time; | 438 int start_time, this_time; |
323 | 439 |