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.4 by root, Mon Sep 4 11:07:59 2006 UTC

1/* 1/*
2 * static char *rcsid_image_c = 2 * static char *rcsid_image_c =
3 * "$Id: image.C,v 1.3 2006/08/30 16:30:36 root Exp $"; 3 * "$Id: image.C,v 1.4 2006/09/04 11:07:59 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
42 * that some number corresponds to the face at that number - for 42 * 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 43 * xbm, it may not. At current time, these do in fact match because
44 * the bmaps file is created in a sorted order. 44 * the bmaps file is created in a sorted order.
45 */ 45 */
46 46
47struct bmappair { 47struct bmappair
48{
48 char *name; 49 char *name;
49 unsigned int number; 50 unsigned int number;
50}; 51};
52
53void free (bmappair *); // guard to catch free when delete should be used
51 54
52static struct bmappair *xbm=NULL; 55static struct bmappair *xbm=NULL;
53 56
54/* Following can just as easily be pointers, but 57/* Following can just as easily be pointers, but
55 * it is easier to keep them like this. 58 * it is easier to keep them like this.
71int nrofpixmaps = 0; 74int nrofpixmaps = 0;
72 75
73/** 76/**
74 * id is the face to smooth, smooth is the 16x2 face used to smooth id. 77 * id is the face to smooth, smooth is the 16x2 face used to smooth id.
75 */ 78 */
76struct smoothing { 79struct smoothing : zero_initialised
80{
77 uint16 id; 81 uint16 id;
78 uint16 smooth; 82 uint16 smooth;
79}; 83};
84
85void free (smoothing *); // guard to catch free when delete should be used
80 86
81/** 87/**
82 * Contains all defined smoothing entries. smooth is an array of nrofsmooth 88 * Contains all defined smoothing entries. smooth is an array of nrofsmooth
83 * entries. It is sorted by smooth[].id. 89 * entries. It is sorted by smooth[].id.
84 */ 90 */
154 if (*buf=='#') continue; 160 if (*buf=='#') continue;
155 if (!strncmp(buf,"end",3)) { 161 if (!strncmp(buf,"end",3)) {
156 on_face = NULL; 162 on_face = NULL;
157 } 163 }
158 else if (!strncmp(buf,"face",4)) { 164 else if (!strncmp(buf,"face",4)) {
159 int tmp; 165 int tmp;
160 166
161 cp = buf + 5; 167 cp = buf + 5;
162 cp[strlen(cp)-1] = '\0'; /* remove newline */ 168 cp[strlen(cp)-1] = '\0'; /* remove newline */
163 169
164 if ((tmp=FindFace(cp,-1))==-1) { 170 if ((tmp=FindFace(cp,-1))==-1) {
165 LOG(llevError,"Could not find face %s\n", cp); 171 LOG(llevError,"Could not find face %s\n", cp);
166 continue; 172 continue;
167 } 173 }
168 on_face = &new_faces[tmp]; 174 on_face = &new_faces[tmp];
169 on_face->visibility=0; 175 on_face->visibility=0;
170 } 176 }
171 else if (on_face==NULL) { 177 else if (on_face==NULL) {
172 LOG(llevError,"Got line with no face set: %s\n", buf); 178 LOG(llevError,"Got line with no face set: %s\n", buf);
173 } 179 }
221 while (fgets (buf, MAX_BUF, fp)!=NULL) 227 while (fgets (buf, MAX_BUF, fp)!=NULL)
222 if(buf[0] != '#' && buf[0] != '\n' ) 228 if(buf[0] != '#' && buf[0] != '\n' )
223 nrofbmaps++; 229 nrofbmaps++;
224 rewind(fp); 230 rewind(fp);
225 231
226 xbm = (struct bmappair *) malloc(sizeof(struct bmappair) * nrofbmaps); 232 xbm = new bmappair [nrofbmaps];
227 memset (xbm, 0, sizeof (struct bmappair) * nrofbmaps); 233 memset (xbm, 0, sizeof (struct bmappair) * nrofbmaps);
228 234
229 while(nroffiles < nrofbmaps && fgets (buf, MAX_BUF, fp) != NULL) { 235 while(nroffiles < nrofbmaps && fgets (buf, MAX_BUF, fp) != NULL) {
230 if (*buf == '#') 236 if (*buf == '#')
231 continue; 237 continue;
265 } 271 }
266 fclose(fp); 272 fclose(fp);
267 273
268 LOG(llevDebug,"done (got %d/%d/%d)\n",nrofpixmaps,nrofbmaps,nroffiles); 274 LOG(llevDebug,"done (got %d/%d/%d)\n",nrofpixmaps,nrofbmaps,nroffiles);
269 275
270 new_faces = (New_Face *)malloc(sizeof(New_Face) * nrofpixmaps); 276 new_faces = new New_Face [nrofpixmaps];
271 for (i = 0; i < nrofpixmaps; i++) { 277 for (i = 0; i < nrofpixmaps; i++) {
272 new_faces[i].name = ""; 278 new_faces[i].name = "";
273 new_faces[i].number = i; 279 new_faces[i].number = i;
274 new_faces[i].visibility=0; 280 new_faces[i].visibility=0;
275 new_faces[i].magicmap=255; 281 new_faces[i].magicmap=255;
276 } 282 }
277 for (i = 0; i < nroffiles; i++) { 283 for (i = 0; i < nroffiles; i++) {
278 new_faces[xbm[i].number].name = xbm[i].name; 284 new_faces[xbm[i].number].name = xbm[i].name;
279 } 285 }
280 286
287 // non-pod datatype, likely not allowed
281 qsort (xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar); 288 qsort (xbm, nroffiles, sizeof(struct bmappair), (int (*)(const void*, const void*))compar);
282 289
283 ReadFaceData(); 290 ReadFaceData();
284 291
285 for (i = 0; i < nrofpixmaps; i++) { 292 for (i = 0; i < nrofpixmaps; i++) {
357 while (fgets (buf, MAX_BUF, fp)!=NULL) 364 while (fgets (buf, MAX_BUF, fp)!=NULL)
358 if(buf[0] != '#' && buf[0] != '\n' ) 365 if(buf[0] != '#' && buf[0] != '\n' )
359 smoothcount++; 366 smoothcount++;
360 rewind(fp); 367 rewind(fp);
361 368
362 smooth = (struct smoothing *) malloc(sizeof(struct smoothing) * (smoothcount)); 369 smooth = new smoothing [smoothcount];
363 memset (smooth, 0, sizeof (struct smoothing) * (smoothcount));
364 370
365 while(nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp)!=NULL) { 371 while(nrofsmooth < smoothcount && fgets (buf, MAX_BUF, fp)!=NULL) {
366 if (*buf == '#') 372 if (*buf == '#')
367 continue; 373 continue;
368 p=strchr(buf,' '); 374 p=strchr(buf,' ');
410{ 416{
411 int i; 417 int i;
412 418
413 for (i=0; i<nroffiles; i++) 419 for (i=0; i<nroffiles; i++)
414 free(xbm[i].name); 420 free(xbm[i].name);
415 free(xbm); 421
416 free(new_faces); 422 delete [] xbm;
417 free(smooth); 423 delete [] new_faces;
424 delete [] smooth;
418} 425}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines