Mercurial > hg > Game > Cerium
annotate Renderer/Engine/SceneGraphRoot.cc @ 582:4ee1d40823b8 draft
fix realloc
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 24 Oct 2009 18:15:18 +0900 |
parents | ec9dd24c2dc8 |
children | 7e33deb9d3f4 |
rev | line source |
---|---|
539 | 1 #include <SDL.h> |
2 #include <SDL_image.h> | |
3 #include <libxml/parser.h> | |
4 #include "SceneGraphRoot.h" | |
5 #include "xml.h" | |
6 #include "sys.h" | |
7 #include "TextureHash.h" | |
8 #include "texture.h" | |
562 | 9 //#include "SGList.h" |
10 #include "Application.h" | |
539 | 11 |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
12 static int cnt = 0; |
562 | 13 static const int SGLIST_LENGTH = 138; |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
14 static int sg_src_size = SGLIST_LENGTH ; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
15 static int sg_src_id = -1; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
16 static SceneGraphPtr *sg_src; |
562 | 17 |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
18 |
558 | 19 SceneGraphRoot *sgroot; |
20 | |
539 | 21 SceneGraphRoot::SceneGraphRoot(float w, float h) |
22 { | |
562 | 23 // SGLIST_LENGTH 決め打ちかぁ、動的生成にする場合上限決めておいた方がいいのかな |
24 // | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
25 sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH); |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
26 |
539 | 27 camera = new Camera(w, h); |
28 iterator = new SceneGraphIterator; | |
29 controller = create_controller(); | |
30 | |
31 sg_exec_tree = NULL; | |
32 sg_draw_tree = NULL; | |
33 sg_available_list = NULL; | |
34 sg_remove_list = NULL; | |
35 | |
562 | 36 sgroot = this; |
37 | |
539 | 38 // TODO |
39 // 今はとりあえず camera を Root にしています | |
40 // 今はそれすらもしてません | |
41 //sg_exec_tree = camera; | |
42 } | |
43 | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
44 SceneGraphRoot::~SceneGraphRoot() |
539 | 45 { |
46 SceneGraphPtr p = sg_available_list; | |
47 | |
48 while (p) { | |
49 SceneGraphPtr tmp = p->next; | |
50 delete p; | |
51 p = tmp; | |
52 cnt--; | |
53 } | |
54 | |
55 p = sg_remove_list; | |
56 | |
57 while (p) { | |
58 SceneGraphPtr tmp = p->next; | |
59 delete p; | |
60 p = tmp; | |
61 cnt--; | |
62 } | |
63 | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
64 free(sg_src); |
539 | 65 delete camera; |
66 delete iterator; | |
67 delete controller; | |
68 } | |
69 | |
70 /** | |
71 * xml ファイルから生成された SceneGraph を sg_src に登録する。 | |
72 * | |
73 * @param sg SceneGraph created by xmlfile | |
74 */ | |
75 void | |
76 SceneGraphRoot::registSceneGraph(SceneGraphPtr sg) | |
77 { | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
78 int dup; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
79 if ((dup = getSgid(sg->name))>=0) { // while... |
576 | 80 sg_src[dup]->name = ""; |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
81 // we should remove this. but some one may use it... |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
82 } |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
83 if (sg_src_id+1> sg_src_size) { |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
84 sg_src_size *= 2; |
582 | 85 sg_src = (SceneGraphPtr*)realloc(sg_src, sg_src_size*sizeof(SceneGraphPtr)); |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
86 } |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
87 sg->sgid = ++sg_src_id; |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
88 sg_src[sg->sgid] = sg; |
539 | 89 } |
90 | |
91 void | |
92 SceneGraphRoot::addNext(SceneGraphPtr sg) | |
93 { | |
94 SceneGraphPtr last = sg_available_list; | |
95 | |
96 if (!last) { | |
97 sg_available_list = sg; | |
98 } else { | |
99 while (last->next) { | |
100 last = last->next; | |
101 } | |
102 last->next = sg; | |
103 sg->prev = last; | |
104 } | |
105 | |
106 cnt++; | |
107 } | |
108 | |
109 /* XMLファイルからポリゴンを作成 */ | |
110 void | |
111 SceneGraphRoot::createFromXMLfile(TaskManager *manager, const char *xmlfile) | |
112 { | |
113 xmlDocPtr doc; | |
114 xmlNodePtr cur; | |
115 SceneGraphPtr tmp; | |
562 | 116 |
539 | 117 /* パース DOM生成 */ |
118 doc = xmlParseFile(xmlfile); | |
119 cur = xmlDocGetRootElement(doc); | |
120 | |
121 /* ?? */ | |
122 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D"); | |
123 | |
124 /* XMLのノードを一つずつ解析 */ | |
125 for (cur=cur->children; cur; cur=cur->next) { | |
562 | 126 /* 扱うのはsurfaceオンリー */ |
127 if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) { | |
128 continue; | |
129 } | |
539 | 130 |
562 | 131 /* ポリゴン(SceneGraph)生成 */ |
132 tmp = new SceneGraph(manager, cur); | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
133 registSceneGraph(tmp); |
539 | 134 } |
135 xmlFreeDoc(doc); | |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
136 } |
562 | 137 |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
138 void |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
139 SceneGraphRoot::createFromXMLmemory(TaskManager *manager, SceneGraph *node, char *data, int len) |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
140 { |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
141 xmlDocPtr doc; |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
142 xmlNodePtr cur; |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
143 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
144 // size は取れるはず、テスト用に mmap したデータを使う |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
145 /* パース DOM生成 */ |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
146 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
147 doc = xmlParseMemory(data, len); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
148 cur = xmlDocGetRootElement(doc); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
149 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
150 /* ?? */ |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
151 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D"); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
152 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
153 /* XMLのノードを一つずつ解析 */ |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
154 for (cur=cur->children; cur; cur=cur->next) { |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
155 /* 扱うのはsurfaceオンリー */ |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
156 if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) { |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
157 continue; |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
158 } |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
159 /* ポリゴン(SceneGraph)生成 */ |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
160 SceneGraphPtr original = new SceneGraph(manager, cur); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
161 registSceneGraph(original); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
162 SceneGraphPtr clone = createSceneGraph(original->sgid); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
163 node->addChild(clone); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
164 } |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
165 xmlFreeDoc(doc); |
539 | 166 } |
167 | |
168 SceneGraphPtr | |
169 SceneGraphRoot::createSceneGraph(int id) | |
170 { | |
171 SceneGraphPtr src; | |
172 SceneGraphPtr p; | |
173 | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
174 if (id < 0 || id > sg_src_size) { |
539 | 175 return NULL; |
176 } | |
177 | |
178 /* オリジナルの SceneGraph */ | |
562 | 179 src = sg_src[id]; |
539 | 180 |
181 /* ユーザーにはオリジナルの clone を返す */ | |
182 p = src->clone(); | |
183 | |
184 addNext(p); | |
185 | |
186 return p; | |
187 } | |
188 | |
562 | 189 |
190 | |
191 | |
192 SceneGraphPtr | |
193 SceneGraphRoot::createSceneGraph(const char *name) | |
194 { | |
195 SceneGraphPtr src; | |
196 SceneGraphPtr p; | |
197 | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
198 int id = getSgid(name); |
562 | 199 if (id < 0) { |
200 return NULL; | |
201 } | |
202 | |
203 /* オリジナルの SceneGraph */ | |
204 src = sg_src[id]; | |
205 | |
206 /* ユーザーにはオリジナルの clone を返す */ | |
207 p = src->clone(); | |
208 | |
209 addNext(p); | |
210 | |
211 return p; | |
212 } | |
213 | |
214 int | |
215 SceneGraphRoot::getSgid(const char *name) | |
216 { | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
217 for(int i =0;i<= sg_src_id; i++) { |
576 | 218 if (sg_src[i] && strcmp(name,sg_src[i]->name) == 0) |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
219 return i; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
220 } |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
221 return -1; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
222 } |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
223 |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
224 int |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
225 SceneGraphRoot::getLast() |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
226 { |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
227 if (sg_src_id>=0) |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
228 return sg_src[sg_src_id]->sgid; |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
229 return -1; |
562 | 230 } |
231 | |
539 | 232 /** |
233 * 何も表示しない、move,collision もしない SceneGraph を生成 | |
234 * いずれ、Transform3D 的なものに回す予定 | |
235 */ | |
236 SceneGraphPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
237 SceneGraphRoot::createSceneGraph() |
539 | 238 { |
239 SceneGraphPtr p = new SceneGraph; | |
240 | |
241 addNext(p); | |
242 p->flag_drawable = 0; | |
243 | |
244 return p; | |
245 } | |
246 | |
247 void | |
248 SceneGraphRoot::speExecute(int screen_w, int screen_h) | |
249 { | |
250 | |
251 SceneGraphPtr list = sg_available_list; | |
252 // SceneGraphPtr t = sg_exec_tree; | |
253 // SceneGraphPtr cur_parent = camera; | |
254 | |
255 // 前フレームで描画した SceneGraph は削除 | |
256 allRemove(sg_remove_list); | |
257 | |
258 // 前フレームに作られた SceneGraph は描画用に移行 | |
259 // 現フレームでの操作は以下の tree,list には適用されない | |
260 sg_draw_tree = sg_exec_tree; | |
261 sg_remove_list = sg_available_list; | |
262 | |
263 // 現フレームで新しく SceneGraph がコピーされるので初期化 | |
264 sg_exec_tree = NULL; | |
265 sg_available_list = NULL; | |
266 | |
267 camera->move_execute(screen_w, screen_h); | |
268 camera->update(screen_w, screen_h); | |
269 | |
270 camera->children = NULL; | |
271 camera->lastChild = NULL; | |
272 | |
273 list->move_execute(screen_w, screen_h); | |
274 list->collision_check(screen_w, screen_h, list); | |
275 | |
276 list->frame++; | |
277 list = list->next; | |
278 | |
279 if(sg_exec_tree != NULL) { | |
280 return; | |
281 } | |
282 | |
283 /*removeのflagをもとにtreeを形成*/ | |
284 /* spe から送り返されてきた property の配列を見て生成する for()*/ | |
285 /* | |
562 | 286 for (Property *t = (Property*)app->property[0]; is_end(t); t++){ |
287 SceneGraphPtr s = app->scenegraph_factory(t); // SceneGraphNode を作る | |
288 t->scenegraph = s; // property list には SceneGraphへのポインタが入っている | |
289 app->scenegraph_connector(property[0], s); // add する | |
290 } | |
291 */ | |
292 | |
293 | |
294 // 現在、allExecute が終わった時点では | |
295 // camera->children が User SceneGraph の root になる | |
296 | |
297 /** | |
298 * NULL じゃなかったら、setSceneData が呼ばれてるから | |
299 * そっちを次の Scene にする | |
300 */ | |
301 | |
302 sg_exec_tree = camera->children; | |
303 } | |
304 | |
305 void | |
306 SceneGraphRoot::speExecute(int screen_w, int screen_h, Application *app) | |
307 { | |
308 // SceneGraphPtr t = sg_exec_tree; | |
309 // SceneGraphPtr cur_parent = camera; | |
310 | |
311 // 前フレームで描画した SceneGraph は削除 | |
312 allRemove(sg_remove_list); | |
313 | |
314 // 前フレームに作られた SceneGraph は描画用に移行 | |
315 // 現フレームでの操作は以下の tree,list には適用されない | |
316 sg_draw_tree = sg_exec_tree; | |
317 sg_remove_list = sg_available_list; | |
318 | |
319 // 現フレームで新しく SceneGraph がコピーされるので初期化 | |
320 sg_exec_tree = NULL; | |
321 sg_available_list = NULL; | |
322 | |
323 camera->move_execute(screen_w, screen_h); | |
324 camera->update(screen_w, screen_h); | |
325 | |
326 camera->children = NULL; | |
327 camera->lastChild = NULL; | |
328 | |
329 | |
330 if(sg_exec_tree != NULL) { | |
331 return; | |
332 } | |
333 | |
334 /*removeのflagをもとにtreeを形成*/ | |
335 /* spe から送り返されてきた property の配列を見て生成する for()*/ | |
336 /* Application内に移動 */ | |
337 | |
338 // app->property_ope(sg_available_list); | |
339 | |
340 /* | |
341 for (Property *t = (Property *)properties[0]; is_end(t); t++){ | |
342 SceneGraphPtr s = app->scenegraph_factory(t); // SceneGraphNode を作る | |
343 t->scenegraph = s; // property list には SceneGraphへのポインタが入っている | |
344 app->scenegraph_connector(property[0], s); // add する | |
345 } | |
539 | 346 */ |
562 | 347 |
348 | |
539 | 349 |
350 // 現在、allExecute が終わった時点では | |
351 // camera->children が User SceneGraph の root になる | |
352 | |
353 /** | |
354 * NULL じゃなかったら、setSceneData が呼ばれてるから | |
355 * そっちを次の Scene にする | |
356 */ | |
357 | |
358 sg_exec_tree = camera->children; | |
359 } | |
360 | |
361 | |
362 void | |
363 SceneGraphRoot::allExecute(int screen_w, int screen_h) | |
364 { | |
365 SceneGraphPtr list = sg_available_list; | |
366 SceneGraphPtr t = sg_exec_tree; | |
367 SceneGraphPtr cur_parent = camera; | |
368 | |
369 // 前フレームで描画した SceneGraph は削除 | |
370 allRemove(sg_remove_list); | |
371 | |
372 // 前フレームに作られた SceneGraph は描画用に移行 | |
373 // 現フレームでの操作は以下の tree,list には適用されない | |
374 sg_draw_tree = sg_exec_tree; | |
375 sg_remove_list = sg_available_list; | |
376 | |
377 // 現フレームで新しく SceneGraph がコピーされるので初期化 | |
378 sg_exec_tree = NULL; | |
379 sg_available_list = NULL; | |
380 | |
381 camera->move_execute(screen_w, screen_h); | |
382 camera->update(screen_w, screen_h); | |
383 | |
384 camera->children = NULL; | |
385 camera->lastChild = NULL; | |
386 | |
387 /*まずは全部動作させる*/ | |
388 while (list) { | |
389 | |
390 list->move_execute(screen_w, screen_h); | |
391 list->collision_check(screen_w, screen_h, list); | |
392 | |
393 list->frame++; | |
394 list = list->next; | |
395 | |
396 } | |
397 | |
398 if(sg_exec_tree != NULL) { | |
399 return; | |
400 } | |
401 | |
402 /*removeのflagをもとにtreeを形成*/ | |
403 while (t) { | |
404 SceneGraphPtr c = NULL; | |
405 if (!t->isRemoved()) { | |
406 c = t->clone(); | |
407 addNext(c); | |
408 cur_parent->addChild(c); | |
409 c->frame = t->frame; | |
410 /*親の回転、座標から、子の回転、座標を算出*/ | |
411 get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); | |
412 } | |
413 | |
414 if (t->children != NULL && c != NULL) { | |
415 cur_parent = c; | |
416 t = t->children; | |
417 } else if (t->brother != NULL) { | |
418 t = t->brother; | |
419 } else { | |
420 while (t) { | |
421 if (t->brother != NULL) { | |
422 t = t->brother; | |
423 break; | |
424 } else { | |
425 if (t->parent == NULL) { | |
426 t = NULL; | |
427 break; | |
428 } else { | |
429 cur_parent = cur_parent->parent; | |
430 t = t->parent; | |
431 | |
432 } | |
433 } | |
434 } | |
435 } | |
436 } | |
437 | |
438 | |
439 | |
440 // 現在、allExecute が終わった時点では | |
441 // camera->children が User SceneGraph の root になる | |
442 | |
443 /** | |
444 * NULL じゃなかったら、setSceneData が呼ばれてるから | |
445 * そっちを次の Scene にする | |
446 */ | |
447 | |
448 sg_exec_tree = camera->children; | |
449 } | |
450 | |
451 void | |
452 SceneGraphRoot::allRemove(SceneGraphPtr list) | |
453 { | |
454 SceneGraphPtr p = list; | |
455 | |
456 while (p) { | |
457 SceneGraphPtr p1 = p->next; | |
458 delete p; | |
459 p = p1; | |
460 cnt--; | |
461 } | |
462 } | |
463 | |
464 void | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
465 SceneGraphRoot::checkRemove() |
539 | 466 { |
467 SceneGraphPtr p = sg_available_list; | |
468 SceneGraphPtr p1; | |
469 | |
470 while (p) { | |
471 p1 = p->next; | |
472 if (p->isRemoved()) { | |
473 sg_exec_tree = p->realRemoveFromTree(sg_exec_tree); | |
474 sg_available_list = p->realRemoveFromList(sg_available_list); | |
475 } | |
476 delete p; | |
477 p = p1; | |
478 } | |
479 } | |
480 | |
481 SceneGraphPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
482 SceneGraphRoot::getExecuteSceneGraph() |
539 | 483 { |
484 return sg_exec_tree; | |
485 } | |
486 | |
487 SceneGraphPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
488 SceneGraphRoot::getDrawSceneGraph() |
539 | 489 { |
490 return sg_draw_tree; | |
491 } | |
492 | |
493 void | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
494 SceneGraphRoot::updateControllerState() |
539 | 495 { |
496 controller->check(); | |
497 } | |
498 | |
499 void | |
500 SceneGraphRoot::setSceneData(SceneGraphPtr sg) | |
501 { | |
502 sg_exec_tree = sg; | |
503 } | |
504 | |
505 Pad* | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
506 SceneGraphRoot::getController() |
539 | 507 { |
508 return controller; | |
509 } | |
510 | |
511 SceneGraphIteratorPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
512 SceneGraphRoot::getIterator() |
539 | 513 { |
514 iterator->set(sg_remove_list); | |
515 return iterator; | |
516 } | |
517 | |
518 SceneGraphIteratorPtr | |
519 SceneGraphRoot::getIterator(SceneGraphPtr list) | |
520 { | |
521 iterator->set(list); | |
522 return iterator; | |
523 } | |
524 | |
525 CameraPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
526 SceneGraphRoot::getCamera() |
539 | 527 { |
528 return camera; | |
529 } |