--- deliantra/server/common/anim.C 2006/08/30 16:30:36 1.3 +++ deliantra/server/common/anim.C 2006/09/03 07:57:54 1.5 @@ -1,6 +1,6 @@ /* * static char *rcsid_anim_c = - * "$Id: anim.C,v 1.3 2006/08/30 16:30:36 root Exp $"; + * "$Id: anim.C,v 1.5 2006/09/03 07:57:54 root Exp $"; */ /* @@ -31,14 +31,17 @@ #include #include -void free_all_anim(void) { - int i; +std::vector animations; - for (i=0; i<=num_animations; i++) { - free_string(animations[i].name); - free(animations[i].faces); +void free_all_anim(void) +{ + for (int i=0; i<=num_animations; i++) + { + animations[i].name = 0; + free (animations[i].faces); } - free(animations); + + animations.clear (); } void init_anim(void) { @@ -48,18 +51,16 @@ int num_frames=0,faces[MAX_ANIMATIONS],i; if (anim_init) return; - animations_allocated=9; num_animations=0; /* Make a default. New animations start at one, so if something * thinks it is animated but hasn't set the animation_id properly, * it will have a default value that should be pretty obvious. */ - animations = (Animations *) malloc(10*sizeof(Animations)); /* set the name so we don't try to dereferance null. * Put # at start so it will be first in alphabetical * order. */ - animations[0].name=add_string("###none"); + animations[0].name = "###none"; animations[0].num_animations=1; animations[0].faces = (Fontindex *) malloc(sizeof(Fontindex)); animations[0].faces[0]=0; @@ -81,13 +82,11 @@ num_frames=0; } num_animations++; - if (num_animations==animations_allocated) { - animations= (Animations *) realloc(animations, sizeof(Animations)*(animations_allocated+10)); - animations_allocated+=10; - } - animations[num_animations].name = add_string(buf+5); - animations[num_animations].num = num_animations; /* for bsearch */ - animations[num_animations].facings = 1; + + Animations &anim = animations.at (num_animations); + anim.name = buf + 5; + anim.num = num_animations; /* for bsearch */ + anim.facings = 1; } else if (!strncmp(buf,"mina",4)) { animations[num_animations].faces = (Fontindex *) malloc(sizeof(Fontindex)*num_frames); @@ -96,21 +95,21 @@ animations[num_animations].num_animations = num_frames; if (num_frames % animations[num_animations].facings) { LOG(llevDebug,"Animation %s frame numbers (%d) is not a multiple of facings (%d)\n", - animations[num_animations].name, num_frames, animations[num_animations].facings); + &animations[num_animations].name, num_frames, animations[num_animations].facings); } num_frames=0; } else if (!strncmp(buf,"facings",7)) { if (!(animations[num_animations].facings = atoi(buf+7))) { LOG(llevDebug,"Animation %s has 0 facings, line=%s\n", - animations[num_animations].name, buf); + &animations[num_animations].name, buf); animations[num_animations].facings=1; } } else { if (!(faces[num_frames++] = FindFace(buf,0))) LOG(llevDebug,"Could not find face %s for animation %s\n", - buf, animations[num_animations].name); + buf, &animations[num_animations].name); } } fclose(fp); @@ -130,7 +129,7 @@ search.name = name; - match = (Animations*)bsearch(&search, animations, (num_animations+1), + match = (Animations*)bsearch(&search, &animations [0], (num_animations+1), sizeof(Animations), (int (*)(const void*, const void*))anim_compare);