Mercurial > hg > Game > Cerium
comparison example/scenegraph/xml/task/collision.cpp @ 351:10c1f6970f6a draft
add move,collision task
author | admin@mcbk.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 10 Jul 2009 18:20:26 +0900 |
parents | 628cb162be88 |
children |
comparison
equal
deleted
inserted
replaced
350:628cb162be88 | 351:10c1f6970f6a |
---|---|
1 /** | 1 /** |
2 * SceneGraph が増えてくると動かなくなるかもしれない。 | 2 * 前もって collision する対象を task の global に登録しておく task が必要 |
3 * 一応 mainMem とかで動くようになるとは思うけど。 | 3 * SceneGraph を読み込んで |
4 * だめだったら、そこら辺が怪しいと思うべき | 4 * 衝突判定を行う node を確保する |
5 * node の型に対応する collision 関数を呼び出す | |
6 * 新しい SceneGraoh を生成する | |
7 * 登録してある global を解放する task を用意する | |
8 * | |
5 */ | 9 */ |
6 | 10 |
7 // #define DEBUG | 11 // #define DEBUG |
8 #include "error.h" | 12 #include "error.h" |
9 | |
10 #include "CreatePolygon.h" | |
11 #include "polygon_pack.h" | |
12 #include "scene_graph_pack.h" | 13 #include "scene_graph_pack.h" |
13 | 14 |
14 SchedDefineTask(CreatePolygon); | 15 // 本来は tasks.xml に書く |
16 SchedDefineTask(SceneGraphCollision); | |
15 | 17 |
16 #define SG_PACK_LOAD 10 | 18 int |
17 #define SG_NODE_LOAD 11 | 19 move::run(void *rbuf, void *wbuf) |
18 #define PP_LOAD 12 | 20 { |
19 #define PP_STORE 13 | 21 __debug_spe("SceneGraphCollision\n"); |
20 | 22 |
21 /** | 23 SceneGraphPackPtr cur = (SceneGraphPack*) rbuf; |
22 * あとで直す | 24 int collision_task_id = cur->collision_task; |
23 */ | 25 // next は Mainmemory 上のアドレス |
24 static void | 26 SceneGraphPackPtr next = |
25 rotate(float *xyz, float *matrix) | 27 (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack)); |
26 { | |
27 float abc[4]; | |
28 | 28 |
29 abc[0] = xyz[0]; | 29 if (smanager->call_task(collision_task_id, (void*)cur, (void*)next)) { |
30 abc[1] = xyz[1]; | 30 // 次の状態があって、新しく node を確保してそこを確保する |
31 abc[2] = xyz[2]; | 31 smanager->write(cur, next, sizeof(SceneGraphPack)); |
32 abc[3] = xyz[3]; | 32 } else { |
33 | 33 // この node は消滅 |
34 for(int i=0; i<4; i++) | 34 smanager->free(next); |
35 { | |
36 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; | |
37 } | 35 } |
38 } | |
39 | |
40 int | |
41 CreatePolygon::run(void *rbuf, void *wbuf) | |
42 { | |
43 __debug_spe("CreatePolygon\n"); | |
44 | |
45 float xyz1[4],xyz2[4],xyz3[4]; | |
46 | |
47 SceneGraphPackPtr sgp = (SceneGraphPack*)smanager->get_input(0); | |
48 SceneGraphPackPtr next_sgp = | |
49 (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack)); | |
50 SceneGraphPackPtr free_sgp = next_sgp; | |
51 SceneGraphPackPtr tmp_sgp; | |
52 | |
53 SceneGraphNodePtr node; | |
54 SceneGraphNodePtr next_node | |
55 = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode)); | |
56 SceneGraphNodePtr free_node = next_node; | |
57 SceneGraphNodePtr tmp_node; | |
58 | |
59 PolygonPackPtr pp | |
60 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); | |
61 PolygonPackPtr send_pp | |
62 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); | |
63 PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(0); | |
64 PolygonPackPtr tmp_pp; | |
65 | |
66 pp->init(); | |
67 send_pp->init(); | |
68 | |
69 do { | |
70 if (sgp->next != NULL) { | |
71 smanager->dma_load(next_sgp, (uint32)sgp->next, | |
72 sizeof(SceneGraphPack), SG_PACK_LOAD); | |
73 } else { | |
74 next_sgp = NULL; | |
75 } | |
76 | |
77 for (int i = 0; i < sgp->info.size; i++) { | |
78 node = &sgp->node[i]; | |
79 | |
80 do { | |
81 if (node->next != NULL) { | |
82 smanager->dma_load(next_node, (uint32)node->next, | |
83 sizeof(SceneGraphNode), SG_NODE_LOAD); | |
84 } else { | |
85 next_node = NULL; | |
86 } | |
87 | |
88 for (int n = 0, nt = 0; n < node->size*3; n+=9, nt+=6) { | |
89 | |
90 if (pp->info.size >= MAX_SIZE_TRIANGLE) { | |
91 PolygonPackPtr next; | |
92 | |
93 // smanager から Task を作る、0 ではなく PolygonPack->task_id が良い | |
94 smanager->mainMem_alloc(0, sizeof(PolygonPack)); | |
95 smanager->mainMem_wait(); | |
96 next = (PolygonPackPtr)smanager->mainMem_get(0); | |
97 | |
98 pp->next = next; // この部分は TaskManager 側でやるべき | |
99 | |
100 tmp_pp = pp; | |
101 pp = send_pp; | |
102 send_pp = tmp_pp; | |
103 | |
104 smanager->dma_wait(PP_STORE); | |
105 smanager->dma_store(send_pp, (uint32)pp_addr, | |
106 sizeof(PolygonPack), PP_STORE); | |
107 | |
108 pp_addr = next; | |
109 | |
110 smanager->dma_wait(PP_LOAD); // 多分不要 | |
111 smanager->dma_load(pp, (uint32)pp_addr, | |
112 sizeof(PolygonPack), PP_LOAD); | |
113 // 次の dma_wait のコストが高いのでパイプラインで隠す必要がある | |
114 | |
115 smanager->dma_wait(PP_LOAD); | |
116 pp->init(); | |
117 | |
118 } | |
119 | |
120 TrianglePack *triangle = &pp->tri[pp->info.size++]; | |
121 | |
122 xyz1[0] = node->vertex[n]; | |
123 xyz1[1] = node->vertex[n+1]; | |
124 xyz1[2] = node->vertex[n+2]*-1; | |
125 xyz1[3] = 1; | |
126 xyz2[0] = node->vertex[n+3]; | |
127 xyz2[1] = node->vertex[n+3+1]; | |
128 xyz2[2] = node->vertex[n+3+2]*-1; | |
129 xyz2[3] = 1; | |
130 xyz3[0] = node->vertex[n+6]; | |
131 xyz3[1] = node->vertex[n+6+1]; | |
132 xyz3[2] = node->vertex[n+6+2]*-1; | |
133 xyz3[3] = 1; | |
134 | |
135 rotate(xyz1, node->translation); | |
136 rotate(xyz2, node->translation); | |
137 rotate(xyz3, node->translation); | |
138 | |
139 triangle->ver1.x = xyz1[0]; | |
140 triangle->ver1.y = xyz1[1]; | |
141 triangle->ver1.z = xyz1[2]; | |
142 triangle->ver1.tex_x = node->texture[nt]; | |
143 triangle->ver1.tex_y = node->texture[nt+1]; | |
144 | |
145 triangle->ver2.x = xyz2[0]; | |
146 triangle->ver2.y = xyz2[1]; | |
147 triangle->ver2.z = xyz2[2]; | |
148 triangle->ver2.tex_x = node->texture[nt+2]; | |
149 triangle->ver2.tex_y = node->texture[nt+2+1]; | |
150 | |
151 triangle->ver3.x = xyz3[0]; | |
152 triangle->ver3.y = xyz3[1]; | |
153 triangle->ver3.z = xyz3[2]; | |
154 triangle->ver3.tex_x = node->texture[nt+4]; | |
155 triangle->ver3.tex_y = node->texture[nt+4+1]; | |
156 | |
157 #if 1 | |
158 triangle->tex_info.addr = node->tex_addr; | |
159 triangle->tex_info.width = node->tex_width; | |
160 triangle->tex_info.height = node->tex_height; | |
161 #else | |
162 triangle->tex_info.addr = node->texture_info.pixels; | |
163 triangle->tex_info.width = node->texture_info.t_w; | |
164 triangle->tex_info.height = node->texture_info.t_h; | |
165 #endif | |
166 } | |
167 | |
168 smanager->dma_wait(SG_NODE_LOAD); | |
169 | |
170 tmp_node = node; | |
171 node = next_node; | |
172 next_node = tmp_node; | |
173 } while (node); | |
174 | |
175 next_node = free_node; | |
176 } | |
177 | |
178 smanager->dma_wait(SG_PACK_LOAD); | |
179 | |
180 tmp_sgp = sgp; | |
181 sgp = next_sgp; | |
182 next_sgp = tmp_sgp; | |
183 } while (sgp); | |
184 | |
185 smanager->dma_wait(PP_STORE); | |
186 smanager->dma_store(pp, (uint32)pp_addr, | |
187 sizeof(PolygonPack), PP_STORE); | |
188 smanager->dma_wait(PP_STORE); | |
189 | |
190 free(pp); | |
191 free(send_pp); | |
192 free(free_node); | |
193 free(free_sgp); | |
194 | 36 |
195 return 0; | 37 return 0; |
196 } | 38 } |