Skip to main content
gamedev.net
🔒 Locked

Weird Problem

Started by santonel 1 reply 500+ views
Original Post
santonel
santonel
Ok I'm having a problem that is getting me super mad . I am making a simcity type simulation game and I'm working on buildings. Here is the code I use to load them:
//----------------------------------------------------------------------------
typedef struct _point
{
float x,y,z;
float tex_x,tex_y;
float norm_x,norm_y,norm_z;
}point;

typedef struct _poly
{
int r,g,b;
int texture_num;
point vertices[4];
bool quad;
}poly;

typedef struct _building
{
char name[255];
char type;
int wealth,density,pop;//pop = residents/jobs
unsigned int *textures;
poly *polys;
int xsize,ysize,num_textures,num_polys;
}bldg,building;
//-----------------------------------------------------------------------------
bool load_building(building &b,char *filename);
void draw_building(building b);
void free_building(building &b);
//-----------------------------------------------------------------------------
bool load_building(building &b,char *filename)
{
FILE *fp;
int ctr,dx,tmp,tmp_x,tmp_y;
unsigned char *tmp_mem;
fp = fopen(filename,"r");
 if(fp == NULL)
 {
 MessageBox(NULL,"Doesn't exist","-",MB_OK);
 return false;
 }
 if(fgetc(fp) != 'S')
 {
 MessageBox(NULL,"Invalid","-",MB_OK);
 fclose(fp);
 return false;
 }
fscanf(fp,"\nname:%s",&b.name);
fscanf(fp,"\nxsize:%d",&b.xsize);
fscanf(fp,"\nysize:%d",&b.ysize);
fscanf(fp,"\ntextures:%d",&b.num_textures);
fscanf(fp,"\npolys:%d",&b.num_polys);
b.polys =(poly*)calloc(b.xsize * b.ysize , sizeof(poly));
b.textures = (unsigned int *)calloc(b.num_textures,sizeof(unsigned int));
 if(b.polys == NULL)
 {
 MessageBox(NULL,"Can't Allocate Memory","-",MB_OK);
 fclose(fp);
 return false;
 }
 if(b.textures == NULL)
 {
 MessageBox(NULL,"Can't Allocate Memory","-",MB_OK);
 fclose(fp);
 return false;
 }

 for(ctr=0;ctr  
Now everything runs fine when I compile and run it in VC++ 6.0 but when I run it from the generated executabe with any building file the x coordinate of the first vertex of the second polygon is set to 0 for some reasons. Anybody know why this happens?

[edited by - santonel on March 3, 2004 11:31:04 PM]   
                        
justinwalsh
justinwalsh
this might be a dumb post but, what is the file path you are passing to your load_building function? relative to the executable is that file in that location on your hard drive?
santonel
santonel
Yes th path is relative to the executable. It loads the building so the path is right otherwise it will give me an error. Also some of my code got cut off in the post incase anyone is wondering.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.