Advertisement

World in a text file

Started by January 22, 2004 01:00 PM
19 comments, last by Kheteris 21 years, 1 month ago
how about changing it to use a seperate file for the texture name and numbers.

struct txtfile
{
int txtcount; // Number of textures being used
bool txtused[100]; // 1 = Texture used
char txtfilename[255]; // Directory + Filename
char txtdir[255]; // Just directory
};

txtfile array[20];

void CheckTextures(){	ReadWorld();	char txtfilename[255];				// Texture file name	char textdir[255];					// Location of texture directory	char textdirectory[255];	int  numtext=0;	int  textnum=1;						// Texture number (from world) temp store	int  length=0;	int  tstused=0;	FILE *filein;	char oneline[255];	filein = fopen("data/textures.txt", "rt");			// File To Load World Data From	filein = world;	readstr(filein,oneline);							// Read first line into filein store	sscan(oneline, "[TEXTURES] %d\n", &numtext);		// check for texture counter	readstr(filein,oneline);							// Read first line into filein store	sscan(oneline, "[DIRECTORY] %s\n", &textdir);		// check for texture directory location		length = strlen (textdir);	textdir[length] = 47;	textdir[length+1] = 0;	strcpy (array[0].txtdir, textdir);					// Store Texture directory	strcpy (textdirectory, textdir);					// Store Texture directory	for (int loop = 0; loop < numtext; loop++)			// This loop builds a vector list	{		strcpy (textdir, textdirectory);					// Restore Texture directory		readstr(filein,oneline);							// Read first line into filein store		sscan(oneline, "%d%s\n", &textnum, &txtfilename);	// check for texture number+Filename			strcat(textdir, txtfilename);						// add Filename to directory		strcpy (array[textnum].txtfilename, textdir);		// Store Texture directory + Filename	}	fclose(filein);	int zz = 0;//// Check to see what textures are being used// Generates a bool list in array[0].txtused// 1 = used, 0 = not used//	filein = fopen("data/world.txt", "rt");			// File To Load World Data From	readstr(filein, oneline);						// Grab poly count	sscanf(oneline, "[NUMPOLLIES] %d\n", &numtext);	// store number of polys	numtext = numtext/2;							// div by 2 (2 triangle = 1 texture)	for (loop=0; loop < numtext; loop++)			// This loop builds a texture list	{		readstr(filein, oneline);		sscanf(oneline, "gfx %d\n", &tstused);		array[0].txtused[tstused] = 1;				// Store Texture 1 = used		readstr(filein, oneline);					// Normal 0.0 0.0 0.0		readstr(filein, oneline);		readstr(filein, oneline);		readstr(filein, oneline);		readstr(filein, oneline);		readstr(filein, oneline);		readstr(filein, oneline);	}	fclose(filein);	for (loop=1; loop < 20; loop++)			// This loop builds a used texture count	{		switch (array[0].txtused[loop])		{			case 0 :			{				break;			}			case 1 :								// 1= used			{				array[0].txtcount++;				// increase counter			}		}	}	return;}


File Format :

[TEXTURES] 07[DIRECTORY] data/textures01 granite.bmp02 broof1.bmp03 bstonwll1.bmp04 bstonwll1pllrw2.bmp05 bstonwll2.bmp06 rock.bmp07 volcanicgrey.bmp08 darkrock.bmp09 fire.bmp10 sand.bmp


World data:

////      X   Y  (on texture)//      U   V// A = 0.0 0.0// B = 0.0 1.0// C = 1.0 0.0// D = 1.0 1.0//[NUMPOLLIES] 42// Wall Backgfx 03// ABD DCA-30.0  00.0 -12.0 0.0 0.0-30.0  30.0 -12.0 0.0 12.0 30.0  30.0 -12.0 12.0 12.0 30.0  30.0 -12.0 12.0 12.0 30.0  00.0 -12.0 12.0 0.0-30.0  00.0 -12.0 0.0 0.0// Wall frontgfx 03// ABD DCA 30.0  00.0  12.0 0.0 0.0 30.0  30.0  12.0 0.0 6.0-30.0  30.0  12.0 6.0 6.0-30.0  30.0  12.0 6.0 6.0-30.0  00.0  12.0 6.0 0.0 30.0  00.0  12.0 0.0 0.0


Then again you can keep adding functions forever.


Boo!! I know all.

This topic is closed to new replies.

Advertisement