fix Assets filesByExtension storing duplicate asset paths
slipped in with the asset load scripts - this caused rare duplication errors when the Databases parse assets by extension and an asset path is indexed with more than one capitalization #66
This commit is contained in:
parent
19986b30a1
commit
db42ccae71
@ -371,7 +371,7 @@ StringList Assets::scan(String const& suffix) const {
|
||||
StringList Assets::scan(String const& prefix, String const& suffix) const {
|
||||
StringList result;
|
||||
if (suffix.beginsWith(".") && !suffix.substr(1).hasChar('.')) {
|
||||
StringSet filesWithExtension = scanExtension(suffix);
|
||||
auto& filesWithExtension = scanExtension(suffix);
|
||||
for (auto const& file : filesWithExtension) {
|
||||
if (file.beginsWith(prefix, String::CaseInsensitive))
|
||||
result.append(file);
|
||||
@ -386,11 +386,11 @@ StringList Assets::scan(String const& prefix, String const& suffix) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
const StringSet NullStringSet;
|
||||
const CaseInsensitiveStringSet NullExtensionScan;
|
||||
|
||||
StringSet const& Assets::scanExtension(String const& extension) const {
|
||||
CaseInsensitiveStringSet const& Assets::scanExtension(String const& extension) const {
|
||||
auto find = m_filesByExtension.find(extension.beginsWith(".") ? extension.substr(1) : extension);
|
||||
return find != m_filesByExtension.end() ? find->second : NullStringSet;
|
||||
return find != m_filesByExtension.end() ? find->second : NullExtensionScan;
|
||||
}
|
||||
|
||||
Json Assets::json(String const& path) const {
|
||||
@ -416,7 +416,7 @@ void Assets::queueJsons(StringList const& paths) const {
|
||||
}));
|
||||
}
|
||||
|
||||
void Assets::queueJsons(StringSet const& paths) const {
|
||||
void Assets::queueJsons(CaseInsensitiveStringSet const& paths) const {
|
||||
MutexLocker assetsLocker(m_assetsMutex);
|
||||
for (String const& path : paths) {
|
||||
auto components = AssetPath::split(path);
|
||||
@ -439,7 +439,7 @@ void Assets::queueImages(StringList const& paths) const {
|
||||
}));
|
||||
}
|
||||
|
||||
void Assets::queueImages(StringSet const& paths) const {
|
||||
void Assets::queueImages(CaseInsensitiveStringSet const& paths) const {
|
||||
MutexLocker assetsLocker(m_assetsMutex);
|
||||
for (String const& path : paths) {
|
||||
auto components = AssetPath::split(path);
|
||||
@ -482,7 +482,7 @@ void Assets::queueAudios(StringList const& paths) const {
|
||||
}));
|
||||
}
|
||||
|
||||
void Assets::queueAudios(StringSet const& paths) const {
|
||||
void Assets::queueAudios(CaseInsensitiveStringSet const& paths) const {
|
||||
MutexLocker assetsLocker(m_assetsMutex);
|
||||
for (String const& path : paths) {
|
||||
auto components = AssetPath::split(path);
|
||||
|
@ -190,7 +190,7 @@ public:
|
||||
// Scans all assets for files with the given extension, which is specially
|
||||
// indexed and much faster than a normal scan. Extension may contain leading
|
||||
// '.' character or it may be omitted.
|
||||
StringSet const& scanExtension(String const& extension) const;
|
||||
CaseInsensitiveStringSet const& scanExtension(String const& extension) const;
|
||||
|
||||
// Get json asset with an optional sub-path. The sub-path portion of the
|
||||
// path refers to a key in the top-level object, and may use dot notation
|
||||
@ -204,7 +204,7 @@ public:
|
||||
|
||||
// Load all the given jsons using background processing.
|
||||
void queueJsons(StringList const& paths) const;
|
||||
void queueJsons(StringSet const& paths) const;
|
||||
void queueJsons(CaseInsensitiveStringSet const& paths) const;
|
||||
|
||||
// Returns *either* an image asset or a sub-frame. Frame files are JSON
|
||||
// descriptor files that reference a particular image and label separate
|
||||
@ -216,7 +216,7 @@ public:
|
||||
ImageConstPtr image(AssetPath const& path) const;
|
||||
// Load images using background processing
|
||||
void queueImages(StringList const& paths) const;
|
||||
void queueImages(StringSet const& paths) const;
|
||||
void queueImages(CaseInsensitiveStringSet const& paths) const;
|
||||
// Return the given image *if* it is already loaded, otherwise queue it for
|
||||
// loading.
|
||||
ImageConstPtr tryImage(AssetPath const& path) const;
|
||||
@ -231,7 +231,7 @@ public:
|
||||
AudioConstPtr audio(String const& path) const;
|
||||
// Load audios using background processing
|
||||
void queueAudios(StringList const& paths) const;
|
||||
void queueAudios(StringSet const& paths) const;
|
||||
void queueAudios(CaseInsensitiveStringSet const& paths) const;
|
||||
// Return the given audio *if* it is already loaded, otherwise queue it for
|
||||
// loading.
|
||||
AudioConstPtr tryAudio(String const& path) const;
|
||||
@ -331,7 +331,7 @@ private:
|
||||
// Maps the source asset name to the source containing it
|
||||
CaseInsensitiveStringMap<AssetFileDescriptor> m_files;
|
||||
// Maps an extension to the files with that extension
|
||||
CaseInsensitiveStringMap<StringSet> m_filesByExtension;
|
||||
CaseInsensitiveStringMap<CaseInsensitiveStringSet> m_filesByExtension;
|
||||
|
||||
ByteArray m_digest;
|
||||
|
||||
|
@ -359,6 +359,8 @@ struct CaseInsensitiveStringCompare {
|
||||
|
||||
typedef HashSet<String> StringSet;
|
||||
|
||||
typedef HashSet<String, CaseInsensitiveStringHash, CaseInsensitiveStringCompare> CaseInsensitiveStringSet;
|
||||
|
||||
template <typename MappedT, typename HashT = hash<String>, typename ComparatorT = std::equal_to<String>>
|
||||
using StringMap = HashMap<String, MappedT, HashT, ComparatorT>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user