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.4 by root, Mon Sep 4 11:07:59 2006 UTC vs.
Revision 1.8 by root, Thu Dec 14 22:45:40 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines