Skip to main content
gamedev.net
🔒 Locked

File Saving

Started by PsYchOtroW 1 reply 450+ views
Original Post
PsYchOtroW
PsYchOtroW
Hi, i am using a Map File Format like the example from Dino at Iso Engines.
  

// Map Header

struct map_header
{
public:
	int		Version;		// 4

	char	Name[64];		// 64

	char	Author[64];		// 64

//	int		Width;			// 4

//	int		Height;			// 4

//	int		Padding[126];	// 126

};							// 256 total


#define DATAVERSION			3


#define TILE_WIDTH  64
#define TILE_HEIGHT	32

// Definition of our map structure

typedef struct
{
    unsigned char TileID;   // The ID of this tile

    unsigned char Type;     // What type of tile is this

	bool walkable;
} MAPTILE;
// New Map Function

void CMap::New( const char *FileName, char *MapName, char *MapAuthor )
{

	ofstream File( FileName, ios::out|ios::binary );

	Header.Version = DATAVERSION;		// 4

	memcpy(Header.Name, MapName, 64); // Set Name

	memcpy(Header.Author, MapName, 64); // Set Author


	// Initialize the elements of the map

	for(int lyr = 0; lyr < 3; lyr++)
	{
		for( int x = 0; x < 255; x++)
		{
			for(int y = 0; y < 255; y++)
			{
				Map[lyr][x][y].TileID = 0;
				Map[lyr][x][y].Type = 0;
				Map[lyr][x][x].walkable = true;
			}
		}
	}


	// header is supposed to be 256 bytes

	File.write( (char *)&Header, sizeof( Header ));

	for ( int layer =0; layer < 3; layer++ )
	{	
		for ( int MapX =0; MapX < 255; MapX++ )
		{
			for ( int MapY =0; MapY < 255; MapY++ )
			{
				File.write( (char *)&(Map[layer][MapX][MapY]), sizeof( Map ) );
					
				

			}
		}
	}


}

  
There is a Error in the New Map Function but what? Please help me. I don`t know what i do wrong. Lutz Hören [ Power Productions ]
psYchOtroW
andy maddison
andy maddison
Maybe you could have supplied the error message(s)?

Anyway, at a quick glance I see there''s no declaration for Header and Map, unless you''ve left them out of your post for the sake of brevity?

ie.
  
map_header Header;
MAPTILE Map;


Also, wouldn''t it be better to use strcpy() for copying names? You wouldn''t then have to be concerned with supplying the number of bytes to copy (which may change later).

ie.
  
strcpy(Header.Name,MapName);


Oh, and I''ve just noticed you''ve got a typo here:
  
Map[lyr][x][x].walkable = true;

You want:
  
Map[lyr][x][y].walkable = true;


Andy.
PsYchOtroW
PsYchOtroW
Thanks Andy,
i have found my Error, is was using the sizeof(Map) but i need sizeof( MAPTILE ). That was it...

Thanks

Lutz Hören

[ Power Productions ]
psYchOtroW

Topic Locked

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

Sign in to reply to this topic.