void initializePathsLookup(){ static std::once_flag onceFlag; std::call_once(onceFlag,[](){ std::string filePath(pathToPaths()); std::ifstream mapStream(filePath); std::string line; while(std::getline(mapStream, line)) _paths.push_back(line); }); }
void Map::load(std::string mapName) { // Check sheet compatibility SDL_QueryTexture(this->tileSheet, NULL, NULL, &sheetWidth, &sheetHeight); if (sheetWidth % TILE_WIDTH != 0 || sheetHeight % TILE_HEIGHT != 0) { std::cout << "Map error: Sprite sheet dimensions do not match" << std::endl; return; } // Load map std::ifstream mapStream(mapName); std::string line; // Check if has stream if (!mapStream) { std::cout << "Map error: Could not load map" << std::endl; return; } int mapPosX = 0; int mapPosY = 0; while (std::getline(mapStream, line)) { std::stringstream lineStream(line); int tileType; mapPosX = 0; while (lineStream >> tileType) { // Check for read error if (mapStream.fail()) { mapStream.close(); std::cout << "Map error: Could not read map" << std::endl; return; } tiles[mapPosX][mapPosY] = tileType; mapPosX++; } mapPosY++; } this->mapWidth = mapPosX; this->mapHeight = mapPosY; mapStream.close(); std::cout << "Map success: Map " << mapName << " loaded successfully" << std::endl; this->initTileSheet(); }
void Doom3MapCompiler::runDmap(const std::string& mapFile) { if (!os::fileOrDirExists(mapFile) || file_is_directory(mapFile.c_str())) { rError() << "Can't dmap, file doesn't exist: " << mapFile << std::endl; return; } TextFileInputStream file(mapFile); std::istream mapStream(&file); boost::shared_ptr<BasicNode> root(new BasicNode); RawImporter importFilter(root); try { // Parse our map file Doom3MapReader reader(importFilter); reader.readFromStream(mapStream); } catch (IMapReader::FailureException& e) { rError() << (boost::format("Failure reading map file:\n%s\n\n%s") % mapFile % e.what()).str() << std::endl; return; } // Start the sequence runDmap(root); if (_procFile->hasLeak()) { std::string ext = "." + os::getExtension(mapFile); std::string leakFileName = boost::algorithm::replace_last_copy(mapFile, ext, LeakFile::Extension()); _procFile->leakFile->writeToFile(leakFileName); return; } std::string ext = "." + os::getExtension(mapFile); std::string procFileName = boost::algorithm::replace_last_copy(mapFile, ext, ProcFile::Extension()); _procFile->saveToFile(procFileName); }