annotate TaskManager/Test/test_render/chain.cpp @ 395:208ba3551474 draft

chain on SPE
author game@localhost.localdomain
date Thu, 17 Sep 2009 16:55:18 +0900
parents 3d1e86396d16
children 0b623693e6ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
2 #include <math.h>
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
3 #include "SceneGraphRoot.h"
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
4 #include "SceneGraph.h"
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
5 #include "SGList.h"
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
6 #include "TaskManager.h"
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
7 #include "Func.h"
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
8
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 #define FALSE 0
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 #define TRUE !FALSE
382
1c3f84a6f5d0 chain.cpp update
kazz@kazzone.cr.ie.u-ryukyu.ac.jp
parents: 378
diff changeset
11 #define CHAIN_LEN 50
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
12
382
1c3f84a6f5d0 chain.cpp update
kazz@kazzone.cr.ie.u-ryukyu.ac.jp
parents: 378
diff changeset
13 static double chain_width = 10;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
14
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
15 typedef struct {
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 double x, y, next_x, next_y;
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
17 double vx, vy, next_vx, next_vy;
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
18 double angle[3];
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
19 int can_move;
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
20 SceneGraphPtr parent;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
21 int id;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
22 //int parent;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
23 } CHAIN_VARS;
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
24
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
25 /* SceneGraph の property */
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
26 CHAIN_VARS* property;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
27
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
28 CHAIN_VARS cv[CHAIN_LEN];
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
29
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
30 void createSceneGraphFromProperty(CHAIN_VARS* p) ;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
31
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
32 void
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
33 init_chain_vars(CHAIN_VARS *cv) {
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0;
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
35 cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0;
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 cv->can_move = TRUE;
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 }
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
38
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 void
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
40 set_vector(CHAIN_VARS *p, SceneGraphPtr sg) {
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
41 sg->xyz[0] = p->next_x;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
42 sg->xyz[1] = p->next_y;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
43 sg->xyz[2] = 0.0f;
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
44 sg->angle[0] = p->angle[0];
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
45 sg->angle[1] = p->angle[1];
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
46 sg->angle[2] = p->angle[2];
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 }
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
48
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
49
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
50 static void
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 chain_move_ope(SceneGraphPtr node, int screen_w, int screen_h)
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 {
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 Pad *pad = sgroot->getController();
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
54
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 if (pad->circle.isHold()) {
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
56 property[CHAIN_LEN-1].can_move = FALSE;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 if (pad->left.isHold()) {
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
58 property[CHAIN_LEN-1].x += -5.0;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 } else if (pad->right.isHold()) {
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
60 property[CHAIN_LEN-1].x += 5.0;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 }
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
62
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 if (pad->up.isHold()) {
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
64 property[CHAIN_LEN-1].y += -5.0;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 } else if (pad->down.isHold()) {
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
66 property[CHAIN_LEN-1].y += 5.0;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
67 }
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
68 } else {
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
69 property[CHAIN_LEN-1].can_move = TRUE;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
70 }
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
71 }
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
72
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
73 void
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
74 chain_move(SceneGraphPtr sg, int w, int h)
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
75 {
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
76 int id = sg->id;
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
77 CHAIN_VARS* p = (CHAIN_VARS*)sg->propertyptr;
382
1c3f84a6f5d0 chain.cpp update
kazz@kazzone.cr.ie.u-ryukyu.ac.jp
parents: 378
diff changeset
78 if(id == 0) {
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
79 HTaskPtr chain_cal;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
80 chain_cal = manager->create_task(CHAINCAL_TASK);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
81 chain_cal->add_inData(&property[CHAIN_LEN-1], sizeof(CHAIN_VARS));
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
82 chain_cal->add_param(id);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
83 chain_cal->add_outData(property, sizeof(CHAIN_VARS)*CHAIN_LEN);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
84 chain_cal->spawn();
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
85 createSceneGraphFromProperty(p);
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
86 }
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
87
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
88 }
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
89
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
90 void
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
91 chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg)
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
92 {
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
93
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
94 }
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
95
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
96 void
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
97 createSceneGraphFromProperty(CHAIN_VARS* p)
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
98 {
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
99 SceneGraphPtr chain_copy;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
100 chain_copy = sgroot->createSceneGraph(CHAIN);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
101 chain_copy->propertyptr = (void*)p;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
102 set_vector(p, chain_copy);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
103 p->parent->addChild(chain_copy);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
104 }
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
105
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
106 void
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
107 chain_init(int w, int h)
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
108 {
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
109 SceneGraphPtr root_chain, chain;
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
110 CHAIN_VARS rcv;
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
111
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
112 HTaskPtr chain_init;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
113
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
114 sgroot->createFromXMLfile("xml_file/chain.xml");
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
115
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
116 /* SPE に送る property の配列の領域確保 */
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
117 property = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*CHAIN_LEN);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
118
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
119 root_chain = sgroot->createSceneGraph(CHAIN);
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
120 root_chain->set_move_collision(chain_move_ope, chain_collision);
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
121 init_chain_vars(&rcv);
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
122 rcv.next_x = w / 2;
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
123 rcv.next_y = 0.0;
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
124 rcv.angle[0] = 0;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
125 rcv.angle[1] = 0;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
126 rcv.angle[2] = 0;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
127
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
128 set_vector(&rcv, root_chain);
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
129
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
130 for(int i = 0; i < CHAIN_LEN; i++) {
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
131 chain = sgroot->createSceneGraph(CHAIN);
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
132 property[i].id = i;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
133 init_chain_vars(&property[i]);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
134 property[i].x = 0;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
135 property[i].y = chain_width * i;
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
136 set_vector(&property[i], chain);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
137 property->angle[1] = -90 * (i % 2);
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
138 chain->set_move_collision(chain_move, chain_collision);
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
139
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
140 root_chain->addChild(chain);
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
141 property[i].parent = root_chain;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
142 }
382
1c3f84a6f5d0 chain.cpp update
kazz@kazzone.cr.ie.u-ryukyu.ac.jp
parents: 378
diff changeset
143 cv[0].can_move = FALSE;
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
144
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
145 // property を SPU の共有領域へコピーする
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
146 chain_init = manager->create_task(CHAININIT_TASK);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
147 chain_init->add_inData(property, sizeof(CHAIN_VARS)*CHAIN_LEN);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
148 chain_init->add_param(CHAIN_LEN);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
149 chain_init->set_cpu(SPE_0);
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
150
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
151
375
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
152 sgroot->setSceneData(root_chain);
2ae25549dd6a chain.cpp added
kazz@kazzone.ie.u-ryukyu.ac.jp
parents:
diff changeset
153 }
395
208ba3551474 chain on SPE
game@localhost.localdomain
parents: 388
diff changeset
154