Mercurial > hg > Game > Cerium
annotate TaskManager/Test/test_render/Application/chain.cc @ 447:9b06420a940c draft
fix...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 25 Sep 2009 07:40:09 +0900 |
parents | efe8584a7b5a |
children | 0bed2a9889f5 |
rev | line source |
---|---|
388
3d1e86396d16
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
382
diff
changeset
|
1 #include <iostream> |
375 | 2 #include <math.h> |
3 #include "SceneGraphRoot.h" | |
395 | 4 #include "SceneGraph.h" |
375 | 5 #include "SGList.h" |
395 | 6 #include "TaskManager.h" |
7 #include "Func.h" | |
445 | 8 #include "Chain.h" |
375 | 9 |
445 | 10 using namespace std; |
375 | 11 #define FALSE 0 |
12 #define TRUE !FALSE | |
382 | 13 #define CHAIN_LEN 50 |
375 | 14 |
382 | 15 static double chain_width = 10; |
445 | 16 static void createSceneGraphFromProperty(void* p); |
375 | 17 |
395 | 18 /* SceneGraph の property */ |
445 | 19 ChainPropertyPtr properties[2]; |
20 ChainPropertyPtr property; | |
431 | 21 |
395 | 22 |
445 | 23 SceneGraphPtr scenegraph_factory(void *p, int size){ |
24 return 0; | |
25 } | |
447 | 26 |
445 | 27 SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list){ |
28 return 0; | |
29 } | |
375 | 30 |
447 | 31 int |
32 Chain::move_task_id(){ | |
33 return move_task_id_; | |
445 | 34 } |
35 | |
36 | |
37 //void createSceneGraphFromProperty(ChainPropertyPtr* p) ; | |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
38 void createSceneGraphFromProperty(void* p) ; |
395 | 39 |
375 | 40 void |
445 | 41 Chain::init_chain_vars(ChainPropertyPtr cv) { |
375 | 42 cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; |
43 cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0; | |
44 cv->can_move = TRUE; | |
45 } | |
46 | |
47 void | |
445 | 48 set_vector(ChainPropertyPtr p, SceneGraphPtr sg) { |
395 | 49 sg->xyz[0] = p->next_x; |
50 sg->xyz[1] = p->next_y; | |
375 | 51 sg->xyz[2] = 0.0f; |
395 | 52 sg->angle[0] = p->angle[0]; |
53 sg->angle[1] = p->angle[1]; | |
54 sg->angle[2] = p->angle[2]; | |
375 | 55 } |
56 | |
431 | 57 /* |
375 | 58 static void |
59 chain_move_ope(SceneGraphPtr node, int screen_w, int screen_h) | |
60 { | |
61 Pad *pad = sgroot->getController(); | |
62 | |
63 if (pad->circle.isHold()) { | |
395 | 64 property[CHAIN_LEN-1].can_move = FALSE; |
375 | 65 if (pad->left.isHold()) { |
395 | 66 property[CHAIN_LEN-1].x += -5.0; |
375 | 67 } else if (pad->right.isHold()) { |
395 | 68 property[CHAIN_LEN-1].x += 5.0; |
375 | 69 } |
70 | |
71 if (pad->up.isHold()) { | |
395 | 72 property[CHAIN_LEN-1].y += -5.0; |
375 | 73 } else if (pad->down.isHold()) { |
395 | 74 property[CHAIN_LEN-1].y += 5.0; |
375 | 75 } |
76 } else { | |
395 | 77 property[CHAIN_LEN-1].can_move = TRUE; |
375 | 78 } |
79 } | |
431 | 80 */ |
375 | 81 |
82 void | |
431 | 83 Chain::chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h) |
375 | 84 { |
85 int id = sg->id; | |
431 | 86 //PropertyPtr p = (PropertyPtr)sg->propertyptr; |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
87 HTaskPtr chain_cal; |
445 | 88 ChainPropertyPtr output; |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
89 |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
90 // SceneGraph の切り替えもここでやる |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
91 if (property == properties[0]) { |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
92 property = properties[1]; |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
93 output = properties[0]; |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
94 }else{ |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
95 property = properties[0]; |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
96 output = properties[1]; |
375 | 97 } |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
98 chain_cal = manager->create_task(CHAINCAL_TASK); |
445 | 99 chain_cal->add_inData(property, sizeof(ChainPropertyPtr)*CHAIN_LEN); |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
100 chain_cal->add_param(id); |
445 | 101 chain_cal->add_outData(output, sizeof(ChainPropertyPtr)*CHAIN_LEN); |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
102 chain_cal->set_post(createSceneGraphFromProperty, (void*)id); |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
103 chain_cal->spawn(); |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
104 |
375 | 105 } |
106 | |
107 void | |
431 | 108 Chain::chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) |
375 | 109 { |
110 } | |
111 | |
395 | 112 void |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
113 createSceneGraphFromProperty(void* p) |
395 | 114 { |
445 | 115 ChainPropertyPtr chain_p = (ChainPropertyPtr)p; |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
116 SceneGraphPtr chain_copy = sgroot->createSceneGraph(CHAIN); |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
117 chain_copy->propertyptr = (void*)chain_p; |
445 | 118 chain_copy->property_size = sizeof(ChainPropertyPtr); |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
119 set_vector(chain_p, chain_copy); |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
120 chain_p->parent->addChild(chain_copy); |
395 | 121 } |
122 | |
375 | 123 void |
435 | 124 Chain::init(TaskManager *manager, int w, int h) |
375 | 125 { |
126 SceneGraphPtr root_chain, chain; | |
445 | 127 ChainProperty r; |
128 ChainPropertyPtr rcv = &r; | |
375 | 129 |
395 | 130 HTaskPtr chain_init; |
131 | |
445 | 132 move_task_id_ = CHAINCAL_TASK; |
397
ce86b0186a4a
delete manager (in kernel/ppe/TaskManager.h)
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
396
diff
changeset
|
133 sgroot->createFromXMLfile(manager, "xml_file/chain.xml"); |
375 | 134 |
395 | 135 /* SPE に送る property の配列の領域確保 */ |
445 | 136 properties[0] = (ChainPropertyPtr)manager->allocate(sizeof(ChainPropertyPtr)*CHAIN_LEN); |
137 properties[1] = (ChainPropertyPtr)manager->allocate(sizeof(ChainPropertyPtr)*CHAIN_LEN); | |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
138 property = properties[0]; |
395 | 139 |
375 | 140 root_chain = sgroot->createSceneGraph(CHAIN); |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
141 // set_move_collision()ではだめ |
445 | 142 //root_chain->set_move_collision(chain_move_ope, chain_collision); |
143 init_chain_vars(rcv); | |
144 rcv->next_x = w / 2; | |
145 rcv->next_y = 0.0; | |
146 rcv->angle[0] = 0; | |
147 rcv->angle[1] = 0; | |
148 rcv->angle[2] = 0; | |
395 | 149 |
445 | 150 set_vector(rcv, root_chain); |
375 | 151 |
152 for(int i = 0; i < CHAIN_LEN; i++) { | |
153 chain = sgroot->createSceneGraph(CHAIN); | |
395 | 154 property[i].id = i; |
155 init_chain_vars(&property[i]); | |
156 property[i].x = 0; | |
157 property[i].y = chain_width * i; | |
158 set_vector(&property[i], chain); | |
159 property->angle[1] = -90 * (i % 2); | |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
160 //chain->set_move_collision(chain_move, chain_collision); |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
161 chain->propertyptr = &property[i]; |
445 | 162 chain->property_size = sizeof(ChainPropertyPtr); |
375 | 163 root_chain->addChild(chain); |
395 | 164 property[i].parent = root_chain; |
375 | 165 } |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
166 property[0].can_move = FALSE; |
375 | 167 |
395 | 168 // property を SPU の共有領域へコピーする |
169 chain_init = manager->create_task(CHAININIT_TASK); | |
445 | 170 chain_init->add_inData(property, sizeof(ChainPropertyPtr)*CHAIN_LEN); |
395 | 171 chain_init->add_param(CHAIN_LEN); |
172 chain_init->set_cpu(SPE_0); | |
396
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
173 chain_init->set_post(createSceneGraphFromProperty, (void*)property); |
0b623693e6ec
don't move. separate allExecute from run_loop
game@henri.cr.ie.u-ryukyu.ac.jp
parents:
395
diff
changeset
|
174 chain_init->spawn(); |
395 | 175 |
375 | 176 sgroot->setSceneData(root_chain); |
177 } | |
395 | 178 |