--- deliantra/server/common/anim.C 2006/08/30 16:30:36 1.3 +++ deliantra/server/common/anim.C 2006/09/03 08:05:39 1.6 @@ -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.6 2006/09/03 08:05:39 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,22 +51,26 @@ 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].num_animations=1; - animations[0].faces = (Fontindex *) malloc(sizeof(Fontindex)); - animations[0].faces[0]=0; - animations[0].facings=0; + { + Animations anim0; + + anim0.name = "###none"; + anim0.num_animations=1; + anim0.faces = (Fontindex *) malloc(sizeof(Fontindex)); + anim0.faces[0]=0; + anim0.facings=0; + + animations.push_back (anim0); + } sprintf(buf,"%s/animations", settings.datadir); LOG(llevDebug,"Reading animations from %s...", buf); @@ -81,13 +88,12 @@ 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; + anim.name = buf + 5; + anim.num = num_animations; /* for bsearch */ + anim.facings = 1; + animations.push_back (anim); } else if (!strncmp(buf,"mina",4)) { animations[num_animations].faces = (Fontindex *) malloc(sizeof(Fontindex)*num_frames); @@ -96,21 +102,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 +136,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);