src/behavior.c

changeset 162
d3598c834f9b
parent 148
9f030f402699
equal deleted inserted replaced
161:4c8b9c6d241f 162:d3598c834f9b
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "ascension/behavior.h" 28 #include "ascension/behavior.h"
29 #include "ascension/context.h" 29 #include "ascension/context.h"
30 #include "ascension/error.h"
31 #include "ascension/scene.h" 30 #include "ascension/scene.h"
32 31
33 #include <cx/array_list.h> 32 #include <cx/array_list.h>
34 #include <cx/tree.h> 33 #include <cx/tree.h>
34
35 #include <assert.h>
35 36
36 static void asc_behavior_destroy(void *b) { 37 static void asc_behavior_destroy(void *b) {
37 AscBehavior *behavior = b; 38 AscBehavior *behavior = b;
38 if (behavior->destroy_func) { 39 if (behavior->destroy_func) {
39 behavior->destroy_func(behavior); 40 behavior->destroy_func(behavior);
50 AscBehavior *asc_behavior_add_(AscSceneNode *node, struct asc_behavior_create_args args) { 51 AscBehavior *asc_behavior_add_(AscSceneNode *node, struct asc_behavior_create_args args) {
51 if (node->behaviors == NULL) { 52 if (node->behaviors == NULL) {
52 node->behaviors = asc_behavior_new_list(); 53 node->behaviors = asc_behavior_new_list();
53 } 54 }
54 AscBehavior *behavior = cxListEmplace(node->behaviors); 55 AscBehavior *behavior = cxListEmplace(node->behaviors);
55 if (behavior == NULL) { 56 assert(behavior != NULL);
56 const cxstring node_name = asc_scene_node_get_name(node);
57 asc_error("Failed to add behavior to scene node %"CX_PRIstr, CX_SFMT(node_name));
58 return NULL;
59 }
60 behavior->enabled = true; 57 behavior->enabled = true;
61 behavior->node = node; 58 behavior->node = node;
62 behavior->func = args.func; 59 behavior->func = args.func;
63 behavior->destroy_func = args.destroy_func; 60 behavior->destroy_func = args.destroy_func;
64 behavior->data = args.data; 61 behavior->data = args.data;

mercurial