src/behavior.c

changeset 148
9f030f402699
parent 114
5b91bbab1ac0
equal deleted inserted replaced
147:4908cc6c2e01 148:9f030f402699
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
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/error.h" 30 #include "ascension/error.h"
30 #include "ascension/scene.h" 31 #include "ascension/scene.h"
31 32
32 #include <cx/array_list.h> 33 #include <cx/array_list.h>
33 #include <cx/tree.h> 34 #include <cx/tree.h>
59 behavior->enabled = true; 60 behavior->enabled = true;
60 behavior->node = node; 61 behavior->node = node;
61 behavior->func = args.func; 62 behavior->func = args.func;
62 behavior->destroy_func = args.destroy_func; 63 behavior->destroy_func = args.destroy_func;
63 behavior->data = args.data; 64 behavior->data = args.data;
65 behavior->interval = args.interval;
66 behavior->last_execution = 0;
64 return behavior; 67 return behavior;
65 } 68 }
69
70 void asc_behavior_trigger(AscBehavior *behavior) {
71 if (!behavior->enabled) return;
72 if (behavior->last_execution + behavior->interval > asc_context.total_nanos) return;
73
74 behavior->func(behavior);
75 behavior->last_execution = asc_context.total_nanos;
76 }

mercurial