50 asc_scene_node_free(scene->root); |
50 asc_scene_node_free(scene->root); |
51 } |
51 } |
52 |
52 |
53 void asc_scene_add(AscScene *scene, AscSceneNode *node) { |
53 void asc_scene_add(AscScene *scene, AscSceneNode *node) { |
54 asc_scene_node_link(scene->root, node); |
54 asc_scene_node_link(scene->root, node); |
|
55 asc_node_update(node); |
55 } |
56 } |
56 |
57 |
57 void asc_scene_draw(AscScene const *scene) { |
58 void asc_scene_draw(AscScene const *scene) { |
58 // TODO: don't visit the tree, visit the render groups |
|
59 CxTreeIterator iter = cx_tree_iterator(scene->root, false, child_list_off_); |
59 CxTreeIterator iter = cx_tree_iterator(scene->root, false, child_list_off_); |
|
60 |
|
61 // skip the root node deliberately, we know it's just the container |
|
62 cxIteratorNext(iter); |
|
63 |
|
64 // draw the children |
60 cx_foreach(AscSceneNode*, node, iter) { |
65 cx_foreach(AscSceneNode*, node, iter) { |
|
66 if (node->need_update && node->update_func != NULL) { |
|
67 node->need_update = false; |
|
68 asc_transform_copy(node->transform, node->parent->transform); |
|
69 node->update_func(node); |
|
70 } |
|
71 // TODO: don't visit the tree for drawing, visit the render groups |
61 if (node->draw_func != NULL) { |
72 if (node->draw_func != NULL) { |
62 node->draw_func(node); |
73 node->draw_func(node); |
63 } |
74 } |
64 } |
75 } |
65 } |
76 } |
66 |
77 |
67 AscSceneNode *asc_scene_node_empty(void) { |
78 AscSceneNode *asc_scene_node_empty(void) { |
68 // TODO: check if this can remain a calloc or if it's too expensive |
|
69 AscSceneNode *node = calloc(1, sizeof(AscSceneNode)); |
79 AscSceneNode *node = calloc(1, sizeof(AscSceneNode)); |
70 assert(node != NULL); |
80 assert(node != NULL); |
71 node->free_func = (asc_scene_free_func) free; |
81 node->free_func = (asc_scene_free_func) free; |
|
82 asc_transform_identity(node->transform); |
72 return node; |
83 return node; |
73 } |
84 } |
74 |
85 |
75 void asc_scene_node_free(AscSceneNode *node) { |
86 void asc_scene_node_free(AscSceneNode *node) { |
76 if (node == NULL) return; |
87 if (node == NULL) return; |