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.3 by root, Wed Aug 30 16:30:36 2006 UTC vs.
Revision 1.7 by root, Thu Sep 14 22:33:58 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines