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.8 by root, Thu Dec 14 22:45:40 2006 UTC vs.
Revision 1.15 by root, Mon Feb 5 02:17:28 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) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 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
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 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>
22*/ 23 */
23 24
24 25
25#include <global.h> 26#include <global.h>
26#include <stdio.h> 27#include <stdio.h>
27 28
28New_Face *new_faces; 29facetile *new_faces;
29 30
30/* bmappair and xbm are used when looking for the image id numbers 31/* bmappair and xbm are used when looking for the image id numbers
31 * of a face by name. xbm is sorted alphabetically so that bsearch 32 * of a face by name. xbm is sorted alphabetically so that bsearch
32 * can be used to quickly find the entry for a name. the number is 33 * can be used to quickly find the entry for a name. the number is
33 * then an index into the new_faces array. 34 * then an index into the new_faces array.
43{ 44{
44 char *name; 45 char *name;
45 unsigned int number; 46 unsigned int number;
46}; 47};
47 48
48void free (bmappair *); // guard to catch free when delete should be used
49
50static struct bmappair *xbm = NULL; 49static struct bmappair *xbm = NULL;
51 50
52/* Following can just as easily be pointers, but
53 * it is easier to keep them like this.
54 */
55New_Face *blank_face, *dark_faces[3], *empty_face, *smooth_face; 51facetile *blank_face, *dark_faces[3], *empty_face, *smooth_face;
56
57 52
58/* nroffiles is the actual number of bitmaps defined. 53/* nroffiles is the actual number of bitmaps defined.
59 * nrofpixmaps is the number of bitmaps loaded. With 54 * nrofpixmaps is the number of bitmaps loaded. With
60 * the automatic generation of the bmaps file, this is now equal 55 * the automatic generation of the bmaps file, this is now equal
61 * to nroffiles. 56 * to nroffiles.
69int nrofpixmaps = 0; 64int nrofpixmaps = 0;
70 65
71/** 66/**
72 * id is the face to smooth, smooth is the 16x2 face used to smooth id. 67 * id is the face to smooth, smooth is the 16x2 face used to smooth id.
73 */ 68 */
74struct smoothing:zero_initialised 69struct smoothing : zero_initialised
75{ 70{
76 uint16 id; 71 uint16 id;
77 uint16 smooth; 72 uint16 smooth;
78}; 73};
79
80void free (smoothing *); // guard to catch free when delete should be used
81 74
82/** 75/**
83 * Contains all defined smoothing entries. smooth is an array of nrofsmooth 76 * Contains all defined smoothing entries. smooth is an array of nrofsmooth
84 * entries. It is sorted by smooth[].id. 77 * entries. It is sorted by smooth[].id.
85 */ 78 */
111static int 104static int
112compar (const struct bmappair *a, const struct bmappair *b) 105compar (const struct bmappair *a, const struct bmappair *b)
113{ 106{
114 return strcmp (a->name, b->name); 107 return strcmp (a->name, b->name);
115} 108}
109
116static int 110static int
117compar_smooth (const struct smoothing *a, const struct smoothing *b) 111compar_smooth (const struct smoothing *a, const struct smoothing *b)
118{ 112{
119 if (a->id < b->id) 113 if (a->id < b->id)
120 return -1; 114 return -1;
121 if (b->id < a->id) 115 if (b->id < a->id)
122 return 1; 116 return 1;
123 return 0; 117 return 0;
124} 118}
125 119
126
127/* 120/*
128 * Returns the matching color in the coloralias if found, 121 * Returns the matching color in the coloralias if found,
129 * 0 otherwise. Note that 0 will actually be black, so there is no 122 * 0 otherwise. Note that 0 will actually be black, so there is no
130 * way the calling function can tell if an error occurred or not 123 * way the calling function can tell if an error occurred or not
131 */ 124 */
132
133static uint8 125static uint8
134find_color (const char *name) 126find_color (const char *name)
135{ 127{
136 uint8 i; 128 uint8 i;
137 129
143} 135}
144 136
145/* This reads the lib/faces file, getting color and visibility information. 137/* This reads the lib/faces file, getting color and visibility information.
146 * it is called by ReadBmapNames. 138 * it is called by ReadBmapNames.
147 */ 139 */
148
149static void 140static void
150ReadFaceData (void) 141ReadFaceData (void)
151{ 142{
152 char buf[MAX_BUF], *cp; 143 char buf[MAX_BUF], *cp;
153 New_Face *on_face = NULL; 144 facetile *on_face = NULL;
154 FILE *fp; 145 FILE *fp;
155 146
156 sprintf (buf, "%s/faces", settings.datadir); 147 sprintf (buf, "%s/faces", settings.datadir);
157 LOG (llevDebug, "Reading faces from %s...", buf); 148 LOG (llevDebug, "Reading faces from %s...\n", buf);
158 if ((fp = fopen (buf, "r")) == NULL) 149 if ((fp = fopen (buf, "r")) == NULL)
159 { 150 {
160 LOG (llevError, "Cannot open faces file %s: %s\n", buf, strerror (errno)); 151 LOG (llevError, "Cannot open faces file %s: %s\n", buf, strerror (errno));
161 exit (-1); 152 exit (-1);
162 } 153 }
216 on_face->magicmap |= FACE_FLOOR; 207 on_face->magicmap |= FACE_FLOOR;
217 } 208 }
218 else 209 else
219 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); 210 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf);
220 } 211 }
212
221 LOG (llevDebug, "done\n"); 213 LOG (llevDebug, "done\n");
222 fclose (fp); 214 fclose (fp);
223} 215}
224 216
225/* This reads the bmaps file to get all the bitmap names and 217/* This reads the bmaps file to get all the bitmap names and
226 * stuff. It only needs to be done once, because it is player 218 * stuff. It only needs to be done once, because it is player
227 * independent (ie, what display the person is on will not make a 219 * independent (ie, what display the person is on will not make a
228 * difference.) 220 * difference.)
229 */ 221 */
230
231void 222void
232ReadBmapNames (void) 223ReadBmapNames (void)
233{ 224{
234 char buf[MAX_BUF], *p, *q; 225 char buf[MAX_BUF], *p, *q;
235 FILE *fp; 226 FILE *fp;
236 int value, nrofbmaps = 0, i; 227 int value, nrofbmaps = 0, i;
237 size_t l; 228 size_t l;
238 229
239 bmaps_checksum = 0; 230 bmaps_checksum = 0;
240 sprintf (buf, "%s/bmaps", settings.datadir); 231 sprintf (buf, "%s/bmaps", settings.datadir);
241 LOG (llevDebug, "Reading bmaps from %s...", buf); 232 LOG (llevDebug, "Reading bmaps from %s...\n", buf);
242 if ((fp = fopen (buf, "r")) == NULL) 233 if ((fp = fopen (buf, "r")) == NULL)
243 { 234 {
244 LOG (llevError, "Cannot open bmaps file %s: %s\n", buf, strerror (errno)); 235 LOG (llevError, "Cannot open bmaps file %s: %s\n", buf, strerror (errno));
245 exit (-1); 236 exit (-1);
246 } 237 }
296 } 287 }
297 fclose (fp); 288 fclose (fp);
298 289
299 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); 290 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles);
300 291
301 new_faces = new New_Face[nrofpixmaps]; 292 new_faces = new facetile[nrofpixmaps];
302 293
303 for (i = 0; i < nrofpixmaps; i++) 294 for (i = 0; i < nrofpixmaps; i++)
304 { 295 {
305 new_faces[i].name = ""; 296 new_faces[i].name = "";
306 new_faces[i].number = i; 297 new_faces[i].number = i;
307 new_faces[i].visibility = 0; 298 new_faces[i].visibility = 0;
308 new_faces[i].magicmap = 255; 299 new_faces[i].magicmap = 255;
309 } 300 }
301
310 for (i = 0; i < nroffiles; i++) 302 for (i = 0; i < nroffiles; i++)
311 {
312 new_faces[xbm[i].number].name = xbm[i].name; 303 new_faces[xbm[i].number].name = xbm[i].name;
313 }
314 304
315 // non-pod datatype, likely not allowed 305 // non-pod datatype, likely not allowed
316 qsort (xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar); 306 qsort (xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar);
317 307
318 ReadFaceData (); 308 ReadFaceData ();
387 FILE *fp; 377 FILE *fp;
388 int smoothcount = 0; 378 int smoothcount = 0;
389 379
390 bmaps_checksum = 0; 380 bmaps_checksum = 0;
391 sprintf (buf, "%s/smooth", settings.datadir); 381 sprintf (buf, "%s/smooth", settings.datadir);
392 LOG (llevDebug, "Reading smooth from %s...", buf); 382 LOG (llevDebug, "Reading smooth from %s...\n", buf);
393 if ((fp = fopen (buf, "r")) == NULL) 383 if ((fp = fopen (buf, "r")) == NULL)
394 { 384 {
395 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); 385 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno));
396 exit (-1); 386 exit (-1);
397 } 387 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines