libanim

diff src/anim.c @ 23:203c11299586

set/get currently active animation name and minor enhancements in the example
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Dec 2013 11:29:42 +0200
parents 9758004136f8
children 09e267e7ed4a
line diff
     1.1 --- a/src/anim.c	Fri Dec 27 10:58:23 2013 +0200
     1.2 +++ b/src/anim.c	Fri Dec 27 11:29:42 2013 +0200
     1.3 @@ -44,6 +44,8 @@
     1.4  	char *newname = malloc(strlen(name) + 1);
     1.5  	if(!newname) return;
     1.6  
     1.7 +	strcpy(newname, name);
     1.8 +
     1.9  	free(anim->name);
    1.10  	anim->name = newname;
    1.11  }
    1.12 @@ -413,6 +415,36 @@
    1.13  	invalidate_cache(node);
    1.14  }
    1.15  
    1.16 +void anm_set_node_active_animation_name(struct anm_node *node, const char *name)
    1.17 +{
    1.18 +	struct anm_animation *anim = anm_get_active_animation(node, 0);
    1.19 +	if(!anim) return;
    1.20 +
    1.21 +	anm_set_animation_name(anim, name);
    1.22 +}
    1.23 +
    1.24 +void anm_set_active_animation_name(struct anm_node *node, const char *name)
    1.25 +{
    1.26 +	struct anm_node *child;
    1.27 +
    1.28 +	anm_set_node_active_animation_name(node, name);
    1.29 +
    1.30 +	child = node->child;
    1.31 +	while(child) {
    1.32 +		anm_set_active_animation_name(child, name);
    1.33 +		child = child->next;
    1.34 +	}
    1.35 +}
    1.36 +
    1.37 +const char *anm_get_active_animation_name(struct anm_node *node)
    1.38 +{
    1.39 +	struct anm_animation *anim = anm_get_active_animation(node, 0);
    1.40 +	if(anim) {
    1.41 +		return anim->name;
    1.42 +	}
    1.43 +	return 0;
    1.44 +}
    1.45 +
    1.46  void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm)
    1.47  {
    1.48  	struct anm_animation *anim = anm_get_active_animation(node, 0);