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.12 by pippijn, Mon Jan 15 21:06:18 2007 UTC vs.
Revision 1.17 by root, Thu Feb 15 18:09:33 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
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
29New_Face *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
34 * then an index into the new_faces array. 36 * then an index into the new_faces array.
44{ 46{
45 char *name; 47 char *name;
46 unsigned int number; 48 unsigned int number;
47}; 49};
48 50
49void free (bmappair *); // guard to catch free when delete should be used
50
51static struct bmappair *xbm = NULL; 51static struct bmappair *xbm = NULL;
52 52
53/* Following can just as easily be pointers, but
54 * it is easier to keep them like this.
55 */
56New_Face *blank_face, *dark_faces[3], *empty_face, *smooth_face; 53facetile *blank_face, *dark_faces[3], *empty_face, *smooth_face;
57
58 54
59/* nroffiles is the actual number of bitmaps defined. 55/* nroffiles is the actual number of bitmaps defined.
60 * nrofpixmaps is the number of bitmaps loaded. With 56 * nrofpixmaps is the number of bitmaps loaded. With
61 * the automatic generation of the bmaps file, this is now equal 57 * the automatic generation of the bmaps file, this is now equal
62 * to nroffiles. 58 * to nroffiles.
70int nrofpixmaps = 0; 66int nrofpixmaps = 0;
71 67
72/** 68/**
73 * id is the face to smooth, smooth is the 16x2 face used to smooth id. 69 * id is the face to smooth, smooth is the 16x2 face used to smooth id.
74 */ 70 */
75struct smoothing:zero_initialised 71struct smoothing : zero_initialised
76{ 72{
77 uint16 id; 73 uint16 id;
78 uint16 smooth; 74 uint16 smooth;
79}; 75};
80
81void free (smoothing *); // guard to catch free when delete should be used
82 76
83/** 77/**
84 * Contains all defined smoothing entries. smooth is an array of nrofsmooth 78 * Contains all defined smoothing entries. smooth is an array of nrofsmooth
85 * entries. It is sorted by smooth[].id. 79 * entries. It is sorted by smooth[].id.
86 */ 80 */
147 */ 141 */
148static void 142static void
149ReadFaceData (void) 143ReadFaceData (void)
150{ 144{
151 char buf[MAX_BUF], *cp; 145 char buf[MAX_BUF], *cp;
152 New_Face *on_face = NULL; 146 facetile *on_face = NULL;
153 FILE *fp; 147 FILE *fp;
154 148
155 sprintf (buf, "%s/faces", settings.datadir); 149 sprintf (buf, "%s/faces", settings.datadir);
156 LOG (llevDebug, "Reading faces from %s...\n", buf); 150 LOG (llevDebug, "Reading faces from %s...\n", buf);
157 if ((fp = fopen (buf, "r")) == NULL) 151 if ((fp = fopen (buf, "r")) == NULL)
232{ 226{
233 char buf[MAX_BUF], *p, *q; 227 char buf[MAX_BUF], *p, *q;
234 FILE *fp; 228 FILE *fp;
235 int value, nrofbmaps = 0, i; 229 int value, nrofbmaps = 0, i;
236 size_t l; 230 size_t l;
231 crc32 crc;
237 232
238 bmaps_checksum = 0;
239 sprintf (buf, "%s/bmaps", settings.datadir); 233 sprintf (buf, "%s/bmaps", settings.datadir);
240 LOG (llevDebug, "Reading bmaps from %s...\n", buf); 234 LOG (llevDebug, "Reading bmaps from %s...\n", buf);
241 if ((fp = fopen (buf, "r")) == NULL) 235 if ((fp = fopen (buf, "r")) == NULL)
242 { 236 {
243 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));
262 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n"))) 256 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n")))
263 { 257 {
264 LOG (llevDebug, "Warning, syntax error: %s\n", buf); 258 LOG (llevDebug, "Warning, syntax error: %s\n", buf);
265 continue; 259 continue;
266 } 260 }
261
267 value = atoi (p); 262 value = atoi (p);
268 xbm[nroffiles].name = strdup (q); 263 xbm[nroffiles].name = strdup (q);
269 264
270 /* We need to calculate the checksum of the bmaps file 265 /* We need to calculate the checksum of the bmaps file
271 * name->number mapping to send to the client. This does not 266 * name->number mapping to send to the client. This does not
272 * 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 -
273 * 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
274 * 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
275 * the file has the same data or not. 270 * the file has the same data or not.
276 */ 271 */
277 ROTATE_RIGHT (bmaps_checksum); 272 crc (value);
278 bmaps_checksum += value & 0xff; 273 crc (value >> 8);
279 bmaps_checksum &= 0xffffffff;
280 274
281 ROTATE_RIGHT (bmaps_checksum);
282 bmaps_checksum += (value >> 8) & 0xff;
283 bmaps_checksum &= 0xffffffff;
284 for (l = 0; l < strlen (q); l++) 275 for (l = 0; l < strlen (q); l++)
285 { 276 crc (q [l]);
286 ROTATE_RIGHT (bmaps_checksum);
287 bmaps_checksum += q[l];
288 bmaps_checksum &= 0xffffffff;
289 }
290 277
291 xbm[nroffiles].number = value; 278 xbm[nroffiles].number = value;
292 nroffiles++; 279 nroffiles++;
293 if (value >= nrofpixmaps) 280 if (value >= nrofpixmaps)
294 nrofpixmaps = value + 1; 281 nrofpixmaps = value + 1;
295 } 282 }
283
296 fclose (fp); 284 fclose (fp);
297 285
298 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); 286 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles);
299 287
300 new_faces = new New_Face[nrofpixmaps]; 288 new_faces = new facetile[nrofpixmaps];
301 289
302 for (i = 0; i < nrofpixmaps; i++) 290 for (i = 0; i < nrofpixmaps; i++)
303 { 291 {
304 new_faces[i].name = ""; 292 new_faces[i].name = "";
305 new_faces[i].number = i; 293 new_faces[i].number = i;
306 new_faces[i].visibility = 0; 294 new_faces[i].visibility = 0;
307 new_faces[i].magicmap = 255; 295 new_faces[i].magicmap = 255;
308 } 296 }
297
309 for (i = 0; i < nroffiles; i++) 298 for (i = 0; i < nroffiles; i++)
310 {
311 new_faces[xbm[i].number].name = xbm[i].name; 299 new_faces[xbm[i].number].name = xbm[i].name;
312 }
313 300
314 // non-pod datatype, likely not allowed 301 // non-pod datatype, likely not allowed
315 qsort (xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar); 302 qsort (xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar);
316 303
317 ReadFaceData (); 304 ReadFaceData ();
337 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)]; 324 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)];
338 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)]; 325 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)];
339 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)]; 326 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)];
340 327
341 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)]; 328 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)];
329
330 bmaps_checksum = crc;
342} 331}
343 332
344/* 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
345 * during an invocation, but not necessarily between versions (this 334 * during an invocation, but not necessarily between versions (this
346 * is because the faces are arranged in alphabetical order, so 335 * is because the faces are arranged in alphabetical order, so
384{ 373{
385 char buf[MAX_BUF], *p, *q; 374 char buf[MAX_BUF], *p, *q;
386 FILE *fp; 375 FILE *fp;
387 int smoothcount = 0; 376 int smoothcount = 0;
388 377
389 bmaps_checksum = 0;
390 sprintf (buf, "%s/smooth", settings.datadir); 378 sprintf (buf, "%s/smooth", settings.datadir);
391 LOG (llevDebug, "Reading smooth from %s...\n", buf); 379 LOG (llevDebug, "Reading smooth from %s...\n", buf);
392 if ((fp = fopen (buf, "r")) == NULL) 380 if ((fp = fopen (buf, "r")) == NULL)
393 { 381 {
394 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