ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/image.C
(Generate patch)

Comparing deliantra/server/common/image.C (file contents):
Revision 1.16 by root, Thu Feb 15 15:43:36 2007 UTC vs.
Revision 1.17 by root, Thu Feb 15 18:09:33 2007 UTC

24 24
25 25
26#include <global.h> 26#include <global.h>
27#include <stdio.h> 27#include <stdio.h>
28 28
29#include "crc.h"
30
29facetile *new_faces; 31facetile *new_faces;
30 32
31/* bmappair and xbm are used when looking for the image id numbers 33/* bmappair and xbm are used when looking for the image id numbers
32 * of a face by name. xbm is sorted alphabetically so that bsearch 34 * of a face by name. xbm is sorted alphabetically so that bsearch
33 * can be used to quickly find the entry for a name. the number is 35 * can be used to quickly find the entry for a name. the number is
224{ 226{
225 char buf[MAX_BUF], *p, *q; 227 char buf[MAX_BUF], *p, *q;
226 FILE *fp; 228 FILE *fp;
227 int value, nrofbmaps = 0, i; 229 int value, nrofbmaps = 0, i;
228 size_t l; 230 size_t l;
231 crc32 crc;
229 232
230 bmaps_checksum = 0;
231 sprintf (buf, "%s/bmaps", settings.datadir); 233 sprintf (buf, "%s/bmaps", settings.datadir);
232 LOG (llevDebug, "Reading bmaps from %s...\n", buf); 234 LOG (llevDebug, "Reading bmaps from %s...\n", buf);
233 if ((fp = fopen (buf, "r")) == NULL) 235 if ((fp = fopen (buf, "r")) == NULL)
234 { 236 {
235 LOG (llevError, "Cannot open bmaps file %s: %s\n", buf, strerror (errno)); 237 LOG (llevError, "Cannot open bmaps file %s: %s\n", buf, strerror (errno));
254 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n"))) 256 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n")))
255 { 257 {
256 LOG (llevDebug, "Warning, syntax error: %s\n", buf); 258 LOG (llevDebug, "Warning, syntax error: %s\n", buf);
257 continue; 259 continue;
258 } 260 }
261
259 value = atoi (p); 262 value = atoi (p);
260 xbm[nroffiles].name = strdup (q); 263 xbm[nroffiles].name = strdup (q);
261 264
262 /* We need to calculate the checksum of the bmaps file 265 /* We need to calculate the checksum of the bmaps file
263 * name->number mapping to send to the client. This does not 266 * name->number mapping to send to the client. This does not
264 * need to match what sum or other utility may come up with - 267 * need to match what sum or other utility may come up with -
265 * as long as we get the same results on the same real file 268 * as long as we get the same results on the same real file
266 * data, it does the job as it lets the client know if 269 * data, it does the job as it lets the client know if
267 * the file has the same data or not. 270 * the file has the same data or not.
268 */ 271 */
269 rotate_right (bmaps_checksum); 272 crc (value);
270 bmaps_checksum += value & 0xff; 273 crc (value >> 8);
271 bmaps_checksum &= 0xffffffff;
272 274
273 rotate_right (bmaps_checksum);
274 bmaps_checksum += (value >> 8) & 0xff;
275 bmaps_checksum &= 0xffffffff;
276 for (l = 0; l < strlen (q); l++) 275 for (l = 0; l < strlen (q); l++)
277 { 276 crc (q [l]);
278 rotate_right (bmaps_checksum);
279 bmaps_checksum += q[l];
280 bmaps_checksum &= 0xffffffff;
281 }
282 277
283 xbm[nroffiles].number = value; 278 xbm[nroffiles].number = value;
284 nroffiles++; 279 nroffiles++;
285 if (value >= nrofpixmaps) 280 if (value >= nrofpixmaps)
286 nrofpixmaps = value + 1; 281 nrofpixmaps = value + 1;
287 } 282 }
283
288 fclose (fp); 284 fclose (fp);
289 285
290 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); 286 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles);
291 287
292 new_faces = new facetile[nrofpixmaps]; 288 new_faces = new facetile[nrofpixmaps];
328 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)]; 324 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)];
329 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)]; 325 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)];
330 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)]; 326 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)];
331 327
332 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)]; 328 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)];
329
330 bmaps_checksum = crc;
333} 331}
334 332
335/* This returns an the face number of face 'name'. Number is constant 333/* This returns an the face number of face 'name'. Number is constant
336 * during an invocation, but not necessarily between versions (this 334 * during an invocation, but not necessarily between versions (this
337 * is because the faces are arranged in alphabetical order, so 335 * is because the faces are arranged in alphabetical order, so
375{ 373{
376 char buf[MAX_BUF], *p, *q; 374 char buf[MAX_BUF], *p, *q;
377 FILE *fp; 375 FILE *fp;
378 int smoothcount = 0; 376 int smoothcount = 0;
379 377
380 bmaps_checksum = 0;
381 sprintf (buf, "%s/smooth", settings.datadir); 378 sprintf (buf, "%s/smooth", settings.datadir);
382 LOG (llevDebug, "Reading smooth from %s...\n", buf); 379 LOG (llevDebug, "Reading smooth from %s...\n", buf);
383 if ((fp = fopen (buf, "r")) == NULL) 380 if ((fp = fopen (buf, "r")) == NULL)
384 { 381 {
385 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); 382 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines