29 #include "ascension/context.h" |
29 #include "ascension/context.h" |
30 #include "ascension/scene.h" |
30 #include "ascension/scene.h" |
31 #include "ascension/util.h" |
31 #include "ascension/util.h" |
32 #include "ascension/error.h" |
32 #include "ascension/error.h" |
33 |
33 |
34 #include <cx/hash_map.h> |
34 #include <cx/kv_list.h> |
35 #include <cx/tree.h> |
35 #include <cx/tree.h> |
36 |
36 |
37 #include <assert.h> |
37 #include <assert.h> |
38 |
38 |
39 static void asc_behavior_destroy(void *b) { |
39 static void asc_behavior_destroy(void *b) { |
44 behavior->destroy_func(behavior); |
44 behavior->destroy_func(behavior); |
45 } |
45 } |
46 } |
46 } |
47 |
47 |
48 static CxMap *asc_behavior_new_map(void) { |
48 static CxMap *asc_behavior_new_map(void) { |
49 CxMap *map = cxHashMapCreateSimple(sizeof(AscBehavior)); |
49 CxMap *map = cxKvListCreateAsMapSimple(sizeof(AscBehavior)); |
50 cxDefineDestructor(map, asc_behavior_destroy); |
50 cxDefineDestructor(map, asc_behavior_destroy); |
51 return map; |
51 return map; |
52 } |
52 } |
53 |
53 |
54 AscBehavior *asc_behavior_add_(AscSceneNode *node, struct asc_behavior_create_args args) { |
54 AscBehavior *asc_behavior_add_(AscSceneNode *node, struct asc_behavior_create_args args) { |
56 node->behaviors = asc_behavior_new_map(); |
56 node->behaviors = asc_behavior_new_map(); |
57 } |
57 } |
58 cxmutstr name = args.name == NULL |
58 cxmutstr name = args.name == NULL |
59 ? asc_util_gen_name("behavior") |
59 ? asc_util_gen_name("behavior") |
60 : cx_mutstr(strdup(args.name)); |
60 : cx_mutstr(strdup(args.name)); |
61 // FIXME: we need the ordered map here, because the execution order of behaviors is important |
|
62 AscBehavior *behavior = cxMapEmplace(node->behaviors, name); |
61 AscBehavior *behavior = cxMapEmplace(node->behaviors, name); |
63 assert(behavior != NULL); |
62 assert(behavior != NULL); |
64 behavior->enabled = !args.start_disabled; |
63 behavior->enabled = !args.start_disabled; |
65 behavior->always_enabled = args.always_enabled; |
64 behavior->always_enabled = args.always_enabled; |
66 behavior->killed = false; |
65 behavior->killed = false; |