--- deliantra/server/common/image.C 2007/03/11 02:12:44 1.19 +++ deliantra/server/common/image.C 2007/04/12 14:18:04 1.23 @@ -22,7 +22,6 @@ * The maintainer of this code can be reached at */ - #include #include @@ -33,23 +32,6 @@ facehash_t facehash; std::vector faces; -std::vector face32, face64; - -/** - * id is the face to smooth, smooth is the 16x2 face used to smooth id. - */ -struct smoothing : zero_initialised -{ - uint16 id; - uint16 smooth; -}; - -/** - * Contains all defined smoothing entries. smooth is an array of nrofsmooth - * entries. It is sorted by smooth[].id. - */ -static struct smoothing *smooth = NULL; -int nrofsmooth = 0; /* the only thing this table is used for now is to * translate the colorname in the magicmap field of the @@ -73,16 +55,6 @@ "khaki" /* 12 */ }; -static int -compar_smooth (const struct smoothing *a, const struct smoothing *b) -{ - if (a->id < b->id) - return -1; - if (b->id < a->id) - return 1; - return 0; -} - /* * Returns the matching color in the coloralias if found, * 0 otherwise. Note that 0 will actually be black, so there is no @@ -101,92 +73,35 @@ return 0; } -int -face_find (const char *name, int defidx) +faceidx +face_find (const char *name, faceidx defidx) { + if (!name) + return defidx; + facehash_t::iterator i = facehash.find (name); return i == facehash.end () ? defidx : i->second; } -facedata * -face_data (int idx, int faceset) +faceinfo * +face_info (faceidx idx) { - return &(faceset ? face64 : face32)[idx]; -} + assert (0 < (faceidx)-1); // faceidx must be unsigned -/* Reads the smooth file to know how to smooth datas. - * the smooth file if made of 2 elements lines. - * lines starting with # are comment - * the first element of line is face to smooth - * the next element is the 16x2 faces picture - * used for smoothing - */ -int -ReadSmooth (void) -{ - char buf[MAX_BUF], *p, *q; - FILE *fp; - int smoothcount = 0; - - sprintf (buf, "%s/smooth", settings.datadir); - LOG (llevDebug, "Reading smooth from %s...\n", buf); - if ((fp = fopen (buf, "r")) == NULL) - { - LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); - exit (-1); - } - - /* First count how many smooth we have, so we can allocate correctly */ - while (fgets (buf, MAX_BUF, fp) != NULL) - if (buf[0] != '#' && buf[0] != '\n') - smoothcount++; - rewind (fp); - - smooth = new smoothing[smoothcount]; - - while (nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp) != NULL) - { - if (*buf == '#') - continue; - p = strchr (buf, ' '); - if (!p) - continue; - *p = '\0'; - q = buf; - smooth[nrofsmooth].id = face_find (q); - q = p + 1; - smooth[nrofsmooth].smooth = face_find (q); - nrofsmooth++; - } - fclose (fp); - - LOG (llevDebug, "done (got %d smooth entries)\n", nrofsmooth); - qsort (smooth, nrofsmooth, sizeof (struct smoothing), (int (*)(const void *, const void *)) compar_smooth); - return nrofsmooth; + if (idx >= faces.size ()) + return 0; + + return &faces [idx]; } -/** - * Find the smooth face for a given face. - * - * @param face the face to find the smoothing face for - * - * @param smoothed return value: set to smooth face - * - * @return 1=smooth face found, 0=no smooth face found - */ -int -FindSmooth (uint16 face, uint16 * smoothed) +facedata * +face_data (faceidx idx, int faceset) { - struct smoothing *bp, tmp; + if (faceinfo *f = face_info (idx)) + return &(faceset ? f->data32 : f->data64); - tmp.id = face; - bp = (struct smoothing *) bsearch - (&tmp, smooth, nrofsmooth, sizeof (struct smoothing), (int (*)(const void *, const void *)) compar_smooth); - (*smoothed) = 0; - if (bp) - (*smoothed) = bp->smooth; - return bp ? 1 : 0; + return 0; }