QSet<QString> CellNameLoader::getCellNames(QStringList &contentPaths) { QSet<QString> cellNames; ESM::ESMReader esmReader; // Loop through all content files for (auto &contentPath : contentPaths) { esmReader.open(contentPath.toStdString()); // Loop through all records while(esmReader.hasMoreRecs()) { ESM::NAME recordName = esmReader.getRecName(); esmReader.getRecHeader(); if (isCellRecord(recordName)) { QString cellName = getCellName(esmReader); if (!cellName.isEmpty()) { cellNames.insert(cellName); } } // Stop loading content for this record and continue to the next esmReader.skipRecord(); } } return cellNames; }
TRasterP TCacheResource::load(const PointLess &cellPos) { if (m_path.isEmpty()) return 0; TFilePath cellPath(TCacheResourcePool::instance()->getPath() + m_path + TFilePath(getCellName(cellPos.x, cellPos.y))); TRasterP ras; if (m_tileType == CM32) { ::loadCompressed(cellPath, ras, CM32); } else { TImageReader::load(cellPath.withType(".tif"), ras); } return ras; }
void TCacheResource::save(const TFilePath &fp) { assert(!fp.isEmpty()); std::map<PointLess, CellData>::iterator it; for (it = m_cellDatas.begin(); it != m_cellDatas.end(); ++it) { TRasterP cellRas = getRaster(TImageCache::instance()->get( getCellCacheId(it->first.x, it->first.y), false)); assert(m_tileType != NONE); TFilePath cellFp(fp + TFilePath(getCellName(it->first.x, it->first.y))); if (m_tileType == CM32) ::saveCompressed(cellFp, cellRas); else TImageWriter::save(cellFp.withType(".tif"), cellRas); } }
bool TCacheResource::save(const PointLess &cellIndex, TRasterP cellRas) const { if (!m_backEnabled || m_invalidated) return false; assert(!m_path.isEmpty()); if (!cellRas) cellRas = getRaster(TImageCache::instance()->get( getCellCacheId(cellIndex.x, cellIndex.y), false)); assert(m_tileType != NONE); TFilePath fp(TCacheResourcePool::instance()->getPath() + m_path + getCellName(cellIndex.x, cellIndex.y)); if (m_tileType == CM32) { ::saveCompressed(fp, cellRas); } else { TImageWriter::save(fp.withType(".tif"), cellRas); } return true; }
inline std::string TCacheResource::getCellCacheId(int idxX, int idxY) const { return "TCacheResource" + toString(m_id) + getCellName(idxX, idxY); }