Made the FilePager a little more robust regarding filename conflicts.
This commit is contained in:
parent
8bd013f28e
commit
b90f0d4e15
@ -56,13 +56,12 @@ namespace PolyVox
|
|||||||
m_strFolderName.append("/");
|
m_strFolderName.append("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a unique prefix to avoid multiple pagers using the same filenames.
|
// Build a unique postfix to avoid filename conflicts between multiple pagers/runs.
|
||||||
srand(static_cast<unsigned int>(time(0)));
|
// Not a very robust solution but this class is meant as an example for testing really.
|
||||||
int iRandomValue = rand();
|
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::hex << iRandomValue;
|
ss << time(0) << "--"; // Avoid multiple runs using the same filenames.
|
||||||
m_strRandomPrefix = ss.str();
|
ss << this; // Avoid multiple FilePagers using the same filenames.
|
||||||
|
m_strPostfix = ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
@ -82,9 +81,10 @@ namespace PolyVox
|
|||||||
POLYVOX_ASSERT(pChunk->getData(), "Chunk must have valid data");
|
POLYVOX_ASSERT(pChunk->getData(), "Chunk must have valid data");
|
||||||
|
|
||||||
std::stringstream ssFilename;
|
std::stringstream ssFilename;
|
||||||
ssFilename << m_strFolderName << "/" << m_strRandomPrefix << "-"
|
ssFilename << m_strFolderName << "/"
|
||||||
<< region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_"
|
<< region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_"
|
||||||
<< region.getUpperX() << "_" << region.getUpperY() << "_" << region.getUpperZ();
|
<< region.getUpperX() << "_" << region.getUpperY() << "_" << region.getUpperZ()
|
||||||
|
<< "--" << m_strPostfix;
|
||||||
|
|
||||||
std::string filename = ssFilename.str();
|
std::string filename = ssFilename.str();
|
||||||
|
|
||||||
@ -133,9 +133,10 @@ namespace PolyVox
|
|||||||
POLYVOX_LOG_TRACE("Paging out data for " << region);
|
POLYVOX_LOG_TRACE("Paging out data for " << region);
|
||||||
|
|
||||||
std::stringstream ssFilename;
|
std::stringstream ssFilename;
|
||||||
ssFilename << m_strFolderName << "/" << m_strRandomPrefix << "-"
|
ssFilename << m_strFolderName << "/"
|
||||||
<< region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_"
|
<< region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_"
|
||||||
<< region.getUpperX() << "_" << region.getUpperY() << "_" << region.getUpperZ();
|
<< region.getUpperX() << "_" << region.getUpperY() << "_" << region.getUpperZ()
|
||||||
|
<< "--" << m_strPostfix;
|
||||||
|
|
||||||
std::string filename = ssFilename.str();
|
std::string filename = ssFilename.str();
|
||||||
|
|
||||||
@ -163,7 +164,7 @@ namespace PolyVox
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string m_strFolderName;
|
std::string m_strFolderName;
|
||||||
std::string m_strRandomPrefix;
|
std::string m_strPostfix;
|
||||||
|
|
||||||
std::vector<std::string> m_vecCreatedFiles;
|
std::vector<std::string> m_vecCreatedFiles;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user