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