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