Mercurial > hg > Game > Cerium
annotate TaskManager/Test/test_render/viewer.cpp @ 268:2b7d631695ca draft
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 04 Jun 2009 00:00:09 +0900 |
parents | e3b7776b1420 943c2ebe4483 |
children | abf96b4caee5 |
rev | line source |
---|---|
140 | 1 #include <SDL.h> |
109 | 2 #include "viewer.h" |
120 | 3 #include "viewer_types.h" |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
4 #include "SceneGraph.h" |
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
5 #include "scene_graph_pack.h" |
109 | 6 #include "sys.h" |
7 #include "Func.h" | |
8 #include "error.h" | |
9 #include "TaskManager.h" | |
140 | 10 #include "Keyboard.h" |
11 #include "Joystick.h" | |
109 | 12 |
13 extern void post2runLoop(void *); | |
14 extern void post2runDraw(void *); | |
15 | |
16 /* measure for FPS (Frame Per Second) */ | |
17 int start_time; | |
18 int this_time; | |
19 int frames; | |
20 | |
140 | 21 extern SceneGraphPtr scene_graph; |
22 extern SceneGraphPtr scene_graph_viewer; | |
109 | 23 |
176 | 24 /* Data Pack sent to Other CPUs (ex. SPE) */ |
109 | 25 SceneGraphPack *sgpack; |
26 PolygonPack *ppack; | |
27 SpanPackPtr spackList; | |
28 SpanPackPtr *spackList_ptr; | |
29 int spackList_length; | |
30 int spackList_length_align; | |
31 | |
177 | 32 static float *zRow; |
33 | |
140 | 34 /** |
176 | 35 * |
36 */ | |
37 | |
140 | 38 /** |
39 * Joystick があればそれを使い、 | |
40 * 無ければキーボードを返す | |
41 */ | |
42 static Pad* | |
43 create_controller(void) | |
44 { | |
45 if (SDL_NumJoysticks()) { | |
46 SDL_Joystick *joy = SDL_JoystickOpen(0); | |
47 if (!joy) { | |
48 fprintf(stderr, "%s: failed to open joystick", __FUNCTION__); | |
49 return new Keyboard; | |
50 } else { | |
51 printf("Use Joystick\n"); | |
52 return new Joystick(joy); | |
53 } | |
54 } else { | |
55 printf("Use Keyboard\n"); | |
56 return new Keyboard; | |
57 } | |
58 } | |
59 | |
60 | |
109 | 61 Viewer::Viewer(int b, int w, int h, int _num) |
62 { | |
63 bpp = b; | |
64 width = w; | |
65 height = h; | |
66 spe_num = _num; | |
67 } | |
68 | |
69 int | |
70 Viewer::get_ticks() | |
71 { | |
72 int time; | |
73 time = SDL_GetTicks(); | |
74 return time; | |
75 } | |
76 | |
77 bool | |
78 Viewer::quit_check() | |
79 { | |
80 SDL_Event event; | |
81 | |
82 while(SDL_PollEvent(&event)) { | |
83 if (event.type==SDL_QUIT) { | |
84 return true; | |
85 } | |
86 } | |
87 | |
88 Uint8 *keys=SDL_GetKeyState(NULL); | |
89 | |
90 if (keys[SDLK_q] == SDL_PRESSED) { | |
91 return true; | |
92 } | |
93 | |
94 return false; | |
95 } | |
96 | |
97 void | |
98 Viewer::quit() | |
99 { | |
100 SDL_Quit(); | |
101 } | |
102 | |
103 void | |
104 Viewer::swap_buffers() | |
105 { | |
106 SDL_GL_SwapBuffers(); | |
107 } | |
108 | |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
109 extern void node_init(void); |
144 | 110 extern void create_cube_split(int); |
153
70146cdec3d4
画像のサイズテストを加える -sg = [2,3,4]
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
150
diff
changeset
|
111 extern void create_snake_bg(int); |
158 | 112 extern void universe_init(void); |
142 | 113 |
109 | 114 void |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
177
diff
changeset
|
115 Viewer::run_init(const char *xml, int sg_number) |
109 | 116 { |
117 HTaskPtr task_next; | |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
118 HTaskPtr task_tex; |
109 | 119 |
120 start_time = get_ticks(); | |
121 this_time = 0; | |
122 frames = 0; | |
123 | |
140 | 124 //scene_graph = SceneGraph::createFromXMLfile(xml); |
125 /** | |
126 * これを実行すると、 | |
127 * scene_graph にオリジナルの SceneGraph Object のリストが、 | |
128 * scene_graph_viewer に描画用の SceneGraph が生成される | |
129 */ | |
142 | 130 //SceneGraph::createFromXMLfile(xml); |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
131 //polygon->viewer = this; |
140 | 132 |
144 | 133 switch (sg_number) { |
134 case 0: | |
135 case 1: | |
136 create_cube_split(sg_number); | |
137 break; | |
138 case 2: | |
153
70146cdec3d4
画像のサイズテストを加える -sg = [2,3,4]
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
150
diff
changeset
|
139 case 3: |
70146cdec3d4
画像のサイズテストを加える -sg = [2,3,4]
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
150
diff
changeset
|
140 case 4: |
70146cdec3d4
画像のサイズテストを加える -sg = [2,3,4]
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
150
diff
changeset
|
141 create_snake_bg(sg_number); |
144 | 142 break; |
153
70146cdec3d4
画像のサイズテストを加える -sg = [2,3,4]
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
150
diff
changeset
|
143 case 5: |
158 | 144 universe_init(); |
145 break; | |
146 case 6: | |
144 | 147 node_init(); |
148 break; | |
149 default: | |
150 node_init(); | |
151 break; | |
152 } | |
142 | 153 |
140 | 154 scene_graph->controller = create_controller(); |
109 | 155 |
156 sgpack = (SceneGraphPack*)manager->malloc(sizeof(SceneGraphPack)); | |
157 sgpack->init(); | |
158 ppack = (PolygonPack*)manager->malloc(sizeof(PolygonPack)); | |
159 | |
160 spackList_length = (this->height + split_screen_h - 1) / split_screen_h; | |
161 spackList = (SpanPack*)manager->malloc(sizeof(SpanPack)*spackList_length); | |
162 | |
176 | 163 /** |
164 * SPU に送る address list は 16 バイト倍数でないといけない。 | |
165 * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような | |
166 * length_align を求めている。はみ出した部分は使われない | |
167 * (ex) spackList_length が 13 の場合 | |
168 * spackList_length_align = 16; | |
169 * 実際に送るデータは64バイトになるのでOK | |
170 * 14,15,16 の部分は何も入らない。 | |
171 */ | |
109 | 172 spackList_length_align = (spackList_length + 3)&(~3); |
173 | |
174 /* 各 SPU が持つ、SpanPack の address list */ | |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
175 spackList_ptr = |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
176 (SpanPack**)manager->malloc(sizeof(SpanPack*)*spackList_length_align); |
109 | 177 |
178 for (int i = 0; i < spackList_length; i++) { | |
179 spackList_ptr[i] = &spackList[i]; | |
180 } | |
181 | |
126
74d0a70f60e9
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
182 for (int i = 1; i <= spackList_length; i++) { |
74d0a70f60e9
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
183 spackList[i-1].init(i*split_screen_h); |
74d0a70f60e9
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
184 } |
74d0a70f60e9
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
185 |
109 | 186 task_next = manager->create_task(TASK_DUMMY); |
187 task_next->set_post(&post2runLoop, NULL); | |
188 | |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
189 #if 0 |
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
190 // 諸事情で、今は SceneGraphPack を作らずに |
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
191 // そのまま SceneGraph でやっています |
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
192 HTaskPtr task_sgp; |
109 | 193 task_sgp = manager->create_task(TASK_CREATE_SGP); |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
194 task_sgp->add_param((uint32)scene_graph); |
109 | 195 task_sgp->add_param((uint32)sgpack); |
196 task_next->wait_for(task_sgp); | |
197 task_sgp->spawn(); | |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
198 #endif |
109 | 199 |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
200 for (int i = 0; i < spe_num; i++) { |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
201 task_tex = manager->create_task(TASK_INIT_TEXTURE); |
176 | 202 /* ここはもう少しわかりやすい使い方がいいかもしれぬ。こんなもん? */ |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
203 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
204 task_next->wait_for(task_tex); |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
158
diff
changeset
|
205 task_tex->spawn(); |
120 | 206 } |
207 | |
109 | 208 task_next->spawn(); |
177 | 209 |
210 zRow=(float*)manager->malloc(sizeof(float)*split_screen_w*split_screen_h); | |
211 | |
212 for (int i = 0; i < split_screen_w*split_screen_h; i++) { | |
213 zRow[i] = 65535.0f; // __FLT_MAX__ とかでも | |
214 } | |
109 | 215 } |
216 | |
217 void | |
218 Viewer::run_loop(void) | |
219 { | |
220 HTaskPtr task_create_pp = NULL; | |
221 HTaskPtr task_create_sp = NULL; | |
222 HTaskPtr task_next; | |
223 bool quit_flg; | |
224 | |
225 quit_flg = quit_check(); | |
226 | |
227 if (quit_flg == true) { | |
228 this_time = get_ticks(); | |
229 run_finish(); | |
230 return; | |
231 } | |
232 | |
233 clean_pixels(); | |
234 | |
235 for (int i = 1; i <= spackList_length; i++) { | |
126
74d0a70f60e9
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
236 spackList[i-1].reinit(i*split_screen_h); |
109 | 237 } |
238 | |
239 task_next = manager->create_task(TASK_DUMMY); | |
240 task_next->set_post(post2runDraw, NULL); | |
241 | |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
242 #if 0 |
157 | 243 // SceneGraphPack の update |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
244 HTaskPtr task_update_sgp = NULL; |
109 | 245 task_update_sgp = manager->create_task(TASK_UPDATE_SGP); |
246 task_update_sgp->add_inData(sgpack, sizeof(SceneGraphPack)); | |
247 task_update_sgp->add_outData(sgpack, sizeof(SceneGraphPack)); | |
248 task_update_sgp->add_param(width); | |
249 task_update_sgp->add_param(height); | |
250 task_next->wait_for(task_update_sgp); | |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
251 task_update_sgp->spawn(); |
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
252 #else |
140 | 253 scene_graph->controller->check(); |
254 scene_graph_viewer->all_execute(width, height); | |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
255 #endif |
109 | 256 |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
257 #if 0 |
157 | 258 // SceneGraphPack(配列) -> PolygonPack |
109 | 259 task_create_pp = manager->create_task(TASK_CREATE_PP); |
260 task_create_pp->add_inData(sgpack, sizeof(SceneGraphPack)); | |
261 task_create_pp->add_param((uint32)ppack); | |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
262 #else |
157 | 263 // SceneGraph(木構造) -> PolygonPack |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
264 task_create_pp = manager->create_task(TASK_CREATE_PP2); |
140 | 265 task_create_pp->add_param((uint32)scene_graph_viewer); |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
266 task_create_pp->add_param((uint32)ppack); |
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
267 #endif |
109 | 268 task_next->wait_for(task_create_pp); |
269 | |
270 int range_base = spe_num; | |
271 // 切り上げのつもり | |
272 int range = (spackList_length + range_base - 1) / range_base; | |
273 | |
274 for (int i = 0; i < range_base; i++) { | |
275 int index_start = range*i; | |
276 int index_end = (index_start + range >= spackList_length) | |
277 ? spackList_length : index_start + range; | |
278 | |
279 task_create_sp = manager->create_task(TASK_CREATE_SPAN); | |
280 task_create_sp->add_inData(ppack, sizeof(PolygonPack)); | |
281 task_create_sp->add_inData(spackList_ptr, | |
282 sizeof(SpanPack*)*spackList_length_align); | |
283 task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); | |
284 | |
285 task_create_sp->add_param(index_start); | |
286 | |
287 /** | |
133
8f1419174cdf
DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
130
diff
changeset
|
288 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 |
109 | 289 * [ 1.. 80] [ 81..160] [161..240] |
290 * [241..320] [321..400] [401..480] | |
291 * | |
292 * ex. screen_height が 1080, spenum が 5 の場合、 | |
293 * [ 1..216] [217..432] [433..648] | |
294 * [649..864] [865..1080] | |
295 */ | |
296 task_create_sp->add_param(index_start*split_screen_h + 1); | |
297 task_create_sp->add_param(index_end*split_screen_h); | |
298 | |
299 task_next->wait_for(task_create_sp); | |
300 task_create_sp->wait_for(task_create_pp); | |
301 | |
302 task_create_sp->set_cpu(SPE_ANY); | |
303 task_create_sp->spawn(); | |
304 } | |
305 | |
306 task_create_pp->spawn(); | |
307 task_next->spawn(); | |
308 } | |
309 | |
310 void | |
311 Viewer::run_draw(void) | |
312 { | |
313 HTaskPtr task_next; | |
314 HTaskPtr task_draw; | |
315 | |
316 task_next = manager->create_task(TASK_DUMMY); | |
317 task_next->set_post(post2runLoop, NULL); | |
318 | |
319 ppack->clear(); | |
320 | |
321 for (int i = 0; i < spackList_length; i++) { | |
322 SpanPack *spack = &spackList[i]; | |
323 int startx = 1; | |
324 int endx = split_screen_w; | |
325 | |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
177
diff
changeset
|
326 int starty = spack->info.y_top - split_screen_h + 1; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
177
diff
changeset
|
327 //int endy = spack->info.y_top; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
177
diff
changeset
|
328 int rangey = (starty + split_screen_h - 1 > this->height) |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
177
diff
changeset
|
329 ? this->height - starty + 1 : split_screen_h; |
109 | 330 |
331 while (startx < this->width) { | |
332 if (spack->info.size > 0) { | |
333 // Draw SpanPack | |
334 task_draw = manager->create_task(TASK_DRAW_SPAN); | |
335 task_draw->add_inData(spack, sizeof(SpanPack)); | |
177 | 336 |
337 task_draw->add_inData(zRow, | |
338 sizeof(float)*(endx-startx+1)*rangey); | |
109 | 339 } else { |
340 // Draw Background (現在は塗りつぶし) | |
341 task_draw = manager->create_task(TASK_DRAW_BACK); | |
266 | 342 <<<<<<< local |
170 | 343 task_draw->add_param(0xffffffff); |
267 | 344 ======= |
345 <<<<<<< local | |
133
8f1419174cdf
DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
130
diff
changeset
|
346 task_draw->add_param(0xffffff); |
266 | 347 ======= |
122 | 348 //task_draw->add_param(0x00ffcc55); |
349 task_draw->add_param(0); | |
350 //task_draw->add_param(st_rgb); | |
266 | 351 >>>>>>> other |
267 | 352 >>>>>>> other |
109 | 353 } |
176 | 354 |
109 | 355 for (int k = 0; k < rangey; k++) { |
356 task_draw->add_outData( | |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
177
diff
changeset
|
357 &pixels[(startx-1)+this->width*(k+starty-1)], |
109 | 358 (endx - startx + 1)*sizeof(int)); |
359 } | |
360 | |
361 task_draw->add_param(startx); | |
362 task_draw->add_param(endx); | |
363 task_draw->add_param(rangey); | |
364 task_draw->set_cpu(SPE_ANY); | |
365 task_next->wait_for(task_draw); | |
366 task_draw->spawn(); | |
367 | |
368 startx += split_screen_w; | |
369 endx += split_screen_w; | |
370 | |
371 if (endx > this->width) { | |
372 endx = this->width; | |
373 } | |
374 } | |
375 } | |
376 | |
377 task_next->spawn(); | |
378 | |
379 frames++; | |
380 } | |
381 | |
382 void | |
383 Viewer::run_finish(void) | |
384 { | |
385 if (this_time != start_time) { | |
386 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); | |
387 } | |
388 | |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
389 scene_graph->delete_data(); |
140 | 390 scene_graph->controller->close(); |
137
91c74dbc32e4
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
391 delete scene_graph; |
109 | 392 |
393 quit(); | |
394 } |