--- deliantra/server/common/image.C 2006/09/10 16:00:23 1.6 +++ deliantra/server/common/image.C 2007/02/15 18:09:33 1.17 @@ -1,37 +1,34 @@ - /* - * static char *rcsid_image_c = - * "$Id: image.C,v 1.6 2006/09/10 16:00:23 root Exp $"; + * CrossFire, A Multiplayer game + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2002 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The maintainer of this code can be reached at */ -/* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The maintainer of this code can be reached at crossfire-devel@real-time.com -*/ - #include #include -New_Face *new_faces; +#include "crc.h" + +facetile *new_faces; /* bmappair and xbm are used when looking for the image id numbers * of a face by name. xbm is sorted alphabetically so that bsearch @@ -51,15 +48,9 @@ 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 - * it is easier to keep them like this. - */ -New_Face *blank_face, *dark_faces[3], *empty_face, *smooth_face; - +facetile *blank_face, *dark_faces[3], *empty_face, *smooth_face; /* nroffiles is the actual number of bitmaps defined. * nrofpixmaps is the number of bitmaps loaded. With @@ -77,14 +68,12 @@ /** * id is the face to smooth, smooth is the 16x2 face used to smooth id. */ -struct smoothing:zero_initialised +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. @@ -119,6 +108,7 @@ { return strcmp (a->name, b->name); } + static int compar_smooth (const struct smoothing *a, const struct smoothing *b) { @@ -129,13 +119,11 @@ return 0; } - /* * Returns the matching color in the coloralias if found, * 0 otherwise. Note that 0 will actually be black, so there is no * way the calling function can tell if an error occurred or not */ - static uint8 find_color (const char *name) { @@ -151,16 +139,15 @@ /* This reads the lib/faces file, getting color and visibility information. * it is called by ReadBmapNames. */ - static void ReadFaceData (void) { char buf[MAX_BUF], *cp; - New_Face *on_face = NULL; + facetile *on_face = NULL; FILE *fp; sprintf (buf, "%s/faces", settings.datadir); - LOG (llevDebug, "Reading faces from %s...", buf); + LOG (llevDebug, "Reading faces from %s...\n", buf); if ((fp = fopen (buf, "r")) == NULL) { LOG (llevError, "Cannot open faces file %s: %s\n", buf, strerror (errno)); @@ -224,6 +211,7 @@ else LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); } + LOG (llevDebug, "done\n"); fclose (fp); } @@ -233,7 +221,6 @@ * independent (ie, what display the person is on will not make a * difference.) */ - void ReadBmapNames (void) { @@ -241,10 +228,10 @@ FILE *fp; int value, nrofbmaps = 0, i; size_t l; + crc32 crc; - bmaps_checksum = 0; sprintf (buf, "%s/bmaps", settings.datadir); - LOG (llevDebug, "Reading bmaps from %s...", buf); + LOG (llevDebug, "Reading bmaps from %s...\n", buf); if ((fp = fopen (buf, "r")) == NULL) { LOG (llevError, "Cannot open bmaps file %s: %s\n", buf, strerror (errno)); @@ -271,8 +258,9 @@ LOG (llevDebug, "Warning, syntax error: %s\n", buf); continue; } + value = atoi (p); - xbm[nroffiles].name = strdup_local (q); + xbm[nroffiles].name = strdup (q); /* We need to calculate the checksum of the bmaps file * name->number mapping to send to the client. This does not @@ -281,30 +269,23 @@ * data, it does the job as it lets the client know if * the file has the same data or not. */ - ROTATE_RIGHT (bmaps_checksum); - bmaps_checksum += value & 0xff; - bmaps_checksum &= 0xffffffff; - - ROTATE_RIGHT (bmaps_checksum); - bmaps_checksum += (value >> 8) & 0xff; - bmaps_checksum &= 0xffffffff; + crc (value); + crc (value >> 8); + for (l = 0; l < strlen (q); l++) - { - ROTATE_RIGHT (bmaps_checksum); - bmaps_checksum += q[l]; - bmaps_checksum &= 0xffffffff; - } + crc (q [l]); xbm[nroffiles].number = value; nroffiles++; if (value >= nrofpixmaps) nrofpixmaps = value + 1; } + fclose (fp); LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); - new_faces = new New_Face[nrofpixmaps]; + new_faces = new facetile[nrofpixmaps]; for (i = 0; i < nrofpixmaps; i++) { @@ -313,10 +294,9 @@ new_faces[i].visibility = 0; new_faces[i].magicmap = 255; } + for (i = 0; i < nroffiles; i++) - { - new_faces[xbm[i].number].name = xbm[i].name; - } + 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); @@ -346,6 +326,8 @@ dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)]; smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)]; + + bmaps_checksum = crc; } /* This returns an the face number of face 'name'. Number is constant @@ -393,9 +375,8 @@ FILE *fp; int smoothcount = 0; - bmaps_checksum = 0; sprintf (buf, "%s/smooth", settings.datadir); - LOG (llevDebug, "Reading smooth from %s...", buf); + 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));