src/behavior.c

changeset 176
cb2f60f48337
parent 162
d3598c834f9b
equal deleted inserted replaced
175:e5544920377e 176:cb2f60f48337
53 node->behaviors = asc_behavior_new_list(); 53 node->behaviors = asc_behavior_new_list();
54 } 54 }
55 AscBehavior *behavior = cxListEmplace(node->behaviors); 55 AscBehavior *behavior = cxListEmplace(node->behaviors);
56 assert(behavior != NULL); 56 assert(behavior != NULL);
57 behavior->enabled = true; 57 behavior->enabled = true;
58 behavior->killed = false;
58 behavior->node = node; 59 behavior->node = node;
59 behavior->func = args.func; 60 behavior->func = args.func;
60 behavior->destroy_func = args.destroy_func; 61 behavior->destroy_func = args.destroy_func;
61 behavior->data = args.data; 62 behavior->data = args.data;
62 behavior->interval = args.interval; 63 behavior->interval = args.interval;
63 behavior->last_execution = 0; 64 behavior->last_execution = 0;
64 return behavior; 65 return behavior;
65 } 66 }
66 67
68 void asc_behavior_remove(AscBehavior *behavior) {
69 // TODO: implement some sort of ID for behaviors which can also be used for logging
70 behavior->killed = true;
71 behavior->enabled = false;
72 }
73
67 void asc_behavior_trigger(AscBehavior *behavior) { 74 void asc_behavior_trigger(AscBehavior *behavior) {
68 if (!behavior->enabled) return; 75 assert(behavior->enabled);
69 if (behavior->last_execution + behavior->interval > asc_context.total_nanos) return; 76 if (behavior->last_execution + behavior->interval > asc_context.total_nanos) return;
70 77
71 behavior->func(behavior); 78 behavior->func(behavior);
72 behavior->last_execution = asc_context.total_nanos; 79 behavior->last_execution = asc_context.total_nanos;
73 } 80 }

mercurial