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 | |
34 | New_Face *new_faces; |
29 | facetile *new_faces; |
35 | |
30 | |
36 | /* 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 |
37 | * 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 |
38 | * 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 |
39 | * then an index into the new_faces array. |
34 | * then an index into the new_faces array. |
… | |
… | |
49 | { |
44 | { |
50 | char *name; |
45 | char *name; |
51 | unsigned int number; |
46 | unsigned int number; |
52 | }; |
47 | }; |
53 | |
48 | |
54 | void free (bmappair *); // guard to catch free when delete should be used |
|
|
55 | |
|
|
56 | static struct bmappair *xbm = NULL; |
49 | static struct bmappair *xbm = NULL; |
57 | |
50 | |
58 | /* Following can just as easily be pointers, but |
|
|
59 | * it is easier to keep them like this. |
|
|
60 | */ |
|
|
61 | New_Face *blank_face, *dark_faces[3], *empty_face, *smooth_face; |
51 | facetile *blank_face, *dark_faces[3], *empty_face, *smooth_face; |
62 | |
|
|
63 | |
52 | |
64 | /* nroffiles is the actual number of bitmaps defined. |
53 | /* nroffiles is the actual number of bitmaps defined. |
65 | * nrofpixmaps is the number of bitmaps loaded. With |
54 | * nrofpixmaps is the number of bitmaps loaded. With |
66 | * the automatic generation of the bmaps file, this is now equal |
55 | * the automatic generation of the bmaps file, this is now equal |
67 | * to nroffiles. |
56 | * to nroffiles. |
… | |
… | |
75 | int nrofpixmaps = 0; |
64 | int nrofpixmaps = 0; |
76 | |
65 | |
77 | /** |
66 | /** |
78 | * 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. |
79 | */ |
68 | */ |
80 | struct smoothing:zero_initialised |
69 | struct smoothing : zero_initialised |
81 | { |
70 | { |
82 | uint16 id; |
71 | uint16 id; |
83 | uint16 smooth; |
72 | uint16 smooth; |
84 | }; |
73 | }; |
85 | |
|
|
86 | void free (smoothing *); // guard to catch free when delete should be used |
|
|
87 | |
74 | |
88 | /** |
75 | /** |
89 | * Contains all defined smoothing entries. smooth is an array of nrofsmooth |
76 | * Contains all defined smoothing entries. smooth is an array of nrofsmooth |
90 | * entries. It is sorted by smooth[].id. |
77 | * entries. It is sorted by smooth[].id. |
91 | */ |
78 | */ |
… | |
… | |
117 | static int |
104 | static int |
118 | compar (const struct bmappair *a, const struct bmappair *b) |
105 | compar (const struct bmappair *a, const struct bmappair *b) |
119 | { |
106 | { |
120 | return strcmp (a->name, b->name); |
107 | return strcmp (a->name, b->name); |
121 | } |
108 | } |
|
|
109 | |
122 | static int |
110 | static int |
123 | compar_smooth (const struct smoothing *a, const struct smoothing *b) |
111 | compar_smooth (const struct smoothing *a, const struct smoothing *b) |
124 | { |
112 | { |
125 | if (a->id < b->id) |
113 | if (a->id < b->id) |
126 | return -1; |
114 | return -1; |
127 | if (b->id < a->id) |
115 | if (b->id < a->id) |
128 | return 1; |
116 | return 1; |
129 | return 0; |
117 | return 0; |
130 | } |
118 | } |
131 | |
119 | |
132 | |
|
|
133 | /* |
120 | /* |
134 | * Returns the matching color in the coloralias if found, |
121 | * Returns the matching color in the coloralias if found, |
135 | * 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 |
136 | * 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 |
137 | */ |
124 | */ |
138 | |
|
|
139 | static uint8 |
125 | static uint8 |
140 | find_color (const char *name) |
126 | find_color (const char *name) |
141 | { |
127 | { |
142 | uint8 i; |
128 | uint8 i; |
143 | |
129 | |
… | |
… | |
149 | } |
135 | } |
150 | |
136 | |
151 | /* This reads the lib/faces file, getting color and visibility information. |
137 | /* This reads the lib/faces file, getting color and visibility information. |
152 | * it is called by ReadBmapNames. |
138 | * it is called by ReadBmapNames. |
153 | */ |
139 | */ |
154 | |
|
|
155 | static void |
140 | static void |
156 | ReadFaceData (void) |
141 | ReadFaceData (void) |
157 | { |
142 | { |
158 | char buf[MAX_BUF], *cp; |
143 | char buf[MAX_BUF], *cp; |
159 | New_Face *on_face = NULL; |
144 | facetile *on_face = NULL; |
160 | FILE *fp; |
145 | FILE *fp; |
161 | |
146 | |
162 | sprintf (buf, "%s/faces", settings.datadir); |
147 | sprintf (buf, "%s/faces", settings.datadir); |
163 | LOG (llevDebug, "Reading faces from %s...", buf); |
148 | LOG (llevDebug, "Reading faces from %s...\n", buf); |
164 | if ((fp = fopen (buf, "r")) == NULL) |
149 | if ((fp = fopen (buf, "r")) == NULL) |
165 | { |
150 | { |
166 | 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)); |
167 | exit (-1); |
152 | exit (-1); |
168 | } |
153 | } |
… | |
… | |
222 | on_face->magicmap |= FACE_FLOOR; |
207 | on_face->magicmap |= FACE_FLOOR; |
223 | } |
208 | } |
224 | else |
209 | else |
225 | LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); |
210 | LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); |
226 | } |
211 | } |
|
|
212 | |
227 | LOG (llevDebug, "done\n"); |
213 | LOG (llevDebug, "done\n"); |
228 | fclose (fp); |
214 | fclose (fp); |
229 | } |
215 | } |
230 | |
216 | |
231 | /* 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 |
232 | * 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 |
233 | * 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 |
234 | * difference.) |
220 | * difference.) |
235 | */ |
221 | */ |
236 | |
|
|
237 | void |
222 | void |
238 | ReadBmapNames (void) |
223 | ReadBmapNames (void) |
239 | { |
224 | { |
240 | char buf[MAX_BUF], *p, *q; |
225 | char buf[MAX_BUF], *p, *q; |
241 | FILE *fp; |
226 | FILE *fp; |
242 | int value, nrofbmaps = 0, i; |
227 | int value, nrofbmaps = 0, i; |
243 | size_t l; |
228 | size_t l; |
244 | |
229 | |
245 | bmaps_checksum = 0; |
230 | bmaps_checksum = 0; |
246 | sprintf (buf, "%s/bmaps", settings.datadir); |
231 | sprintf (buf, "%s/bmaps", settings.datadir); |
247 | LOG (llevDebug, "Reading bmaps from %s...", buf); |
232 | LOG (llevDebug, "Reading bmaps from %s...\n", buf); |
248 | if ((fp = fopen (buf, "r")) == NULL) |
233 | if ((fp = fopen (buf, "r")) == NULL) |
249 | { |
234 | { |
250 | 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)); |
251 | exit (-1); |
236 | exit (-1); |
252 | } |
237 | } |
… | |
… | |
270 | { |
255 | { |
271 | LOG (llevDebug, "Warning, syntax error: %s\n", buf); |
256 | LOG (llevDebug, "Warning, syntax error: %s\n", buf); |
272 | continue; |
257 | continue; |
273 | } |
258 | } |
274 | value = atoi (p); |
259 | value = atoi (p); |
275 | xbm[nroffiles].name = strdup_local (q); |
260 | xbm[nroffiles].name = strdup (q); |
276 | |
261 | |
277 | /* We need to calculate the checksum of the bmaps file |
262 | /* We need to calculate the checksum of the bmaps file |
278 | * name->number mapping to send to the client. This does not |
263 | * name->number mapping to send to the client. This does not |
279 | * need to match what sum or other utility may come up with - |
264 | * 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 |
265 | * as long as we get the same results on the same real file |
… | |
… | |
302 | } |
287 | } |
303 | fclose (fp); |
288 | fclose (fp); |
304 | |
289 | |
305 | LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); |
290 | LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); |
306 | |
291 | |
307 | new_faces = new New_Face[nrofpixmaps]; |
292 | new_faces = new facetile[nrofpixmaps]; |
308 | |
293 | |
309 | for (i = 0; i < nrofpixmaps; i++) |
294 | for (i = 0; i < nrofpixmaps; i++) |
310 | { |
295 | { |
311 | new_faces[i].name = ""; |
296 | new_faces[i].name = ""; |
312 | new_faces[i].number = i; |
297 | new_faces[i].number = i; |
313 | new_faces[i].visibility = 0; |
298 | new_faces[i].visibility = 0; |
314 | new_faces[i].magicmap = 255; |
299 | new_faces[i].magicmap = 255; |
315 | } |
300 | } |
|
|
301 | |
316 | for (i = 0; i < nroffiles; i++) |
302 | for (i = 0; i < nroffiles; i++) |
317 | { |
|
|
318 | new_faces[xbm[i].number].name = xbm[i].name; |
303 | new_faces[xbm[i].number].name = xbm[i].name; |
319 | } |
|
|
320 | |
304 | |
321 | // non-pod datatype, likely not allowed |
305 | // non-pod datatype, likely not allowed |
322 | 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); |
323 | |
307 | |
324 | ReadFaceData (); |
308 | ReadFaceData (); |
… | |
… | |
393 | FILE *fp; |
377 | FILE *fp; |
394 | int smoothcount = 0; |
378 | int smoothcount = 0; |
395 | |
379 | |
396 | bmaps_checksum = 0; |
380 | bmaps_checksum = 0; |
397 | sprintf (buf, "%s/smooth", settings.datadir); |
381 | sprintf (buf, "%s/smooth", settings.datadir); |
398 | LOG (llevDebug, "Reading smooth from %s...", buf); |
382 | LOG (llevDebug, "Reading smooth from %s...\n", buf); |
399 | if ((fp = fopen (buf, "r")) == NULL) |
383 | if ((fp = fopen (buf, "r")) == NULL) |
400 | { |
384 | { |
401 | LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); |
385 | LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); |
402 | exit (-1); |
386 | exit (-1); |
403 | } |
387 | } |