Archived

This topic is now archived and is closed to further replies.

Rodrigox17

Map Editor Map Loading Problem. Help!!!

Recommended Posts

Rodrigox17    122
Here is my code for managing my map files The problem is that whenever I save the map it doesn''t save each tile properly it somehow saves only the first tile in the array Could any one help me with this problem? and Here is the Working Program Click on a Tile with the Left Mouse Button Then Click the right button over where u want to insert the tile Press S to Save and G to grab screen shot When u save the File and the Reload the editor no changes occur http://www.geocities.com/rodrigo_120/downloads/editor.zip struct MAP_FILE_HEADER { //Map file map_header char EngName[20]; //Map engine name. int EngVersion; //Map engine version. char MapName[20]; //Map short name. char Desc[198]; //Map long description. char Tileset[20]; //Name of tileset used for map. long Width; //Width of the map. long Height; //Height of the map. }; typedef struct TILE_TYP { int id; int type; int flags; int mmcolor; } TILE, *TILE_PTR; class CMap { private: TILE *m_World; int m_Width; int m_Height; MAP_FILE_HEADER m_mhf; bool Create(int w, int h); public: CMap(); ~CMap(); void Release(); bool Load(char *fileName); bool Save(char *fileName); void SetWidth(int nWidth); void SetHeight(int nHeight); } CMap::CMap() { m_World = NULL; m_Width = 0; m_Height = 0; m_Device = NULL; } CMap::~CMap() { Release(); } void CMap::Release() { if ( m_World ) { delete [] m_World; m_World = NULL; m_Device = NULL; m_Width = 0; m_Height = 0; } } bool CMap::Load(char *fileName) { if ( m_World ) return true; // Map Already Loaded FILE *file_ptr; file_ptr = fopen(fileName,"r"); if ( file_ptr == NULL) return false; fread(&m_mhf,sizeof(MAP_FILE_HEADER),1,file_ptr); if ( ! Create(m_mhf.Width,m_mhf.Height) ) return false; fread((void*)m_World,sizeof(TILE),m_Width*m_Height,file_ptr); fclose(file_ptr); return true; } bool CMap::Save(char *fileName) { FILE *file_ptr; if ( !m_World ) return false; file_ptr = fopen(fileName,"w"); if ( !file_ptr ) return false; fwrite(&m_mhf,sizeof(MAP_FILE_HEADER),1,file_ptr); fwrite((void*)m_World,sizeof(TILE),m_Width*m_Height,file_ptr); fclose(file_ptr); return true; } bool CMap::Create(int w, int h) { if ( m_World ) return true; // Map Already Created m_World = new TILE[w*h]; if ( !m_World ) return false; // Not Enough Memory SetWidth(w); SetHeight(h); memset(m_World,0,sizeof(TILE_TYP)*m_Width*m_Height); return true; } void CMap::SetWidth(int nWidth) { m_Width = nWidth; } void CMap::SetHeight(int nHeight) { m_Height = nHeight; }

Share this post


Link to post
Share on other sites
Daerax    1207
It would seem to me as if your CMAP class never sets the MAP_FILE_HEADER m_mhf struct.

Also use the source tag. (encased in [])




[edited by - Daerax on March 6, 2003 4:52:00 PM]

Share this post


Link to post
Share on other sites