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.5 by root, Fri Sep 8 16:51:42 2006 UTC vs.
Revision 1.15 by root, Mon Feb 5 02:17:28 2007 UTC

1/* 1/*
2 * static char *rcsid_image_c =
3 * "$Id: image.C,v 1.5 2006/09/08 16:51:42 root Exp $";
4 */
5
6/*
7 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
8 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
9 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
11 7 *
12 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
13 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
14 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version. 11 * (at your option) any later version.
16 12 *
17 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,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details. 16 * GNU General Public License for more details.
21 17 *
22 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
23 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 21 *
26 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>
27*/ 23 */
28 24
29 25
30#include <global.h> 26#include <global.h>
31#include <stdio.h> 27#include <stdio.h>
32 28
33New_Face *new_faces; 29facetile *new_faces;
34 30
35/* 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
36 * 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
37 * 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
38 * then an index into the new_faces array. 34 * then an index into the new_faces array.
48{ 44{
49 char *name; 45 char *name;
50 unsigned int number; 46 unsigned int number;
51}; 47};
52 48
53void free (bmappair *); // guard to catch free when delete should be used
54
55static struct bmappair *xbm=NULL; 49static struct bmappair *xbm = NULL;
56 50
57/* Following can just as easily be pointers, but
58 * it is easier to keep them like this.
59 */
60New_Face *blank_face, *dark_faces[3], *empty_face, *smooth_face; 51facetile *blank_face, *dark_faces[3], *empty_face, *smooth_face;
61
62 52
63/* nroffiles is the actual number of bitmaps defined. 53/* nroffiles is the actual number of bitmaps defined.
64 * nrofpixmaps is the number of bitmaps loaded. With 54 * nrofpixmaps is the number of bitmaps loaded. With
65 * the automatic generation of the bmaps file, this is now equal 55 * the automatic generation of the bmaps file, this is now equal
66 * to nroffiles. 56 * to nroffiles.
76/** 66/**
77 * 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.
78 */ 68 */
79struct smoothing : zero_initialised 69struct smoothing : zero_initialised
80{ 70{
81 uint16 id; 71 uint16 id;
82 uint16 smooth; 72 uint16 smooth;
83}; 73};
84
85void free (smoothing *); // guard to catch free when delete should be used
86 74
87/** 75/**
88 * Contains all defined smoothing entries. smooth is an array of nrofsmooth 76 * Contains all defined smoothing entries. smooth is an array of nrofsmooth
89 * entries. It is sorted by smooth[].id. 77 * entries. It is sorted by smooth[].id.
90 */ 78 */
91static struct smoothing *smooth=NULL; 79static struct smoothing *smooth = NULL;
92int nrofsmooth=0; 80int nrofsmooth = 0;
93 81
94/* the only thing this table is used for now is to 82/* the only thing this table is used for now is to
95 * translate the colorname in the magicmap field of the 83 * translate the colorname in the magicmap field of the
96 * face into a numeric index that is then sent to the 84 * face into a numeric index that is then sent to the
97 * client for magic map commands. The order of this table 85 * client for magic map commands. The order of this table
98 * must match that of the NDI colors in include/newclient.h. 86 * must match that of the NDI colors in include/newclient.h.
99 */ 87 */
100static const char *const colorname[] = { 88static const char *const colorname[] = {
101"black", /* 0 */ 89 "black", /* 0 */
102"white", /* 1 */ 90 "white", /* 1 */
103"blue", /* 2 */ 91 "blue", /* 2 */
104"red", /* 3 */ 92 "red", /* 3 */
105"orange", /* 4 */ 93 "orange", /* 4 */
106"light_blue", /* 5 */ 94 "light_blue", /* 5 */
107"dark_orange", /* 6 */ 95 "dark_orange", /* 6 */
108"green", /* 7 */ 96 "green", /* 7 */
109"light_green", /* 8 */ 97 "light_green", /* 8 */
110"grey", /* 9 */ 98 "grey", /* 9 */
111"brown", /* 10 */ 99 "brown", /* 10 */
112"yellow", /* 11 */ 100 "yellow", /* 11 */
113"khaki" /* 12 */ 101 "khaki" /* 12 */
114}; 102};
115 103
104static int
116static int compar (const struct bmappair *a, const struct bmappair *b) { 105compar (const struct bmappair *a, const struct bmappair *b)
106{
117 return strcmp (a->name, b->name); 107 return strcmp (a->name, b->name);
118} 108}
109
110static int
119static int compar_smooth (const struct smoothing *a, const struct smoothing *b) { 111compar_smooth (const struct smoothing *a, const struct smoothing *b)
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;
124 return 0; 116 return 1;
117 return 0;
125} 118}
126
127 119
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 125static uint8
134static uint8 find_color(const char *name) { 126find_color (const char *name)
127{
135 uint8 i; 128 uint8 i;
129
136 for(i=0;i<sizeof(colorname)/sizeof(*colorname);i++) 130 for (i = 0; i < sizeof (colorname) / sizeof (*colorname); i++)
137 if(!strcmp(name,colorname[i])) 131 if (!strcmp (name, colorname[i]))
138 return i; 132 return i;
139 LOG(llevError,"Unknown color: %s\n",name); 133 LOG (llevError, "Unknown color: %s\n", name);
140 return 0; 134 return 0;
141} 135}
142 136
143/* This reads the lib/faces file, getting color and visibility information. 137/* This reads the lib/faces file, getting color and visibility information.
144 * it is called by ReadBmapNames. 138 * it is called by ReadBmapNames.
145 */ 139 */
146 140static void
147static void ReadFaceData(void) 141ReadFaceData (void)
148{ 142{
149 char buf[MAX_BUF], *cp; 143 char buf[MAX_BUF], *cp;
150 New_Face *on_face=NULL; 144 facetile *on_face = NULL;
151 FILE *fp; 145 FILE *fp;
152 146
153 sprintf(buf,"%s/faces", settings.datadir); 147 sprintf (buf, "%s/faces", settings.datadir);
154 LOG(llevDebug,"Reading faces from %s...",buf); 148 LOG (llevDebug, "Reading faces from %s...\n", buf);
155 if ((fp=fopen(buf,"r"))==NULL) { 149 if ((fp = fopen (buf, "r")) == NULL)
150 {
156 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));
157 exit(-1); 152 exit (-1);
158 } 153 }
159 while (fgets(buf, MAX_BUF, fp)!=NULL) { 154 while (fgets (buf, MAX_BUF, fp) != NULL)
160 if (*buf=='#') continue; 155 {
156 if (*buf == '#')
157 continue;
161 if (!strncmp(buf,"end",3)) { 158 if (!strncmp (buf, "end", 3))
159 {
162 on_face = NULL; 160 on_face = NULL;
163 } 161 }
164 else if (!strncmp(buf,"face",4)) { 162 else if (!strncmp (buf, "face", 4))
163 {
165 int tmp; 164 int tmp;
166 165
167 cp = buf + 5; 166 cp = buf + 5;
168 cp[strlen(cp)-1] = '\0'; /* remove newline */ 167 cp[strlen (cp) - 1] = '\0'; /* remove newline */
169 168
170 if ((tmp=FindFace(cp,-1))==-1) { 169 if ((tmp = FindFace (cp, -1)) == -1)
170 {
171 LOG(llevError,"Could not find face %s\n", cp); 171 LOG (llevError, "Could not find face %s\n", cp);
172 continue; 172 continue;
173 } 173 }
174 on_face = &new_faces[tmp]; 174 on_face = &new_faces[tmp];
175 on_face->visibility=0; 175 on_face->visibility = 0;
176 } 176 }
177 else if (on_face==NULL) { 177 else if (on_face == NULL)
178 {
178 LOG(llevError,"Got line with no face set: %s\n", buf); 179 LOG (llevError, "Got line with no face set: %s\n", buf);
179 } 180 }
180 else if (!strncmp(buf,"color_fg",8)) { 181 else if (!strncmp (buf, "color_fg", 8))
182 {
181 cp = buf + 9; 183 cp = buf + 9;
182 cp[strlen(cp)-1] = '\0'; 184 cp[strlen (cp) - 1] = '\0';
183 if (on_face->magicmap==255) on_face->magicmap=find_color(cp); 185 if (on_face->magicmap == 255)
186 on_face->magicmap = find_color (cp);
184 } 187 }
185 else if (!strncmp(buf,"color_bg",8)) { 188 else if (!strncmp (buf, "color_bg", 8))
189 {
186 /* ignore it */ 190 /* ignore it */
187 } 191 }
188 else if (!strncmp(buf,"visibility",10)) { 192 else if (!strncmp (buf, "visibility", 10))
193 {
189 on_face->visibility = atoi(buf + 11); 194 on_face->visibility = atoi (buf + 11);
190 } 195 }
191 else if (!strncmp(buf,"magicmap",8)) { 196 else if (!strncmp (buf, "magicmap", 8))
197 {
192 cp=buf+9; 198 cp = buf + 9;
193 cp[strlen(cp)-1] = '\0'; 199 cp[strlen (cp) - 1] = '\0';
194 on_face->magicmap=find_color(cp); 200 on_face->magicmap = find_color (cp);
195 } 201 }
196 else if (!strncmp(buf,"is_floor",8)) { 202 else if (!strncmp (buf, "is_floor", 8))
203 {
197 int value = atoi(buf+9); 204 int value = atoi (buf + 9);
205
206 if (value)
198 if (value) on_face->magicmap |= FACE_FLOOR; 207 on_face->magicmap |= FACE_FLOOR;
199 } 208 }
209 else
200 else LOG(llevDebug,"Got unknown line in faces file: %s\n", buf); 210 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf);
201 } 211 }
212
202 LOG(llevDebug,"done\n"); 213 LOG (llevDebug, "done\n");
203 fclose(fp); 214 fclose (fp);
204} 215}
205 216
206/* 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
207 * 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
208 * 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
209 * difference.) 220 * difference.)
210 */ 221 */
211 222void
212void ReadBmapNames (void) { 223ReadBmapNames (void)
224{
213 char buf[MAX_BUF], *p, *q; 225 char buf[MAX_BUF], *p, *q;
214 FILE *fp; 226 FILE *fp;
215 int value, nrofbmaps = 0, i; 227 int value, nrofbmaps = 0, i;
216 size_t l; 228 size_t l;
217 229
218 bmaps_checksum=0; 230 bmaps_checksum = 0;
219 sprintf (buf,"%s/bmaps", settings.datadir); 231 sprintf (buf, "%s/bmaps", settings.datadir);
220 LOG(llevDebug,"Reading bmaps from %s...",buf); 232 LOG (llevDebug, "Reading bmaps from %s...\n", buf);
221 if ((fp=fopen(buf,"r"))==NULL) { 233 if ((fp = fopen (buf, "r")) == NULL)
234 {
222 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));
223 exit(-1); 236 exit (-1);
224 }
225 237 }
238
226 /* First count how many bitmaps we have, so we can allocate correctly */ 239 /* First count how many bitmaps we have, so we can allocate correctly */
227 while (fgets (buf, MAX_BUF, fp)!=NULL) 240 while (fgets (buf, MAX_BUF, fp) != NULL)
228 if(buf[0] != '#' && buf[0] != '\n' ) 241 if (buf[0] != '#' && buf[0] != '\n')
229 nrofbmaps++; 242 nrofbmaps++;
230 rewind(fp); 243 rewind (fp);
231 244
232 xbm = new bmappair [nrofbmaps]; 245 xbm = new bmappair[nrofbmaps];
233 memset (xbm, 0, sizeof (struct bmappair) * nrofbmaps); 246 memset (xbm, 0, sizeof (struct bmappair) * nrofbmaps);
234 247
235 while(nroffiles < nrofbmaps && fgets (buf, MAX_BUF, fp) != NULL) { 248 while (nroffiles < nrofbmaps && fgets (buf, MAX_BUF, fp) != NULL)
249 {
236 if (*buf == '#') 250 if (*buf == '#')
237 continue; 251 continue;
238 252
239 p = (*buf == '\\') ? (buf + 1): buf; 253 p = (*buf == '\\') ? (buf + 1) : buf;
240 if (!(p = strtok (p , " \t")) || !(q = strtok (NULL , " \t\n"))) { 254 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n")))
255 {
241 LOG(llevDebug,"Warning, syntax error: %s\n", buf); 256 LOG (llevDebug, "Warning, syntax error: %s\n", buf);
242 continue; 257 continue;
243 } 258 }
244 value = atoi (p); 259 value = atoi (p);
245 xbm[nroffiles].name = strdup_local(q); 260 xbm[nroffiles].name = strdup (q);
246 261
247 /* We need to calculate the checksum of the bmaps file 262 /* We need to calculate the checksum of the bmaps file
248 * name->number mapping to send to the client. This does not 263 * name->number mapping to send to the client. This does not
249 * 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 -
250 * 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
251 * data, it does the job as it lets the client know if 266 * data, it does the job as it lets the client know if
252 * the file has the same data or not. 267 * the file has the same data or not.
253 */ 268 */
254 ROTATE_RIGHT(bmaps_checksum); 269 ROTATE_RIGHT (bmaps_checksum);
255 bmaps_checksum += value & 0xff; 270 bmaps_checksum += value & 0xff;
256 bmaps_checksum &= 0xffffffff; 271 bmaps_checksum &= 0xffffffff;
257 272
258 ROTATE_RIGHT(bmaps_checksum); 273 ROTATE_RIGHT (bmaps_checksum);
259 bmaps_checksum += (value >> 8) & 0xff; 274 bmaps_checksum += (value >> 8) & 0xff;
260 bmaps_checksum &= 0xffffffff; 275 bmaps_checksum &= 0xffffffff;
261 for (l=0; l<strlen(q); l++) { 276 for (l = 0; l < strlen (q); l++)
277 {
262 ROTATE_RIGHT(bmaps_checksum); 278 ROTATE_RIGHT (bmaps_checksum);
263 bmaps_checksum += q[l]; 279 bmaps_checksum += q[l];
264 bmaps_checksum &= 0xffffffff; 280 bmaps_checksum &= 0xffffffff;
265 } 281 }
266 282
267 xbm[nroffiles].number = value; 283 xbm[nroffiles].number = value;
268 nroffiles++; 284 nroffiles++;
269 if(value >= nrofpixmaps) 285 if (value >= nrofpixmaps)
270 nrofpixmaps = value+1; 286 nrofpixmaps = value + 1;
271 } 287 }
272 fclose(fp); 288 fclose (fp);
273 289
274 LOG(llevDebug,"done (got %d/%d/%d)\n",nrofpixmaps,nrofbmaps,nroffiles); 290 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles);
275 291
276 new_faces = new New_Face [nrofpixmaps]; 292 new_faces = new facetile[nrofpixmaps];
293
277 for (i = 0; i < nrofpixmaps; i++) { 294 for (i = 0; i < nrofpixmaps; i++)
295 {
278 new_faces[i].name = ""; 296 new_faces[i].name = "";
279 new_faces[i].number = i; 297 new_faces[i].number = i;
280 new_faces[i].visibility=0; 298 new_faces[i].visibility = 0;
281 new_faces[i].magicmap=255; 299 new_faces[i].magicmap = 255;
282 } 300 }
301
283 for (i = 0; i < nroffiles; i++) { 302 for (i = 0; i < nroffiles; i++)
284 new_faces[xbm[i].number].name = xbm[i].name; 303 new_faces[xbm[i].number].name = xbm[i].name;
285 }
286 304
287 // non-pod datatype, likely not allowed 305 // non-pod datatype, likely not allowed
288 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);
289 307
290 ReadFaceData(); 308 ReadFaceData ();
291 309
292 for (i = 0; i < nrofpixmaps; i++) { 310 for (i = 0; i < nrofpixmaps; i++)
311 {
293 if (new_faces[i].magicmap==255) { 312 if (new_faces[i].magicmap == 255)
313 {
294#if 0 /* Useful for initial debugging, not needed now */ 314#if 0 /* Useful for initial debugging, not needed now */
295 LOG(llevDebug,"Face %s still had default magicmap, resetting to black\n", 315 LOG (llevDebug, "Face %s still had default magicmap, resetting to black\n", new_faces[i].name);
296 new_faces[i].name);
297#endif 316#endif
298 new_faces[i].magicmap=0; 317 new_faces[i].magicmap = 0;
299 } 318 }
300 } 319 }
301 /* Actually forcefully setting the colors here probably should not 320 /* Actually forcefully setting the colors here probably should not
302 * be done - it could easily create confusion. 321 * be done - it could easily create confusion.
303 */ 322 */
304 blank_face = &new_faces[FindFace(BLANK_FACE_NAME, 0)]; 323 blank_face = &new_faces[FindFace (BLANK_FACE_NAME, 0)];
305 blank_face->magicmap = find_color ("khaki") | FACE_FLOOR; 324 blank_face->magicmap = find_color ("khaki") | FACE_FLOOR;
306 325
307 empty_face = &new_faces[FindFace(EMPTY_FACE_NAME, 0)]; 326 empty_face = &new_faces[FindFace (EMPTY_FACE_NAME, 0)];
308 327
309 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME,0)]; 328 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)];
310 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME,0)]; 329 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)];
311 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME,0)]; 330 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)];
312 331
313 smooth_face = &new_faces[FindFace(SMOOTH_FACE_NAME,0)]; 332 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)];
314} 333}
315 334
316/* This returns an the face number of face 'name'. Number is constant 335/* This returns an the face number of face 'name'. Number is constant
317 * during an invocation, but not necessarily between versions (this 336 * during an invocation, but not necessarily between versions (this
318 * is because the faces are arranged in alphabetical order, so 337 * is because the faces are arranged in alphabetical order, so
324 * you want some default face used, or can be set to negative 343 * you want some default face used, or can be set to negative
325 * so that it will be known that the face could not be found 344 * so that it will be known that the face could not be found
326 * (needed in client, so that it will know to request that image 345 * (needed in client, so that it will know to request that image
327 * from the server) 346 * from the server)
328 */ 347 */
348int
329int FindFace (const char *name, int error) { 349FindFace (const char *name, int error)
350{
330 struct bmappair *bp, tmp; 351 struct bmappair *bp, tmp;
331 char *p; 352 char *p;
332 353
333 if (!name) 354 if (!name)
334 return error; 355 return error;
335 356
336 if ((p = strchr (name, '\n'))) 357 if ((p = strchr (name, '\n')))
337 *p = '\0'; 358 *p = '\0';
338 359
339 tmp.name = (char *)name; 360 tmp.name = (char *) name;
340 bp = (struct bmappair *)bsearch
341 (&tmp, xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar); 361 bp = (struct bmappair *) bsearch (&tmp, xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar);
342 362
343 return bp ? bp->number : error; 363 return bp ? bp->number : error;
344} 364}
345 365
346/* Reads the smooth file to know how to smooth datas. 366/* Reads the smooth file to know how to smooth datas.
347 * the smooth file if made of 2 elements lines. 367 * the smooth file if made of 2 elements lines.
348 * lines starting with # are comment 368 * lines starting with # are comment
349 * the first element of line is face to smooth 369 * the first element of line is face to smooth
350 * the next element is the 16x2 faces picture 370 * the next element is the 16x2 faces picture
351 * used for smoothing 371 * used for smoothing
352 */ 372 */
373int
353int ReadSmooth (void) { 374ReadSmooth (void)
375{
354 char buf[MAX_BUF], *p, *q; 376 char buf[MAX_BUF], *p, *q;
355 FILE *fp; 377 FILE *fp;
356 int smoothcount = 0; 378 int smoothcount = 0;
357 379
358 bmaps_checksum=0; 380 bmaps_checksum = 0;
359 sprintf (buf,"%s/smooth", settings.datadir); 381 sprintf (buf, "%s/smooth", settings.datadir);
360 LOG(llevDebug,"Reading smooth from %s...",buf); 382 LOG (llevDebug, "Reading smooth from %s...\n", buf);
361 if ((fp=fopen(buf,"r"))==NULL) { 383 if ((fp = fopen (buf, "r")) == NULL)
384 {
362 LOG(llevError, "Cannot open smooth file %s: %s\n", strerror(errno)); 385 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno));
363 exit(-1); 386 exit (-1);
364 } 387 }
365 388
366 /* First count how many smooth we have, so we can allocate correctly */ 389 /* First count how many smooth we have, so we can allocate correctly */
367 while (fgets (buf, MAX_BUF, fp)!=NULL) 390 while (fgets (buf, MAX_BUF, fp) != NULL)
368 if(buf[0] != '#' && buf[0] != '\n' ) 391 if (buf[0] != '#' && buf[0] != '\n')
369 smoothcount++; 392 smoothcount++;
370 rewind(fp); 393 rewind (fp);
371 394
372 smooth = new smoothing [smoothcount]; 395 smooth = new smoothing[smoothcount];
373 396
374 while(nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp)!=NULL) { 397 while (nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp) != NULL)
398 {
375 if (*buf == '#') 399 if (*buf == '#')
376 continue; 400 continue;
377 p=strchr(buf,' '); 401 p = strchr (buf, ' ');
378 if (!p) 402 if (!p)
379 continue; 403 continue;
380 *p='\0'; 404 *p = '\0';
381 q=buf; 405 q = buf;
382 smooth[nrofsmooth].id=FindFace(q,0); 406 smooth[nrofsmooth].id = FindFace (q, 0);
383 q=p+1; 407 q = p + 1;
384 smooth[nrofsmooth].smooth=FindFace(q,0); 408 smooth[nrofsmooth].smooth = FindFace (q, 0);
385 nrofsmooth++; 409 nrofsmooth++;
386 } 410 }
387 fclose(fp); 411 fclose (fp);
388 412
389 LOG(llevDebug,"done (got %d smooth entries)\n",nrofsmooth); 413 LOG (llevDebug, "done (got %d smooth entries)\n", nrofsmooth);
390 qsort (smooth, nrofsmooth, sizeof(struct smoothing), (int (*)(const void*, const void*))compar_smooth); 414 qsort (smooth, nrofsmooth, sizeof (struct smoothing), (int (*)(const void *, const void *)) compar_smooth);
391 return nrofsmooth; 415 return nrofsmooth;
392} 416}
393 417
394/** 418/**
395 * Find the smooth face for a given face. 419 * Find the smooth face for a given face.
396 * 420 *
398 * 422 *
399 * @param smoothed return value: set to smooth face 423 * @param smoothed return value: set to smooth face
400 * 424 *
401 * @return 1=smooth face found, 0=no smooth face found 425 * @return 1=smooth face found, 0=no smooth face found
402 */ 426 */
427int
403int FindSmooth (uint16 face, uint16* smoothed) { 428FindSmooth (uint16 face, uint16 * smoothed)
429{
404 struct smoothing *bp, tmp; 430 struct smoothing *bp, tmp;
405 431
406 tmp.id = face; 432 tmp.id = face;
407 bp = (struct smoothing *)bsearch 433 bp = (struct smoothing *) bsearch
408 (&tmp, smooth, nrofsmooth, sizeof(struct smoothing), (int (*)(const void*, const void*))compar_smooth); 434 (&tmp, smooth, nrofsmooth, sizeof (struct smoothing), (int (*)(const void *, const void *)) compar_smooth);
409 (*smoothed)=0; 435 (*smoothed) = 0;
410 if (bp) 436 if (bp)
411 (*smoothed)=bp->smooth; 437 (*smoothed) = bp->smooth;
412 return bp ? 1 : 0; 438 return bp ? 1 : 0;
413} 439}
414 440
415/** 441/**
416 * Deallocates memory allocated by ReadBmapNames() and ReadSmooth(). 442 * Deallocates memory allocated by ReadBmapNames() and ReadSmooth().
417 */ 443 */
444void
418void free_all_images(void) 445free_all_images (void)
419{ 446{
420 int i; 447 int i;
421 448
422 for (i=0; i<nroffiles; i++) 449 for (i = 0; i < nroffiles; i++)
423 free(xbm[i].name); 450 free (xbm[i].name);
424 451
425 delete [] xbm; 452 delete[]xbm;
426 delete [] new_faces; 453 delete[]new_faces;
427 delete [] smooth; 454 delete[]smooth;
428} 455}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines