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.11 by root, Wed Jan 10 19:52:43 2007 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
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}
117
118static int
119static int compar_smooth (const struct smoothing *a, const struct smoothing *b) { 119compar_smooth (const struct smoothing *a, const struct smoothing *b)
120{
120 if (a->id<b->id) 121 if (a->id < b->id)
121 return -1; 122 return -1;
122 if (b->id<a->id) 123 if (b->id < a->id)
123 return 1;
124 return 0; 124 return 1;
125 return 0;
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 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 148static void
147static void ReadFaceData(void) 149ReadFaceData (void)
148{ 150{
149 char buf[MAX_BUF], *cp; 151 char buf[MAX_BUF], *cp;
150 New_Face *on_face=NULL; 152 New_Face *on_face = NULL;
151 FILE *fp; 153 FILE *fp;
152 154
153 sprintf(buf,"%s/faces", settings.datadir); 155 sprintf (buf, "%s/faces", settings.datadir);
154 LOG(llevDebug,"Reading faces from %s...",buf); 156 LOG (llevDebug, "Reading faces from %s...\n", buf);
155 if ((fp=fopen(buf,"r"))==NULL) { 157 if ((fp = fopen (buf, "r")) == NULL)
158 {
156 LOG(llevError, "Cannot open faces file %s: %s\n", buf, strerror(errno)); 159 LOG (llevError, "Cannot open faces file %s: %s\n", buf, strerror (errno));
157 exit(-1); 160 exit (-1);
158 } 161 }
159 while (fgets(buf, MAX_BUF, fp)!=NULL) { 162 while (fgets (buf, MAX_BUF, fp) != NULL)
160 if (*buf=='#') continue; 163 {
164 if (*buf == '#')
165 continue;
161 if (!strncmp(buf,"end",3)) { 166 if (!strncmp (buf, "end", 3))
167 {
162 on_face = NULL; 168 on_face = NULL;
163 } 169 }
164 else if (!strncmp(buf,"face",4)) { 170 else if (!strncmp (buf, "face", 4))
171 {
165 int tmp; 172 int tmp;
166 173
167 cp = buf + 5; 174 cp = buf + 5;
168 cp[strlen(cp)-1] = '\0'; /* remove newline */ 175 cp[strlen (cp) - 1] = '\0'; /* remove newline */
169 176
170 if ((tmp=FindFace(cp,-1))==-1) { 177 if ((tmp = FindFace (cp, -1)) == -1)
178 {
171 LOG(llevError,"Could not find face %s\n", cp); 179 LOG (llevError, "Could not find face %s\n", cp);
172 continue; 180 continue;
173 } 181 }
174 on_face = &new_faces[tmp]; 182 on_face = &new_faces[tmp];
175 on_face->visibility=0; 183 on_face->visibility = 0;
176 } 184 }
177 else if (on_face==NULL) { 185 else if (on_face == NULL)
186 {
178 LOG(llevError,"Got line with no face set: %s\n", buf); 187 LOG (llevError, "Got line with no face set: %s\n", buf);
179 } 188 }
180 else if (!strncmp(buf,"color_fg",8)) { 189 else if (!strncmp (buf, "color_fg", 8))
190 {
181 cp = buf + 9; 191 cp = buf + 9;
182 cp[strlen(cp)-1] = '\0'; 192 cp[strlen (cp) - 1] = '\0';
183 if (on_face->magicmap==255) on_face->magicmap=find_color(cp); 193 if (on_face->magicmap == 255)
194 on_face->magicmap = find_color (cp);
184 } 195 }
185 else if (!strncmp(buf,"color_bg",8)) { 196 else if (!strncmp (buf, "color_bg", 8))
197 {
186 /* ignore it */ 198 /* ignore it */
187 } 199 }
188 else if (!strncmp(buf,"visibility",10)) { 200 else if (!strncmp (buf, "visibility", 10))
201 {
189 on_face->visibility = atoi(buf + 11); 202 on_face->visibility = atoi (buf + 11);
190 } 203 }
191 else if (!strncmp(buf,"magicmap",8)) { 204 else if (!strncmp (buf, "magicmap", 8))
205 {
192 cp=buf+9; 206 cp = buf + 9;
193 cp[strlen(cp)-1] = '\0'; 207 cp[strlen (cp) - 1] = '\0';
194 on_face->magicmap=find_color(cp); 208 on_face->magicmap = find_color (cp);
195 } 209 }
196 else if (!strncmp(buf,"is_floor",8)) { 210 else if (!strncmp (buf, "is_floor", 8))
211 {
197 int value = atoi(buf+9); 212 int value = atoi (buf + 9);
213
214 if (value)
198 if (value) on_face->magicmap |= FACE_FLOOR; 215 on_face->magicmap |= FACE_FLOOR;
199 } 216 }
217 else
200 else LOG(llevDebug,"Got unknown line in faces file: %s\n", buf); 218 LOG (llevDebug, "Got unknown line in faces file: %s\n", buf);
201 } 219 }
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 230void
212void ReadBmapNames (void) { 231ReadBmapNames (void)
232{
213 char buf[MAX_BUF], *p, *q; 233 char buf[MAX_BUF], *p, *q;
214 FILE *fp; 234 FILE *fp;
215 int value, nrofbmaps = 0, i; 235 int value, nrofbmaps = 0, i;
216 size_t l; 236 size_t l;
217 237
218 bmaps_checksum=0; 238 bmaps_checksum = 0;
219 sprintf (buf,"%s/bmaps", settings.datadir); 239 sprintf (buf, "%s/bmaps", settings.datadir);
220 LOG(llevDebug,"Reading bmaps from %s...",buf); 240 LOG (llevDebug, "Reading bmaps from %s...\n", buf);
221 if ((fp=fopen(buf,"r"))==NULL) { 241 if ((fp = fopen (buf, "r")) == NULL)
242 {
222 LOG(llevError, "Cannot open bmaps file %s: %s\n", buf, strerror(errno)); 243 LOG (llevError, "Cannot open bmaps file %s: %s\n", buf, strerror (errno));
223 exit(-1); 244 exit (-1);
224 }
225 245 }
246
226 /* First count how many bitmaps we have, so we can allocate correctly */ 247 /* First count how many bitmaps we have, so we can allocate correctly */
227 while (fgets (buf, MAX_BUF, fp)!=NULL) 248 while (fgets (buf, MAX_BUF, fp) != NULL)
228 if(buf[0] != '#' && buf[0] != '\n' ) 249 if (buf[0] != '#' && buf[0] != '\n')
229 nrofbmaps++; 250 nrofbmaps++;
230 rewind(fp); 251 rewind (fp);
231 252
232 xbm = new bmappair [nrofbmaps]; 253 xbm = new bmappair[nrofbmaps];
233 memset (xbm, 0, sizeof (struct bmappair) * nrofbmaps); 254 memset (xbm, 0, sizeof (struct bmappair) * nrofbmaps);
234 255
235 while(nroffiles < nrofbmaps && fgets (buf, MAX_BUF, fp) != NULL) { 256 while (nroffiles < nrofbmaps && fgets (buf, MAX_BUF, fp) != NULL)
257 {
236 if (*buf == '#') 258 if (*buf == '#')
237 continue; 259 continue;
238 260
239 p = (*buf == '\\') ? (buf + 1): buf; 261 p = (*buf == '\\') ? (buf + 1) : buf;
240 if (!(p = strtok (p , " \t")) || !(q = strtok (NULL , " \t\n"))) { 262 if (!(p = strtok (p, " \t")) || !(q = strtok (NULL, " \t\n")))
263 {
241 LOG(llevDebug,"Warning, syntax error: %s\n", buf); 264 LOG (llevDebug, "Warning, syntax error: %s\n", buf);
242 continue; 265 continue;
243 } 266 }
244 value = atoi (p); 267 value = atoi (p);
245 xbm[nroffiles].name = strdup_local(q); 268 xbm[nroffiles].name = strdup (q);
246 269
247 /* We need to calculate the checksum of the bmaps file 270 /* We need to calculate the checksum of the bmaps file
248 * name->number mapping to send to the client. This does not 271 * name->number mapping to send to the client. This does not
249 * need to match what sum or other utility may come up with - 272 * 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 273 * 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 274 * data, it does the job as it lets the client know if
252 * the file has the same data or not. 275 * the file has the same data or not.
253 */ 276 */
254 ROTATE_RIGHT(bmaps_checksum); 277 ROTATE_RIGHT (bmaps_checksum);
255 bmaps_checksum += value & 0xff; 278 bmaps_checksum += value & 0xff;
256 bmaps_checksum &= 0xffffffff; 279 bmaps_checksum &= 0xffffffff;
257 280
258 ROTATE_RIGHT(bmaps_checksum); 281 ROTATE_RIGHT (bmaps_checksum);
259 bmaps_checksum += (value >> 8) & 0xff; 282 bmaps_checksum += (value >> 8) & 0xff;
260 bmaps_checksum &= 0xffffffff; 283 bmaps_checksum &= 0xffffffff;
261 for (l=0; l<strlen(q); l++) { 284 for (l = 0; l < strlen (q); l++)
285 {
262 ROTATE_RIGHT(bmaps_checksum); 286 ROTATE_RIGHT (bmaps_checksum);
263 bmaps_checksum += q[l]; 287 bmaps_checksum += q[l];
264 bmaps_checksum &= 0xffffffff; 288 bmaps_checksum &= 0xffffffff;
265 } 289 }
266 290
267 xbm[nroffiles].number = value; 291 xbm[nroffiles].number = value;
268 nroffiles++; 292 nroffiles++;
269 if(value >= nrofpixmaps) 293 if (value >= nrofpixmaps)
270 nrofpixmaps = value+1; 294 nrofpixmaps = value + 1;
271 } 295 }
272 fclose(fp); 296 fclose (fp);
273 297
274 LOG(llevDebug,"done (got %d/%d/%d)\n",nrofpixmaps,nrofbmaps,nroffiles); 298 LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles);
275 299
276 new_faces = new New_Face [nrofpixmaps]; 300 new_faces = new New_Face[nrofpixmaps];
301
277 for (i = 0; i < nrofpixmaps; i++) { 302 for (i = 0; i < nrofpixmaps; i++)
303 {
278 new_faces[i].name = ""; 304 new_faces[i].name = "";
279 new_faces[i].number = i; 305 new_faces[i].number = i;
280 new_faces[i].visibility=0; 306 new_faces[i].visibility = 0;
281 new_faces[i].magicmap=255; 307 new_faces[i].magicmap = 255;
282 } 308 }
283 for (i = 0; i < nroffiles; i++) { 309 for (i = 0; i < nroffiles; i++)
310 {
284 new_faces[xbm[i].number].name = xbm[i].name; 311 new_faces[xbm[i].number].name = xbm[i].name;
285 } 312 }
286 313
287 // non-pod datatype, likely not allowed 314 // non-pod datatype, likely not allowed
288 qsort (xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar); 315 qsort (xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar);
289 316
290 ReadFaceData(); 317 ReadFaceData ();
291 318
292 for (i = 0; i < nrofpixmaps; i++) { 319 for (i = 0; i < nrofpixmaps; i++)
320 {
293 if (new_faces[i].magicmap==255) { 321 if (new_faces[i].magicmap == 255)
322 {
294#if 0 /* Useful for initial debugging, not needed now */ 323#if 0 /* Useful for initial debugging, not needed now */
295 LOG(llevDebug,"Face %s still had default magicmap, resetting to black\n", 324 LOG (llevDebug, "Face %s still had default magicmap, resetting to black\n", new_faces[i].name);
296 new_faces[i].name);
297#endif 325#endif
298 new_faces[i].magicmap=0; 326 new_faces[i].magicmap = 0;
299 } 327 }
300 } 328 }
301 /* Actually forcefully setting the colors here probably should not 329 /* Actually forcefully setting the colors here probably should not
302 * be done - it could easily create confusion. 330 * be done - it could easily create confusion.
303 */ 331 */
304 blank_face = &new_faces[FindFace(BLANK_FACE_NAME, 0)]; 332 blank_face = &new_faces[FindFace (BLANK_FACE_NAME, 0)];
305 blank_face->magicmap = find_color ("khaki") | FACE_FLOOR; 333 blank_face->magicmap = find_color ("khaki") | FACE_FLOOR;
306 334
307 empty_face = &new_faces[FindFace(EMPTY_FACE_NAME, 0)]; 335 empty_face = &new_faces[FindFace (EMPTY_FACE_NAME, 0)];
308 336
309 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME,0)]; 337 dark_faces[0] = &new_faces[FindFace (DARK_FACE1_NAME, 0)];
310 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME,0)]; 338 dark_faces[1] = &new_faces[FindFace (DARK_FACE2_NAME, 0)];
311 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME,0)]; 339 dark_faces[2] = &new_faces[FindFace (DARK_FACE3_NAME, 0)];
312 340
313 smooth_face = &new_faces[FindFace(SMOOTH_FACE_NAME,0)]; 341 smooth_face = &new_faces[FindFace (SMOOTH_FACE_NAME, 0)];
314} 342}
315 343
316/* This returns an the face number of face 'name'. Number is constant 344/* This returns an the face number of face 'name'. Number is constant
317 * during an invocation, but not necessarily between versions (this 345 * during an invocation, but not necessarily between versions (this
318 * is because the faces are arranged in alphabetical order, so 346 * is because the faces are arranged in alphabetical order, so
324 * you want some default face used, or can be set to negative 352 * 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 353 * 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 354 * (needed in client, so that it will know to request that image
327 * from the server) 355 * from the server)
328 */ 356 */
357int
329int FindFace (const char *name, int error) { 358FindFace (const char *name, int error)
359{
330 struct bmappair *bp, tmp; 360 struct bmappair *bp, tmp;
331 char *p; 361 char *p;
332 362
363 if (!name)
364 return error;
365
333 if ((p = strchr (name, '\n'))) 366 if ((p = strchr (name, '\n')))
334 *p = '\0'; 367 *p = '\0';
335 368
336 tmp.name = (char *)name; 369 tmp.name = (char *) name;
337 bp = (struct bmappair *)bsearch
338 (&tmp, xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar); 370 bp = (struct bmappair *) bsearch (&tmp, xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar);
339 371
340 return bp ? bp->number : error; 372 return bp ? bp->number : error;
341} 373}
342 374
343/* Reads the smooth file to know how to smooth datas. 375/* Reads the smooth file to know how to smooth datas.
344 * the smooth file if made of 2 elements lines. 376 * the smooth file if made of 2 elements lines.
345 * lines starting with # are comment 377 * lines starting with # are comment
346 * the first element of line is face to smooth 378 * the first element of line is face to smooth
347 * the next element is the 16x2 faces picture 379 * the next element is the 16x2 faces picture
348 * used for smoothing 380 * used for smoothing
349 */ 381 */
382int
350int ReadSmooth (void) { 383ReadSmooth (void)
384{
351 char buf[MAX_BUF], *p, *q; 385 char buf[MAX_BUF], *p, *q;
352 FILE *fp; 386 FILE *fp;
353 int smoothcount = 0; 387 int smoothcount = 0;
354 388
355 bmaps_checksum=0; 389 bmaps_checksum = 0;
356 sprintf (buf,"%s/smooth", settings.datadir); 390 sprintf (buf, "%s/smooth", settings.datadir);
357 LOG(llevDebug,"Reading smooth from %s...",buf); 391 LOG (llevDebug, "Reading smooth from %s...\n", buf);
358 if ((fp=fopen(buf,"r"))==NULL) { 392 if ((fp = fopen (buf, "r")) == NULL)
393 {
359 LOG(llevError, "Cannot open smooth file %s: %s\n", strerror(errno)); 394 LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno));
360 exit(-1); 395 exit (-1);
361 } 396 }
362 397
363 /* First count how many smooth we have, so we can allocate correctly */ 398 /* First count how many smooth we have, so we can allocate correctly */
364 while (fgets (buf, MAX_BUF, fp)!=NULL) 399 while (fgets (buf, MAX_BUF, fp) != NULL)
365 if(buf[0] != '#' && buf[0] != '\n' ) 400 if (buf[0] != '#' && buf[0] != '\n')
366 smoothcount++; 401 smoothcount++;
367 rewind(fp); 402 rewind (fp);
368 403
369 smooth = new smoothing [smoothcount]; 404 smooth = new smoothing[smoothcount];
370 405
371 while(nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp)!=NULL) { 406 while (nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp) != NULL)
407 {
372 if (*buf == '#') 408 if (*buf == '#')
373 continue; 409 continue;
374 p=strchr(buf,' '); 410 p = strchr (buf, ' ');
375 if (!p) 411 if (!p)
376 continue; 412 continue;
377 *p='\0'; 413 *p = '\0';
378 q=buf; 414 q = buf;
379 smooth[nrofsmooth].id=FindFace(q,0); 415 smooth[nrofsmooth].id = FindFace (q, 0);
380 q=p+1; 416 q = p + 1;
381 smooth[nrofsmooth].smooth=FindFace(q,0); 417 smooth[nrofsmooth].smooth = FindFace (q, 0);
382 nrofsmooth++; 418 nrofsmooth++;
383 } 419 }
384 fclose(fp); 420 fclose (fp);
385 421
386 LOG(llevDebug,"done (got %d smooth entries)\n",nrofsmooth); 422 LOG (llevDebug, "done (got %d smooth entries)\n", nrofsmooth);
387 qsort (smooth, nrofsmooth, sizeof(struct smoothing), (int (*)(const void*, const void*))compar_smooth); 423 qsort (smooth, nrofsmooth, sizeof (struct smoothing), (int (*)(const void *, const void *)) compar_smooth);
388 return nrofsmooth; 424 return nrofsmooth;
389} 425}
390 426
391/** 427/**
392 * Find the smooth face for a given face. 428 * Find the smooth face for a given face.
393 * 429 *
395 * 431 *
396 * @param smoothed return value: set to smooth face 432 * @param smoothed return value: set to smooth face
397 * 433 *
398 * @return 1=smooth face found, 0=no smooth face found 434 * @return 1=smooth face found, 0=no smooth face found
399 */ 435 */
436int
400int FindSmooth (uint16 face, uint16* smoothed) { 437FindSmooth (uint16 face, uint16 * smoothed)
438{
401 struct smoothing *bp, tmp; 439 struct smoothing *bp, tmp;
402 440
403 tmp.id = face; 441 tmp.id = face;
404 bp = (struct smoothing *)bsearch 442 bp = (struct smoothing *) bsearch
405 (&tmp, smooth, nrofsmooth, sizeof(struct smoothing), (int (*)(const void*, const void*))compar_smooth); 443 (&tmp, smooth, nrofsmooth, sizeof (struct smoothing), (int (*)(const void *, const void *)) compar_smooth);
406 (*smoothed)=0; 444 (*smoothed) = 0;
407 if (bp) 445 if (bp)
408 (*smoothed)=bp->smooth; 446 (*smoothed) = bp->smooth;
409 return bp ? 1 : 0; 447 return bp ? 1 : 0;
410} 448}
411 449
412/** 450/**
413 * Deallocates memory allocated by ReadBmapNames() and ReadSmooth(). 451 * Deallocates memory allocated by ReadBmapNames() and ReadSmooth().
414 */ 452 */
453void
415void free_all_images(void) 454free_all_images (void)
416{ 455{
417 int i; 456 int i;
418 457
419 for (i=0; i<nroffiles; i++) 458 for (i = 0; i < nroffiles; i++)
420 free(xbm[i].name); 459 free (xbm[i].name);
421 460
422 delete [] xbm; 461 delete[]xbm;
423 delete [] new_faces; 462 delete[]new_faces;
424 delete [] smooth; 463 delete[]smooth;
425} 464}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines