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.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) 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
29New_Face *new_faces; 29facetile *new_faces;
30 30
31/* 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
32 * 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
33 * 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
34 * then an index into the new_faces array. 34 * then an index into the new_faces array.
44{ 44{
45 char *name; 45 char *name;
46 unsigned int number; 46 unsigned int number;
47}; 47};
48 48
49void free (bmappair *); // guard to catch free when delete should be used
50
51static struct bmappair *xbm = NULL; 49static struct bmappair *xbm = NULL;
52 50
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; 51facetile *blank_face, *dark_faces[3], *empty_face, *smooth_face;
57
58 52
59/* nroffiles is the actual number of bitmaps defined. 53/* nroffiles is the actual number of bitmaps defined.
60 * nrofpixmaps is the number of bitmaps loaded. With 54 * nrofpixmaps is the number of bitmaps loaded. With
61 * the automatic generation of the bmaps file, this is now equal 55 * the automatic generation of the bmaps file, this is now equal
62 * to nroffiles. 56 * to nroffiles.
70int nrofpixmaps = 0; 64int nrofpixmaps = 0;
71 65
72/** 66/**
73 * 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.
74 */ 68 */
75struct smoothing:zero_initialised 69struct smoothing : zero_initialised
76{ 70{
77 uint16 id; 71 uint16 id;
78 uint16 smooth; 72 uint16 smooth;
79}; 73};
80
81void free (smoothing *); // guard to catch free when delete should be used
82 74
83/** 75/**
84 * Contains all defined smoothing entries. smooth is an array of nrofsmooth 76 * Contains all defined smoothing entries. smooth is an array of nrofsmooth
85 * entries. It is sorted by smooth[].id. 77 * entries. It is sorted by smooth[].id.
86 */ 78 */
112static int 104static int
113compar (const struct bmappair *a, const struct bmappair *b) 105compar (const struct bmappair *a, const struct bmappair *b)
114{ 106{
115 return strcmp (a->name, b->name); 107 return strcmp (a->name, b->name);
116} 108}
109
117static int 110static int
118compar_smooth (const struct smoothing *a, const struct smoothing *b) 111compar_smooth (const struct smoothing *a, const struct smoothing *b)
119{ 112{
120 if (a->id < b->id) 113 if (a->id < b->id)
121 return -1; 114 return -1;
122 if (b->id < a->id) 115 if (b->id < a->id)
123 return 1; 116 return 1;
124 return 0; 117 return 0;
125} 118}
126 119
127
128/* 120/*
129 * Returns the matching color in the coloralias if found, 121 * Returns the matching color in the coloralias if found,
130 * 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
131 * 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
132 */ 124 */
133
134static uint8 125static uint8
135find_color (const char *name) 126find_color (const char *name)
136{ 127{
137 uint8 i; 128 uint8 i;
138 129
144} 135}
145 136
146/* This reads the lib/faces file, getting color and visibility information. 137/* This reads the lib/faces file, getting color and visibility information.
147 * it is called by ReadBmapNames. 138 * it is called by ReadBmapNames.
148 */ 139 */
149
150static void 140static void
151ReadFaceData (void) 141ReadFaceData (void)
152{ 142{
153 char buf[MAX_BUF], *cp; 143 char buf[MAX_BUF], *cp;
154 New_Face *on_face = NULL; 144 facetile *on_face = NULL;
155 FILE *fp; 145 FILE *fp;
156 146
157 sprintf (buf, "%s/faces", settings.datadir); 147 sprintf (buf, "%s/faces", settings.datadir);
158 LOG (llevDebug, "Reading faces from %s...\n", buf); 148 LOG (llevDebug, "Reading faces from %s...\n", buf);
159 if ((fp = fopen (buf, "r")) == NULL) 149 if ((fp = fopen (buf, "r")) == NULL)
217 on_face->magicmap |= FACE_FLOOR; 207 on_face->magicmap |= FACE_FLOOR;
218 } 208 }
219 else 209 else
220 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); 210 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf);
221 } 211 }
212
222 LOG (llevDebug, "done\n"); 213 LOG (llevDebug, "done\n");
223 fclose (fp); 214 fclose (fp);
224} 215}
225 216
226/* 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
227 * 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
228 * 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
229 * difference.) 220 * difference.)
230 */ 221 */
231
232void 222void
233ReadBmapNames (void) 223ReadBmapNames (void)
234{ 224{
235 char buf[MAX_BUF], *p, *q; 225 char buf[MAX_BUF], *p, *q;
236 FILE *fp; 226 FILE *fp;
297 } 287 }
298 fclose (fp); 288 fclose (fp);
299 289
300 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); 290 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles);
301 291
302 new_faces = new New_Face[nrofpixmaps]; 292 new_faces = new facetile[nrofpixmaps];
303 293
304 for (i = 0; i < nrofpixmaps; i++) 294 for (i = 0; i < nrofpixmaps; i++)
305 { 295 {
306 new_faces[i].name = ""; 296 new_faces[i].name = "";
307 new_faces[i].number = i; 297 new_faces[i].number = i;
308 new_faces[i].visibility = 0; 298 new_faces[i].visibility = 0;
309 new_faces[i].magicmap = 255; 299 new_faces[i].magicmap = 255;
310 } 300 }
301
311 for (i = 0; i < nroffiles; i++) 302 for (i = 0; i < nroffiles; i++)
312 {
313 new_faces[xbm[i].number].name = xbm[i].name; 303 new_faces[xbm[i].number].name = xbm[i].name;
314 }
315 304
316 // non-pod datatype, likely not allowed 305 // non-pod datatype, likely not allowed
317 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);
318 307
319 ReadFaceData (); 308 ReadFaceData ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines