61 AscBehavior *behavior = cxMapEmplace(node->behaviors, name); |
61 AscBehavior *behavior = cxMapEmplace(node->behaviors, name); |
62 assert(behavior != NULL); |
62 assert(behavior != NULL); |
63 behavior->enabled = !args.start_disabled; |
63 behavior->enabled = !args.start_disabled; |
64 behavior->always_enabled = args.always_enabled; |
64 behavior->always_enabled = args.always_enabled; |
65 behavior->killed = false; |
65 behavior->killed = false; |
|
66 behavior->unpaused = false; |
66 behavior->node = node; |
67 behavior->node = node; |
67 behavior->func = args.func; |
68 behavior->func = args.func; |
68 behavior->destroy_func = args.destroy_func; |
69 behavior->destroy_func = args.destroy_func; |
69 behavior->data = args.data; |
70 behavior->data = args.data; |
70 behavior->interval = args.interval; |
71 behavior->interval = args.interval; |
80 behavior->killed = true; |
81 behavior->killed = true; |
81 behavior->enabled = false; |
82 behavior->enabled = false; |
82 } |
83 } |
83 |
84 |
84 void asc_behavior_trigger(AscBehavior *behavior) { |
85 void asc_behavior_trigger(AscBehavior *behavior) { |
85 if (!behavior->enabled) return; |
86 // the behavior is not enabled at the moment |
86 if (behavior->last_execution + behavior->interval > asc_context.total_nanos) return; |
87 if (!behavior->enabled) { |
87 if (!behavior->always_enabled && behavior->pause_while_hidden && asc_scene_node_is_hidden(behavior->node)) return; |
88 behavior->unpaused = true; |
|
89 return; |
|
90 } |
|
91 // the behavior is not scheduled for execution |
|
92 if (behavior->last_execution + behavior->interval > asc_context.total_nanos) { |
|
93 return; |
|
94 } |
|
95 // the behavior is paused while the node is hidden |
|
96 if (!behavior->always_enabled && behavior->pause_while_hidden && asc_scene_node_is_hidden(behavior->node)) { |
|
97 behavior->unpaused = true; |
|
98 return; |
|
99 } |
88 |
100 |
89 behavior->func(behavior); |
101 behavior->func(behavior); |
|
102 behavior->unpaused = false; |
90 behavior->last_execution = asc_context.total_nanos; |
103 behavior->last_execution = asc_context.total_nanos; |
91 } |
104 } |
92 |
105 |
93 cxstring asc_behavior_get_name(const AscBehavior *behavior) { |
106 cxstring asc_behavior_get_name(const AscBehavior *behavior) { |
94 assert(behavior != NULL); |
107 assert(behavior != NULL); |