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.6 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.17 by root, Thu Feb 15 18:09:33 2007 UTC

1
2/* 1/*
3 * static char *rcsid_image_c =
4 * "$Id: image.C,v 1.6 2006/09/10 16:00:23 root Exp $";
5 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
9 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
12 7 *
13 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
14 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
15 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 11 * (at your option) any later version.
17 12 *
18 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,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 16 * GNU General Public License for more details.
22 17 *
23 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
24 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 21 *
27 The maintainer of this code can be reached at crossfire-devel@real-time.com 22 * The maintainer of this code can be reached at <crossfire@schmorp.de>
28*/ 23 */
29 24
30 25
31#include <global.h> 26#include <global.h>
32#include <stdio.h> 27#include <stdio.h>
33 28
29#include "crc.h"
30
34New_Face *new_faces; 31facetile *new_faces;
35 32
36/* 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
37 * 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
38 * 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
39 * then an index into the new_faces array. 36 * then an index into the new_faces array.
49{ 46{
50 char *name; 47 char *name;
51 unsigned int number; 48 unsigned int number;
52}; 49};
53 50
54void free (bmappair *); // guard to catch free when delete should be used
55
56static struct bmappair *xbm = NULL; 51static struct bmappair *xbm = NULL;
57 52
58/* Following can just as easily be pointers, but
59 * it is easier to keep them like this.
60 */
61New_Face *blank_face, *dark_faces[3], *empty_face, *smooth_face; 53facetile *blank_face, *dark_faces[3], *empty_face, *smooth_face;
62
63 54
64/* nroffiles is the actual number of bitmaps defined. 55/* nroffiles is the actual number of bitmaps defined.
65 * nrofpixmaps is the number of bitmaps loaded. With 56 * nrofpixmaps is the number of bitmaps loaded. With
66 * the automatic generation of the bmaps file, this is now equal 57 * the automatic generation of the bmaps file, this is now equal
67 * to nroffiles. 58 * to nroffiles.
75int nrofpixmaps = 0; 66int nrofpixmaps = 0;
76 67
77/** 68/**
78 * 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.
79 */ 70 */
80struct smoothing:zero_initialised 71struct smoothing : zero_initialised
81{ 72{
82 uint16 id; 73 uint16 id;
83 uint16 smooth; 74 uint16 smooth;
84}; 75};
85
86void free (smoothing *); // guard to catch free when delete should be used
87 76
88/** 77/**
89 * Contains all defined smoothing entries. smooth is an array of nrofsmooth 78 * Contains all defined smoothing entries. smooth is an array of nrofsmooth
90 * entries. It is sorted by smooth[].id. 79 * entries. It is sorted by smooth[].id.
91 */ 80 */
117static int 106static int
118compar (const struct bmappair *a, const struct bmappair *b) 107compar (const struct bmappair *a, const struct bmappair *b)
119{ 108{
120 return strcmp (a->name, b->name); 109 return strcmp (a->name, b->name);
121} 110}
111
122static int 112static int
123compar_smooth (const struct smoothing *a, const struct smoothing *b) 113compar_smooth (const struct smoothing *a, const struct smoothing *b)
124{ 114{
125 if (a->id < b->id) 115 if (a->id < b->id)
126 return -1; 116 return -1;
127 if (b->id < a->id) 117 if (b->id < a->id)
128 return 1; 118 return 1;
129 return 0; 119 return 0;
130} 120}
131 121
132
133/* 122/*
134 * Returns the matching color in the coloralias if found, 123 * Returns the matching color in the coloralias if found,
135 * 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
136 * 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
137 */ 126 */
138
139static uint8 127static uint8
140find_color (const char *name) 128find_color (const char *name)
141{ 129{
142 uint8 i; 130 uint8 i;
143 131
149} 137}
150 138
151/* This reads the lib/faces file, getting color and visibility information. 139/* This reads the lib/faces file, getting color and visibility information.
152 * it is called by ReadBmapNames. 140 * it is called by ReadBmapNames.
153 */ 141 */
154
155static void 142static void
156ReadFaceData (void) 143ReadFaceData (void)
157{ 144{
158 char buf[MAX_BUF], *cp; 145 char buf[MAX_BUF], *cp;
159 New_Face *on_face = NULL; 146 facetile *on_face = NULL;
160 FILE *fp; 147 FILE *fp;
161 148
162 sprintf (buf, "%s/faces", settings.datadir); 149 sprintf (buf, "%s/faces", settings.datadir);
163 LOG (llevDebug, "Reading faces from %s...", buf); 150 LOG (llevDebug, "Reading faces from %s...\n", buf);
164 if ((fp = fopen (buf, "r")) == NULL) 151 if ((fp = fopen (buf, "r")) == NULL)
165 { 152 {
166 LOG (llevError, "Cannot open faces file %s: %s\n", buf, strerror (errno)); 153 LOG (llevError, "Cannot open faces file %s: %s\n", buf, strerror (errno));
167 exit (-1); 154 exit (-1);
168 } 155 }
222 on_face->magicmap |= FACE_FLOOR; 209 on_face->magicmap |= FACE_FLOOR;
223 } 210 }
224 else 211 else
225 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); 212 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf);
226 } 213 }
214
227 LOG (llevDebug, "done\n"); 215 LOG (llevDebug, "done\n");
228 fclose (fp); 216 fclose (fp);
229} 217}
230 218
231/* 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
232 * 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
233 * 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
234 * difference.) 222 * difference.)
235 */ 223 */
236
237void 224void
238ReadBmapNames (void) 225ReadBmapNames (void)
239{ 226{
240 char buf[MAX_BUF], *p, *q; 227 char buf[MAX_BUF], *p, *q;
241 FILE *fp; 228 FILE *fp;
242 int value, nrofbmaps = 0, i; 229 int value, nrofbmaps = 0, i;
243 size_t l; 230 size_t l;
231 crc32 crc;
244 232
245 bmaps_checksum = 0;
246 sprintf (buf, "%s/bmaps", settings.datadir); 233 sprintf (buf, "%s/bmaps", settings.datadir);
247 LOG (llevDebug, "Reading bmaps from %s...", buf); 234 LOG (llevDebug, "Reading bmaps from %s...\n", buf);
248 if ((fp = fopen (buf, "r")) == NULL) 235 if ((fp = fopen (buf, "r")) == NULL)
249 { 236 {
250 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));
251 exit (-1); 238 exit (-1);
252 } 239 }
269 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n"))) 256 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n")))
270 { 257 {
271 LOG (llevDebug, "Warning, syntax error: %s\n", buf); 258 LOG (llevDebug, "Warning, syntax error: %s\n", buf);
272 continue; 259 continue;
273 } 260 }
261
274 value = atoi (p); 262 value = atoi (p);
275 xbm[nroffiles].name = strdup_local (q); 263 xbm[nroffiles].name = strdup (q);
276 264
277 /* We need to calculate the checksum of the bmaps file 265 /* We need to calculate the checksum of the bmaps file
278 * name->number mapping to send to the client. This does not 266 * name->number mapping to send to the client. This does not
279 * 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 -
280 * 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
281 * 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
282 * the file has the same data or not. 270 * the file has the same data or not.
283 */ 271 */
284 ROTATE_RIGHT (bmaps_checksum); 272 crc (value);
285 bmaps_checksum += value & 0xff; 273 crc (value >> 8);
286 bmaps_checksum &= 0xffffffff;
287 274
288 ROTATE_RIGHT (bmaps_checksum);
289 bmaps_checksum += (value >> 8) & 0xff;
290 bmaps_checksum &= 0xffffffff;
291 for (l = 0; l < strlen (q); l++) 275 for (l = 0; l < strlen (q); l++)
292 { 276 crc (q [l]);
293 ROTATE_RIGHT (bmaps_checksum);
294 bmaps_checksum += q[l];
295 bmaps_checksum &= 0xffffffff;
296 }
297 277
298 xbm[nroffiles].number = value; 278 xbm[nroffiles].number = value;
299 nroffiles++; 279 nroffiles++;
300 if (value >= nrofpixmaps) 280 if (value >= nrofpixmaps)
301 nrofpixmaps = value + 1; 281 nrofpixmaps = value + 1;
302 } 282 }
283
303 fclose (fp); 284 fclose (fp);
304 285
305 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); 286 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles);
306 287
307 new_faces = new New_Face[nrofpixmaps]; 288 new_faces = new facetile[nrofpixmaps];
308 289
309 for (i = 0; i < nrofpixmaps; i++) 290 for (i = 0; i < nrofpixmaps; i++)
310 { 291 {
311 new_faces[i].name = ""; 292 new_faces[i].name = "";
312 new_faces[i].number = i; 293 new_faces[i].number = i;
313 new_faces[i].visibility = 0; 294 new_faces[i].visibility = 0;
314 new_faces[i].magicmap = 255; 295 new_faces[i].magicmap = 255;
315 } 296 }
297
316 for (i = 0; i < nroffiles; i++) 298 for (i = 0; i < nroffiles; i++)
317 {
318 new_faces[xbm[i].number].name = xbm[i].name; 299 new_faces[xbm[i].number].name = xbm[i].name;
319 }
320 300
321 // non-pod datatype, likely not allowed 301 // non-pod datatype, likely not allowed
322 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);
323 303
324 ReadFaceData (); 304 ReadFaceData ();
344 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)]; 324 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)];
345 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)]; 325 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)];
346 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)]; 326 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)];
347 327
348 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)]; 328 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)];
329
330 bmaps_checksum = crc;
349} 331}
350 332
351/* 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
352 * during an invocation, but not necessarily between versions (this 334 * during an invocation, but not necessarily between versions (this
353 * is because the faces are arranged in alphabetical order, so 335 * is because the faces are arranged in alphabetical order, so
391{ 373{
392 char buf[MAX_BUF], *p, *q; 374 char buf[MAX_BUF], *p, *q;
393 FILE *fp; 375 FILE *fp;
394 int smoothcount = 0; 376 int smoothcount = 0;
395 377
396 bmaps_checksum = 0;
397 sprintf (buf, "%s/smooth", settings.datadir); 378 sprintf (buf, "%s/smooth", settings.datadir);
398 LOG (llevDebug, "Reading smooth from %s...", buf); 379 LOG (llevDebug, "Reading smooth from %s...\n", buf);
399 if ((fp = fopen (buf, "r")) == NULL) 380 if ((fp = fopen (buf, "r")) == NULL)
400 { 381 {
401 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); 382 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno));
402 exit (-1); 383 exit (-1);
403 } 384 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines