/* ====================================== End ====================================== */ void Resources::Free() { // Free all the loaded tiles FreeTileset(); // Note, the font bitmap and cursor are freed in Main.cpp calling to mI->End() }
/* ====================================== Parse file and load backdrop images (tiles) ====================================== */ bool Resources::LoadTileset (char *pTilesetFile) { // If there is a tileset already, free it if (!mVectorTiles.empty()) FreeTileset(); strcpy (mTilesetPath, pTilesetFile); TiXmlDocument mXmlDoc (mTilesetPath); // Fatal error, cannot load if (!mXmlDoc.LoadFile()) { return false; } // Document root TiXmlElement *mXResources = 0; mXResources = mXmlDoc.FirstChildElement("resources"); if (!mXResources) { // No "<resources>" tag return false; } // ----------------- Parse surfaces from the file and load them into a vector ----------------- // Surfaces TiXmlElement *mXSurfaces = 0; mXSurfaces = mXResources->FirstChildElement("surfaces"); if (!mXSurfaces) { // No "<surfaces>" tag return false; } TiXmlElement *mXSurface = 0; mXSurface = mXSurfaces->FirstChildElement("surface"); if (!mXSurface) { // No surfaces to parse return false; } // Parse all the surfaces char mFileName [1024]; mFileName [0] = 0; while (mXSurface) { SURFACEWITHID *mNewSurface = new SURFACEWITHID; // Id if (mXSurface->Attribute("id")) { mNewSurface->mId = atoi (mXSurface->Attribute("id")); } else { delete mNewSurface; return false; } // Path to the image if (mXSurface->Attribute("image")) { strcpy (mFileName, mXSurface->Attribute("image")); // Load surface if (!mI->_surfaceManager->add (mNewSurface->mSurface, mFileName, IND_ALPHA, IND_32)) return 0; } else { delete mNewSurface; return false; } // Push the surface into the surfaces vector mVectorTiles.push_back (mNewSurface); // Move to the next declaration mXSurface = mXSurface->NextSiblingElement("surface"); } // Note: XML nodes are deleted by TiXmlDocument destructor return true; }
/* ====================================== Parse file and load backdrop images (tiles) ====================================== */ bool Resources::LoadTileset (char *pTilesetFile) { // If there is a tileset already, free it if (!mVectorTiles.empty()) FreeTileset(); strcpy (mTilesetPath, pTilesetFile); TiXmlDocument mXmlDoc (mTilesetPath); // Fatal error, cannot load if (!mXmlDoc.LoadFile()) { return false; } // fetching the directory where the xml file is located string tilesetTopPath; string s = string(pTilesetFile); size_t lastPosTemp = s.find_last_of("\\/"); if(lastPosTemp == string::npos){ tilesetTopPath = "./"; } else{ tilesetTopPath = s.substr(0, lastPosTemp + 1); } // Document root TiXmlElement *mXResources = 0; mXResources = mXmlDoc.FirstChildElement("resources"); if (!mXResources) { // No "<resources>" tag return false; } // ----------------- Parse surfaces from the file and load them into a vector ----------------- // Surfaces TiXmlElement *mXSurfaces = 0; mXSurfaces = mXResources->FirstChildElement("surfaces"); if (!mXSurfaces) { // No "<surfaces>" tag return false; } TiXmlElement *mXSurface = 0; mXSurface = mXSurfaces->FirstChildElement("surface"); if (!mXSurface) { // No surfaces to parse return false; } string imagePath; while (mXSurface) { SURFACEWITHID *mNewSurface = new SURFACEWITHID; // Id if (mXSurface->Attribute("id")) { mNewSurface->mId = atoi (mXSurface->Attribute("id")); } else { delete mNewSurface; return false; } // Path to the image if (mXSurface->Attribute("image")) { mNewSurface->mSurface = IND_Surface::newSurface(); imagePath = tilesetTopPath + string(mXSurface->Attribute("image")); // Load surface if (!mI->_surfaceManager->add (mNewSurface->mSurface, imagePath.c_str(), IND_ALPHA, IND_32)) return 0; } else { delete mNewSurface; return false; } // Push the surface into the surfaces vector mVectorTiles.push_back (mNewSurface); // Move to the next declaration mXSurface = mXSurface->NextSiblingElement("surface"); } // Note: XML nodes are deleted by TiXmlDocument destructor return true; }