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.10 by pippijn, Sat Jan 6 14:42:28 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines