--- deliantra/server/common/image.C 2006/08/30 16:30:36 1.3 +++ deliantra/server/common/image.C 2006/09/04 11:07:59 1.4 @@ -1,6 +1,6 @@ /* * static char *rcsid_image_c = - * "$Id: image.C,v 1.3 2006/08/30 16:30:36 root Exp $"; + * "$Id: image.C,v 1.4 2006/09/04 11:07:59 root Exp $"; */ /* @@ -44,11 +44,14 @@ * the bmaps file is created in a sorted order. */ -struct bmappair { - char *name; - unsigned int number; +struct bmappair +{ + char *name; + unsigned int number; }; +void free (bmappair *); // guard to catch free when delete should be used + static struct bmappair *xbm=NULL; /* Following can just as easily be pointers, but @@ -73,11 +76,14 @@ /** * id is the face to smooth, smooth is the 16x2 face used to smooth id. */ -struct smoothing { +struct smoothing : zero_initialised +{ uint16 id; uint16 smooth; }; +void free (smoothing *); // guard to catch free when delete should be used + /** * Contains all defined smoothing entries. smooth is an array of nrofsmooth * entries. It is sorted by smooth[].id. @@ -156,16 +162,16 @@ on_face = NULL; } else if (!strncmp(buf,"face",4)) { - int tmp; + int tmp; - cp = buf + 5; - cp[strlen(cp)-1] = '\0'; /* remove newline */ + cp = buf + 5; + cp[strlen(cp)-1] = '\0'; /* remove newline */ - if ((tmp=FindFace(cp,-1))==-1) { - LOG(llevError,"Could not find face %s\n", cp); - continue; - } - on_face = &new_faces[tmp]; + if ((tmp=FindFace(cp,-1))==-1) { + LOG(llevError,"Could not find face %s\n", cp); + continue; + } + on_face = &new_faces[tmp]; on_face->visibility=0; } else if (on_face==NULL) { @@ -223,7 +229,7 @@ nrofbmaps++; rewind(fp); - xbm = (struct bmappair *) malloc(sizeof(struct bmappair) * nrofbmaps); + xbm = new bmappair [nrofbmaps]; memset (xbm, 0, sizeof (struct bmappair) * nrofbmaps); while(nroffiles < nrofbmaps && fgets (buf, MAX_BUF, fp) != NULL) { @@ -267,7 +273,7 @@ LOG(llevDebug,"done (got %d/%d/%d)\n",nrofpixmaps,nrofbmaps,nroffiles); - new_faces = (New_Face *)malloc(sizeof(New_Face) * nrofpixmaps); + new_faces = new New_Face [nrofpixmaps]; for (i = 0; i < nrofpixmaps; i++) { new_faces[i].name = ""; new_faces[i].number = i; @@ -278,6 +284,7 @@ new_faces[xbm[i].number].name = xbm[i].name; } + // non-pod datatype, likely not allowed qsort (xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar); ReadFaceData(); @@ -359,8 +366,7 @@ smoothcount++; rewind(fp); - smooth = (struct smoothing *) malloc(sizeof(struct smoothing) * (smoothcount)); - memset (smooth, 0, sizeof (struct smoothing) * (smoothcount)); + smooth = new smoothing [smoothcount]; while(nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp)!=NULL) { if (*buf == '#') @@ -412,7 +418,8 @@ for (i=0; i