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.10 by pippijn, Sat Jan 6 14:42:28 2007 UTC vs.
Revision 1.18 by root, Sun Mar 4 19:36:12 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 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 The maintainer of this code can be reached at <crossfire@schmorp.de> 22 * The maintainer of this code can be reached at <crossfire@schmorp.de>
23*/ 23 */
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;
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 */
112static int 106static int
113compar (const struct bmappair *a, const struct bmappair *b) 107compar (const struct bmappair *a, const struct bmappair *b)
114{ 108{
115 return strcmp (a->name, b->name); 109 return strcmp (a->name, b->name);
116} 110}
111
117static int 112static int
118compar_smooth (const struct smoothing *a, const struct smoothing *b) 113compar_smooth (const struct smoothing *a, const struct smoothing *b)
119{ 114{
120 if (a->id < b->id) 115 if (a->id < b->id)
121 return -1; 116 return -1;
122 if (b->id < a->id) 117 if (b->id < a->id)
123 return 1; 118 return 1;
124 return 0; 119 return 0;
125} 120}
126 121
127
128/* 122/*
129 * Returns the matching color in the coloralias if found, 123 * Returns the matching color in the coloralias if found,
130 * 0 otherwise. Note that 0 will actually be black, so there is no 124 * 0 otherwise. Note that 0 will actually be black, so there is no
131 * way the calling function can tell if an error occurred or not 125 * way the calling function can tell if an error occurred or not
132 */ 126 */
133
134static uint8 127static uint8
135find_color (const char *name) 128find_color (const char *name)
136{ 129{
137 uint8 i; 130 uint8 i;
138 131
144} 137}
145 138
146/* This reads the lib/faces file, getting color and visibility information. 139/* This reads the lib/faces file, getting color and visibility information.
147 * it is called by ReadBmapNames. 140 * it is called by ReadBmapNames.
148 */ 141 */
149
150static void 142static void
151ReadFaceData (void) 143ReadFaceData (void)
152{ 144{
153 char buf[MAX_BUF], *cp; 145 char buf[MAX_BUF], *cp;
154 New_Face *on_face = NULL; 146 facetile *on_face = NULL;
155 FILE *fp; 147 FILE *fp;
156 148
157 sprintf (buf, "%s/faces", settings.datadir); 149 sprintf (buf, "%s/faces", settings.datadir);
158 LOG (llevDebug, "Reading faces from %s...\n", buf); 150 LOG (llevDebug, "Reading faces from %s...\n", buf);
159 if ((fp = fopen (buf, "r")) == NULL) 151 if ((fp = fopen (buf, "r")) == NULL)
217 on_face->magicmap |= FACE_FLOOR; 209 on_face->magicmap |= FACE_FLOOR;
218 } 210 }
219 else 211 else
220 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); 212 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf);
221 } 213 }
214
222 LOG (llevDebug, "done\n"); 215 LOG (llevDebug, "done\n");
223 fclose (fp); 216 fclose (fp);
224} 217}
225 218
226/* This reads the bmaps file to get all the bitmap names and 219/* This reads the bmaps file to get all the bitmap names and
227 * stuff. It only needs to be done once, because it is player 220 * stuff. It only needs to be done once, because it is player
228 * independent (ie, what display the person is on will not make a 221 * independent (ie, what display the person is on will not make a
229 * difference.) 222 * difference.)
230 */ 223 */
231
232void 224void
233ReadBmapNames (void) 225ReadBmapNames (void)
234{ 226{
235 char buf[MAX_BUF], *p, *q; 227 char buf[MAX_BUF], *p, *q;
236 FILE *fp; 228 FILE *fp;
237 int value, nrofbmaps = 0, i; 229 int value, nrofbmaps = 0, i;
238 size_t l; 230 size_t l;
231 crc32 crc;
239 232
240 bmaps_checksum = 0;
241 sprintf (buf, "%s/bmaps", settings.datadir); 233 sprintf (buf, "%s/bmaps", settings.datadir);
242 LOG (llevDebug, "Reading bmaps from %s...\n", buf); 234 LOG (llevDebug, "Reading bmaps from %s...\n", buf);
243 if ((fp = fopen (buf, "r")) == NULL) 235 if ((fp = fopen (buf, "r")) == NULL)
244 { 236 {
245 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));
264 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n"))) 256 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n")))
265 { 257 {
266 LOG (llevDebug, "Warning, syntax error: %s\n", buf); 258 LOG (llevDebug, "Warning, syntax error: %s\n", buf);
267 continue; 259 continue;
268 } 260 }
261
269 value = atoi (p); 262 value = atoi (p);
270 xbm[nroffiles].name = strdup (q); 263 xbm[nroffiles].name = strdup (q);
271 264
272 /* We need to calculate the checksum of the bmaps file 265 /* We need to calculate the checksum of the bmaps file
273 * name->number mapping to send to the client. This does not 266 * name->number mapping to send to the client. This does not
274 * 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 -
275 * 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
276 * 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
277 * the file has the same data or not. 270 * the file has the same data or not.
278 */ 271 */
279 ROTATE_RIGHT (bmaps_checksum); 272 crc (value);
280 bmaps_checksum += value & 0xff; 273 crc (value >> 8);
281 bmaps_checksum &= 0xffffffff;
282 274
283 ROTATE_RIGHT (bmaps_checksum);
284 bmaps_checksum += (value >> 8) & 0xff;
285 bmaps_checksum &= 0xffffffff;
286 for (l = 0; l < strlen (q); l++) 275 for (l = 0; l < strlen (q); l++)
287 { 276 crc (q [l]);
288 ROTATE_RIGHT (bmaps_checksum);
289 bmaps_checksum += q[l];
290 bmaps_checksum &= 0xffffffff;
291 }
292 277
293 xbm[nroffiles].number = value; 278 xbm[nroffiles].number = value;
294 nroffiles++; 279 nroffiles++;
295 if (value >= nrofpixmaps) 280 if (value >= nrofpixmaps)
296 nrofpixmaps = value + 1; 281 nrofpixmaps = value + 1;
297 } 282 }
283
298 fclose (fp); 284 fclose (fp);
299 285
300 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); 286 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles);
301 287
302 new_faces = new New_Face[nrofpixmaps]; 288 new_faces = new facetile[nrofpixmaps];
303 289
304 for (i = 0; i < nrofpixmaps; i++) 290 for (i = 0; i < nrofpixmaps; i++)
305 { 291 {
306 new_faces[i].name = ""; 292 new_faces[i].name = "";
307 new_faces[i].number = i; 293 new_faces[i].number = i;
308 new_faces[i].visibility = 0; 294 new_faces[i].visibility = 0;
309 new_faces[i].magicmap = 255; 295 new_faces[i].magicmap = 255;
310 } 296 }
297
311 for (i = 0; i < nroffiles; i++) 298 for (i = 0; i < nroffiles; i++)
312 {
313 new_faces[xbm[i].number].name = xbm[i].name; 299 new_faces[xbm[i].number].name = xbm[i].name;
314 }
315 300
316 // non-pod datatype, likely not allowed 301 // non-pod datatype, likely not allowed
317 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);
318 303
319 ReadFaceData (); 304 ReadFaceData ();
338 323
339 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)]; 324 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)];
340 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)]; 325 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)];
341 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)]; 326 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)];
342 327
343 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)]; 328 bmaps_checksum = crc;
344} 329}
345 330
346/* This returns an the face number of face 'name'. Number is constant 331/* This returns an the face number of face 'name'. Number is constant
347 * during an invocation, but not necessarily between versions (this 332 * during an invocation, but not necessarily between versions (this
348 * is because the faces are arranged in alphabetical order, so 333 * is because the faces are arranged in alphabetical order, so
386{ 371{
387 char buf[MAX_BUF], *p, *q; 372 char buf[MAX_BUF], *p, *q;
388 FILE *fp; 373 FILE *fp;
389 int smoothcount = 0; 374 int smoothcount = 0;
390 375
391 bmaps_checksum = 0;
392 sprintf (buf, "%s/smooth", settings.datadir); 376 sprintf (buf, "%s/smooth", settings.datadir);
393 LOG (llevDebug, "Reading smooth from %s...\n", buf); 377 LOG (llevDebug, "Reading smooth from %s...\n", buf);
394 if ((fp = fopen (buf, "r")) == NULL) 378 if ((fp = fopen (buf, "r")) == NULL)
395 { 379 {
396 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); 380 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines