Mercurial > hg > Game > Cerium
comparison Renderer/Engine/SceneGraphRoot.cc @ 1003:37842bbd35f0 draft
game_task keep up with task_array.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Oct 2010 17:29:50 +0900 |
parents | ceca625af064 |
children | 66f1d3d328a7 |
comparison
equal
deleted
inserted
replaced
1002:ceca625af064 | 1003:37842bbd35f0 |
---|---|
42 screen_h = (int)h; | 42 screen_h = (int)h; |
43 int light_num = 4; | 43 int light_num = 4; |
44 light_sysswitch = 0; | 44 light_sysswitch = 0; |
45 | 45 |
46 for (int i = 0; i < light_num; i++) { | 46 for (int i = 0; i < light_num; i++) { |
47 light[i] = new SceneGraph; | 47 light[i] = new SceneGraph; |
48 light[i]->xyz[0] = 0; | 48 light[i]->xyz[0] = 0; |
49 light[i]->xyz[1] = 0; | 49 light[i]->xyz[1] = 0; |
50 light[i]->xyz[2] = 0; | 50 light[i]->xyz[2] = 0; |
51 | 51 |
52 light_switch[i] = 0; | 52 light_switch[i] = 0; |
53 | 53 |
54 } | 54 } |
55 | 55 |
56 move_finish_flag = 0; | 56 move_finish_flag = 0; |
57 | |
58 gtask_array = NULL; | |
57 | 59 |
58 // TODO | 60 // TODO |
59 // 今はとりあえず camera を Root にしています | 61 // 今はとりあえず camera を Root にしています |
60 // 今はそれすらもしてません | 62 // 今はそれすらもしてません |
61 //sg_exec_tree = camera; | 63 //sg_exec_tree = camera; |
64 SceneGraphRoot::~SceneGraphRoot() | 66 SceneGraphRoot::~SceneGraphRoot() |
65 { | 67 { |
66 SceneGraphPtr p = sg_available_list; | 68 SceneGraphPtr p = sg_available_list; |
67 | 69 |
68 while (p) { | 70 while (p) { |
69 SceneGraphPtr tmp = p->next; | 71 SceneGraphPtr tmp = p->next; |
70 delete p; | 72 delete p; |
71 p = tmp; | 73 p = tmp; |
72 cnt--; | 74 cnt--; |
73 } | 75 } |
74 | 76 |
75 p = sg_remove_list; | 77 p = sg_remove_list; |
76 | 78 |
77 while (p) { | 79 while (p) { |
78 SceneGraphPtr tmp = p->next; | 80 SceneGraphPtr tmp = p->next; |
79 delete p; | 81 delete p; |
80 p = tmp; | 82 p = tmp; |
81 cnt--; | 83 cnt--; |
82 } | 84 } |
83 | 85 |
84 free(sg_src); | 86 free(sg_src); |
85 delete camera; | 87 delete camera; |
86 int light_num = 4; | 88 int light_num = 4; |
87 for (int i = 0; i < light_num; i++) { | 89 for (int i = 0; i < light_num; i++) { |
88 delete light[i]; | 90 delete light[i]; |
89 } | 91 } |
90 delete iterator; | 92 delete iterator; |
91 delete controller; | 93 delete controller; |
94 | |
95 if (gtask_array != NULL) { | |
96 delete gtask_array; | |
97 } | |
92 } | 98 } |
93 | 99 |
94 /** | 100 /** |
95 * xml ファイルから生成された SceneGraph を sg_src に登録する。 | 101 * xml ファイルから生成された SceneGraph を sg_src に登録する。 |
96 * | 102 * |
117 SceneGraphRoot::addNext(SceneGraphPtr sg) | 123 SceneGraphRoot::addNext(SceneGraphPtr sg) |
118 { | 124 { |
119 SceneGraphPtr last = sg_available_list; | 125 SceneGraphPtr last = sg_available_list; |
120 | 126 |
121 if (!last) { | 127 if (!last) { |
122 sg_available_list = sg; | 128 sg_available_list = sg; |
123 } else { | 129 } else { |
124 while (last->next) { | 130 while (last->next) { |
125 last = last->next; | 131 last = last->next; |
126 } | 132 } |
127 last->next = sg; | 133 last->next = sg; |
128 sg->prev = last; | 134 sg->prev = last; |
129 } | 135 } |
130 | 136 |
131 cnt++; | 137 cnt++; |
132 } | 138 } |
133 | 139 |
175 /* ?? */ | 181 /* ?? */ |
176 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D"); | 182 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D"); |
177 | 183 |
178 /* XMLのノードを一つずつ解析 */ | 184 /* XMLのノードを一つずつ解析 */ |
179 for (cur=cur->children; cur; cur=cur->next) { | 185 for (cur=cur->children; cur; cur=cur->next) { |
180 /* 扱うのはsurfaceオンリー */ | 186 /* 扱うのはsurfaceオンリー */ |
181 if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) { | 187 if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) { |
182 continue; | 188 continue; |
183 } | 189 } |
184 /* ポリゴン(SceneGraph)生成 */ | 190 /* ポリゴン(SceneGraph)生成 */ |
185 SceneGraphPtr original = new SceneGraph(manager, cur); | 191 SceneGraphPtr original = new SceneGraph(manager, cur); |
186 registSceneGraph(original); | 192 registSceneGraph(original); |
187 SceneGraphPtr clone = createSceneGraph(original->sgid); | 193 SceneGraphPtr clone = createSceneGraph(original->sgid); |
188 node->addChild(clone); | 194 node->addChild(clone); |
189 } | 195 } |
190 xmlFreeDoc(doc); | 196 xmlFreeDoc(doc); |
191 } | 197 } |
192 | 198 |
193 SceneGraphPtr | 199 SceneGraphPtr |
195 { | 201 { |
196 SceneGraphPtr src; | 202 SceneGraphPtr src; |
197 SceneGraphPtr p; | 203 SceneGraphPtr p; |
198 | 204 |
199 if (id < 0 || id > sg_src_size) { | 205 if (id < 0 || id > sg_src_size) { |
200 printf("error: createSceneGraph(int id): id not found.\n"); | 206 printf("error: createSceneGraph(int id): id not found.\n"); |
201 return NULL; | 207 return NULL; |
202 } | 208 } |
203 | 209 |
204 /* オリジナルの SceneGraph */ | 210 /* オリジナルの SceneGraph */ |
205 src = sg_src[id]; | 211 src = sg_src[id]; |
206 | 212 |
224 SceneGraphPtr src; | 230 SceneGraphPtr src; |
225 SceneGraphPtr p; | 231 SceneGraphPtr p; |
226 | 232 |
227 int id = getSgid(name); | 233 int id = getSgid(name); |
228 if (id < 0) { | 234 if (id < 0) { |
229 printf("error: createSceneGraph(name): name object not found.\n"); | 235 printf("error: createSceneGraph(name): name object not found.\n"); |
230 return NULL; | 236 return NULL; |
231 } | 237 } |
232 | 238 |
233 /* オリジナルの SceneGraph */ | 239 /* オリジナルの SceneGraph */ |
234 src = sg_src[id]; | 240 src = sg_src[id]; |
235 | 241 |
311 | 317 |
312 list->frame++; | 318 list->frame++; |
313 list = list->next; | 319 list = list->next; |
314 | 320 |
315 if(sg_exec_tree != NULL) { | 321 if(sg_exec_tree != NULL) { |
316 return; | 322 return; |
317 } | 323 } |
318 | 324 |
319 /*removeのflagをもとにtreeを形成*/ | 325 /*removeのflagをもとにtreeを形成*/ |
320 /* spe から送り返されてきた property の配列を見て生成する for()*/ | 326 /* spe から送り返されてきた property の配列を見て生成する for()*/ |
321 /* | 327 /* |
322 for (Property *t = (Property*)app->property[0]; is_end(t); t++){ | 328 for (Property *t = (Property*)app->property[0]; is_end(t); t++){ |
323 SceneGraphPtr s = app->scenegraph_factory(t); // SceneGraphNode を作る | 329 SceneGraphPtr s = app->scenegraph_factory(t); // SceneGraphNode を作る |
324 t->scenegraph = s; // property list には SceneGraphへのポインタが入っている | 330 t->scenegraph = s; // property list には SceneGraphへのポインタが入っている |
325 app->scenegraph_connector(property[0], s); // add する | 331 app->scenegraph_connector(property[0], s); // add する |
326 } | 332 } |
327 */ | 333 */ |
328 | 334 |
329 | 335 |
330 // 現在、allExecute が終わった時点では | 336 // 現在、allExecute が終わった時点では |
331 // camera->children が User SceneGraph の root になる | 337 // camera->children が User SceneGraph の root になる |
376 } | 382 } |
377 | 383 |
378 int light_num = 4; | 384 int light_num = 4; |
379 for (int i = 0; i < light_num; i++) { | 385 for (int i = 0; i < light_num; i++) { |
380 | 386 |
381 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); | 387 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
382 | 388 |
383 light_vector[i*4] = 0.0f; | 389 light_vector[i*4] = 0.0f; |
384 light_vector[i*4+1] = 0.0f; | 390 light_vector[i*4+1] = 0.0f; |
385 light_vector[i*4+2] = 0.0f; | 391 light_vector[i*4+2] = 0.0f; |
386 light_vector[i*4+3] = 1.0f; | 392 light_vector[i*4+3] = 1.0f; |
387 | 393 |
388 ApplyMatrix(&light_vector[i*4], light[i]->matrix); | 394 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
389 | 395 |
390 light_vector[i*4] /= light_vector[i*4+2]; | 396 light_vector[i*4] /= light_vector[i*4+2]; |
391 light_vector[i*4+1] /= light_vector[i*4+2]; | 397 light_vector[i*4+1] /= light_vector[i*4+2]; |
392 | 398 |
393 /*SIMD演算のため*/ | 399 /*SIMD演算のため*/ |
394 light_vector[i*4+2] *= -1; | 400 light_vector[i*4+2] *= -1; |
395 light_vector[i*4+3] *= -1; | 401 light_vector[i*4+3] *= -1; |
396 | 402 |
397 } | 403 } |
398 | 404 |
399 | 405 |
400 if(sg_exec_tree != NULL) { | 406 if(sg_exec_tree != NULL) { |
496 | 502 |
497 | 503 |
498 int light_num = 4; | 504 int light_num = 4; |
499 for (int i = 0; i < light_num; i++) { | 505 for (int i = 0; i < light_num; i++) { |
500 | 506 |
501 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); | 507 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
502 | 508 |
503 light_vector[i*4] = 0.0f; | 509 light_vector[i*4] = 0.0f; |
504 light_vector[i*4+1] = 0.0f; | 510 light_vector[i*4+1] = 0.0f; |
505 light_vector[i*4+2] = 0.0f; | 511 light_vector[i*4+2] = 0.0f; |
506 light_vector[i*4+3] = 1.0f; | 512 light_vector[i*4+3] = 1.0f; |
507 | 513 |
508 ApplyMatrix(&light_vector[i*4], light[i]->matrix); | 514 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
509 | 515 |
510 light_vector[i*4] /= light_vector[i*4+2]; | 516 light_vector[i*4] /= light_vector[i*4+2]; |
511 light_vector[i*4+1] /= light_vector[i*4+2]; | 517 light_vector[i*4+1] /= light_vector[i*4+2]; |
512 | 518 |
513 } | 519 } |
514 | 520 |
515 if(sg_exec_tree != NULL) { | 521 if(sg_exec_tree != NULL) { |
516 return; | 522 return; |
517 } | 523 } |
518 } | 524 } |
519 | 525 |
520 /* | 526 /* |
521 ExecMove task の post func として呼んでやる | 527 ExecMove task の post func として呼んでやる |
522 */ | 528 */ |
523 void | 529 void |
524 SceneGraphRoot::move_finish() | 530 SceneGraphRoot::move_finish() |
525 { | 531 { |
526 list->collision_check(screen_w, screen_h, list); | 532 list->collision_check(screen_w, screen_h, list); |
527 | 533 |
529 //list = list->next; | 535 //list = list->next; |
530 | 536 |
531 int light_num = 4; | 537 int light_num = 4; |
532 for (int i = 0; i < light_num; i++) { | 538 for (int i = 0; i < light_num; i++) { |
533 | 539 |
534 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); | 540 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
535 | 541 |
536 light_vector[i*4] = 0.0f; | 542 light_vector[i*4] = 0.0f; |
537 light_vector[i*4+1] = 0.0f; | 543 light_vector[i*4+1] = 0.0f; |
538 light_vector[i*4+2] = 0.0f; | 544 light_vector[i*4+2] = 0.0f; |
539 light_vector[i*4+3] = 1.0f; | 545 light_vector[i*4+3] = 1.0f; |
540 | 546 |
541 ApplyMatrix(&light_vector[i*4], light[i]->matrix); | 547 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
542 | 548 |
543 light_vector[i*4] /= light_vector[i*4+2]; | 549 light_vector[i*4] /= light_vector[i*4+2]; |
544 light_vector[i*4+1] /= light_vector[i*4+2]; | 550 light_vector[i*4+1] /= light_vector[i*4+2]; |
545 | 551 |
546 light_vector[i*4+2] *= -1; | 552 light_vector[i*4+2] *= -1; |
547 light_vector[i*4+3] *= -1; | 553 light_vector[i*4+3] *= -1; |
548 } | 554 } |
549 | 555 |
550 //sgchange->viewer->light_xyz_stock = getLightVector(); | 556 //sgchange->viewer->light_xyz_stock = getLightVector(); |
551 } | 557 } |
552 | 558 |
646 | 652 |
647 SceneGraphPtr | 653 SceneGraphPtr |
648 SceneGraphRoot::getLight(int id) | 654 SceneGraphRoot::getLight(int id) |
649 { | 655 { |
650 | 656 |
651 return light[id]; | 657 return light[id]; |
652 | 658 |
653 } | 659 } |
654 | 660 |
655 | 661 |
656 float* | 662 float* |
657 SceneGraphRoot::getLightVector() | 663 SceneGraphRoot::getLightVector() |
658 { | 664 { |
659 return light_vector; | 665 return light_vector; |
660 } | 666 } |
661 | 667 |
662 int* | 668 int* |
663 SceneGraphRoot::getLightSwitch() | 669 SceneGraphRoot::getLightSwitch() |
664 { | 670 { |
665 return light_switch; | 671 return light_switch; |
666 } | 672 } |
667 | 673 |
668 int | 674 int |
669 SceneGraphRoot::getLightSysSwitch() | 675 SceneGraphRoot::getLightSysSwitch() |
670 { | 676 { |
671 return light_sysswitch; | 677 return light_sysswitch; |
672 } | 678 } |
673 | 679 |
674 void | 680 void |
675 SceneGraphRoot::OnLightSwitch(int id) | 681 SceneGraphRoot::OnLightSwitch(int id) |
676 { | 682 { |
677 light_switch[id] = 1; | 683 light_switch[id] = 1; |
678 } | 684 } |
679 | 685 |
680 void | 686 void |
681 SceneGraphRoot::OffLightSwitch(int id) | 687 SceneGraphRoot::OffLightSwitch(int id) |
682 { | 688 { |
683 light_switch[id] = 0; | 689 light_switch[id] = 0; |
684 } | 690 } |
685 | 691 |
686 void | 692 void |
687 SceneGraphRoot::OnLightSysSwitch() | 693 SceneGraphRoot::OnLightSysSwitch() |
688 { | 694 { |
689 | 695 |
690 light_sysswitch = 1; | 696 light_sysswitch = 1; |
691 | 697 |
692 } | 698 } |
693 | 699 |
694 void | 700 void |
695 SceneGraphRoot::OffLightSysSwitch() | 701 SceneGraphRoot::OffLightSysSwitch() |
696 { | 702 { |
697 | 703 |
698 light_sysswitch = 0; | 704 light_sysswitch = 0; |
699 | 705 |
700 } | 706 } |
701 | 707 |
708 void | |
709 SceneGraphRoot::task_array_init(int id, int task_num, int param, int inData_num, int outData_num) | |
710 { | |
711 gtask_array = new GTaskArray; | |
712 gtask_array->init(id, task_num, param, inData_num, outData_num); | |
713 } | |
714 | |
715 void | |
716 SceneGraphRoot::create_task_array() | |
717 { | |
718 gtask_array->create_task_array(this->tmanager); | |
719 } | |
720 | |
721 void | |
722 SceneGraphRoot::task_array_finish() | |
723 { | |
724 gtask_array->finish(); | |
725 } | |
702 | 726 |
703 void | 727 void |
704 SceneGraphRoot::set_game_task(int id, void *property, int size, PostFunction post_func) | 728 SceneGraphRoot::set_game_task(int id, void *property, int size, PostFunction post_func) |
705 { | 729 { |
706 game_task = game_task_array->next_task_array(id, game_task); | 730 gtask_array->next_task_array(id); |
707 | 731 |
708 game_task->set_inData(0, property, size); | 732 gtask_array->game_task->set_inData(0, property, size); |
709 game_task->set_outData(0, property, size); | 733 gtask_array->game_task->set_outData(0, property, size); |
710 | 734 |
711 /* | |
712 HTask *task = sgroot->tmanager->create_task(id); | |
713 task->set_cpu(SPE_ANY); | |
714 task->set_inData(0, property, size); | |
715 task->set_outData(0, property, size); | |
716 task->set_post(post_func, (void*)property, 0); | |
717 wait_game_task->wait_for(task); | |
718 task->spawn(); | |
719 */ | |
720 } | 735 } |
721 | 736 |
722 void | 737 void |
723 SceneGraphRoot::set_game_task(int id, void *property, void *pad, int size, PostFunction post_func) | 738 SceneGraphRoot::set_game_task(int id, void *property, void *pad, int size, PostFunction post_func) |
724 { | 739 { |
725 game_task = game_task_array->next_task_array(id, game_task); | 740 gtask_array->next_task_array(id); |
726 | 741 |
727 game_task->set_inData(0, property, size); | 742 gtask_array->game_task->set_inData(0, property, size); |
728 game_task->set_inData(1, pad, sizeof(Pad)); | 743 gtask_array->game_task->set_inData(1, pad, sizeof(Pad)); |
729 game_task->set_outData(0, property, size); | 744 gtask_array->game_task->set_outData(0, property, size); |
730 | 745 |
731 /* | |
732 HTask *task = sgroot->tmanager->create_task(id); | |
733 task->set_cpu(SPE_ANY); | |
734 task->set_inData(0, property, size); | |
735 task->set_inData(0, pad, sizeof(Pad)); | |
736 task->set_outData(0, property, size); | |
737 task->set_post(post_func, (void*)property, 0); | |
738 wait_game_task->wait_for(task); | |
739 task->spawn(); | |
740 */ | |
741 } | |
742 | |
743 void | |
744 SceneGraphRoot::task_array_init(int id, int task_num, int param, int inData_num, int outData_num) | |
745 { | |
746 game_task_array = tmanager->create_task_array(id, task_num, param, inData_num, outData_num); | |
747 game_task = 0; | |
748 } | |
749 | |
750 void | |
751 SceneGraphRoot::task_array_finish() | |
752 { | |
753 game_task_array->spawn_task_array(game_task->next()); | |
754 game_task_array->set_cpu(SPE_ANY); | |
755 game_task_array->spawn(); | |
756 } | 746 } |
757 | 747 |
758 void | 748 void |
759 main_task_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | 749 main_task_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
760 { | 750 { |
761 int size = node->property_size; | 751 int size = node->property_size; |
762 void *e = node->propertyptr; | 752 void *e = node->propertyptr; |
763 int move = node->move_id; | 753 int move = node->move_id; |
764 PostFunction post_func = node->post_func; | 754 PostFunction post_func = node->post_func; |
765 ObjPropertyPtr property = (ObjPropertyPtr)node->propertyptr; | 755 ObjPropertyPtr property = (ObjPropertyPtr)node->propertyptr; |
766 property->root = node; | 756 property->root = node; |
767 | 757 |
768 SceneGraphRoot *sgroottmp = (SceneGraphRoot*)sgroot_; | 758 SceneGraphRoot *sgroottmp = (SceneGraphRoot*)sgroot_; |
769 | 759 |
770 sgroottmp->set_game_task(move, (void*)e, size, post_func); | 760 sgroottmp->set_game_task(move, (void*)e, size, post_func); |
771 } | 761 } |
772 | 762 |
773 void | 763 void |
774 pad_task_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | 764 pad_task_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
775 { | 765 { |
776 int size = node->property_size; | 766 int size = node->property_size; |
777 void *e = node->propertyptr; | 767 void *e = node->propertyptr; |
778 int move = node->move_id; | 768 int move = node->move_id; |
779 PostFunction post_func = node->post_func; | 769 PostFunction post_func = node->post_func; |
780 ObjPropertyPtr property = (ObjPropertyPtr)node->propertyptr; | 770 ObjPropertyPtr property = (ObjPropertyPtr)node->propertyptr; |
781 property->root = node; | 771 property->root = node; |
782 | 772 |
783 SceneGraphRoot *sgroottmp = (SceneGraphRoot*)sgroot_; | 773 SceneGraphRoot *sgroottmp = (SceneGraphRoot*)sgroot_; |
784 void *pad = (void*)sgroottmp->getController(); | 774 void *pad = (void*)sgroottmp->getController(); |
785 | 775 |
786 sgroottmp->set_game_task(move, (void*)e, pad, size, post_func); | 776 sgroottmp->set_game_task(move, (void*)e, pad, size, post_func); |
787 } | 777 } |
788 | 778 |
789 void | 779 void |
790 SceneGraphRoot::set_move_task(SceneGraphPtr node, int move, void *property, int size, | 780 SceneGraphRoot::set_move_task(SceneGraphPtr node, int move, void *property, int size, |
791 PostFunction post_func) | 781 PostFunction post_func) |
797 node->property_size = size; | 787 node->property_size = size; |
798 } | 788 } |
799 | 789 |
800 void | 790 void |
801 SceneGraphRoot::set_pad_task(SceneGraphPtr node, int move, void *property, int size, | 791 SceneGraphRoot::set_pad_task(SceneGraphPtr node, int move, void *property, int size, |
802 PostFunction post_func) | 792 PostFunction post_func) |
803 { | 793 { |
804 node->move = pad_task_move; | 794 node->move = pad_task_move; |
805 node->post_func = post_func; | 795 node->post_func = post_func; |
806 node->move_id = move; | 796 node->move_id = move; |
807 node->propertyptr = property; | 797 node->propertyptr = property; |