diff --git a/code/AssetLib/FBX/FBXCompileConfig.h b/code/AssetLib/FBX/FBXCompileConfig.h index 8ff1e06e2..1d0784dbc 100644 --- a/code/AssetLib/FBX/FBXCompileConfig.h +++ b/code/AssetLib/FBX/FBXCompileConfig.h @@ -49,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include // -#if _MSC_VER > 1500 || (defined __GNUC___) +#if _MSC_VER > 1500 || (defined __GNUC__) # define ASSIMP_FBX_USE_UNORDERED_MULTIMAP # else # define fbx_unordered_map map diff --git a/code/AssetLib/Step/STEPFile.h b/code/AssetLib/Step/STEPFile.h index cf6a0736d..8dcb5dba7 100644 --- a/code/AssetLib/Step/STEPFile.h +++ b/code/AssetLib/Step/STEPFile.h @@ -58,7 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # pragma warning(disable : 4127 4456 4245 4512 ) #endif // _MSC_VER -#if _MSC_VER > 1500 || (defined __GNUC___) +#if _MSC_VER > 1500 || (defined __GNUC__) # define ASSIMP_STEP_USE_UNORDERED_MULTIMAP #else # define step_unordered_map map diff --git a/code/AssetLib/Step/StepExporter.cpp b/code/AssetLib/Step/StepExporter.cpp index 1e5de037b..73dce2702 100644 --- a/code/AssetLib/Step/StepExporter.cpp +++ b/code/AssetLib/Step/StepExporter.cpp @@ -63,7 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include // -#if _MSC_VER > 1500 || (defined __GNUC___) +#if _MSC_VER > 1500 || (defined __GNUC__) # define ASSIMP_STEP_USE_UNORDERED_MULTIMAP # else # define step_unordered_map map diff --git a/code/AssetLib/glTF/glTFAsset.h b/code/AssetLib/glTF/glTFAsset.h index 9fec70ea2..49b55aabb 100644 --- a/code/AssetLib/glTF/glTFAsset.h +++ b/code/AssetLib/glTF/glTFAsset.h @@ -83,7 +83,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif -#if _MSC_VER > 1500 || (defined __GNUC___) +#if _MSC_VER > 1500 || (defined __GNUC__) # define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP # else # define gltf_unordered_map map diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index 33bb30688..51863c447 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -64,7 +64,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include #include #include #include @@ -95,7 +95,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # define ai_assert #endif -#if _MSC_VER > 1500 || (defined __GNUC___) +#if _MSC_VER > 1500 || (defined __GNUC__) # define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP #else # define gltf_unordered_map map @@ -1266,9 +1266,8 @@ private: size_t mSceneLength; size_t mBodyOffset; size_t mBodyLength; - IdMap mUsedIds; - std::map> mUsedNamesMap; Ref mBodyBuffer; + std::unordered_map lastUsedID; }; inline std::string getContextForErrorMessages(const std::string &id, const std::string &name) { diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index a29ba205a..24d488cc4 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -438,7 +438,6 @@ unsigned int LazyDict::Remove(const char *id) { const unsigned int index = objIt->second; - mAsset.mUsedIds[id] = false; mObjsById.erase(id); mObjsByOIndex.erase(index); delete mObjs[index]; @@ -472,7 +471,6 @@ unsigned int LazyDict::Remove(const char *id) { template Ref LazyDict::Retrieve(unsigned int i) { - typename Dict::iterator it = mObjsByOIndex.find(i); if (it != mObjsByOIndex.end()) { // already created? return Ref(mObjs, it->second); @@ -540,16 +538,11 @@ Ref LazyDict::Add(T *obj) { mObjs.push_back(obj); mObjsByOIndex[obj->oIndex] = idx; mObjsById[obj->id] = idx; - mAsset.mUsedIds[obj->id] = true; return Ref(mObjs, idx); } template Ref LazyDict::Create(const char *id) { - Asset::IdMap::iterator it = mAsset.mUsedIds.find(id); - if (it != mAsset.mUsedIds.end()) { - throw DeadlyImportError("GLTF: two objects with the same ID exist"); - } T *inst = new T(); unsigned int idx = unsigned(mObjs.size()); inst->id = id; @@ -565,11 +558,12 @@ inline Buffer::Buffer() : byteLength(0), type(Type_arraybuffer), EncodedRegion_Current(nullptr), - mIsSpecial(false) {} + mIsSpecial(false) { + // empty +} inline Buffer::~Buffer() { - for (SEncodedRegion *reg : EncodedRegion_List) - delete reg; + for (SEncodedRegion *reg : EncodedRegion_List) delete reg; } inline const char *Buffer::TranslateId(Asset & /*r*/, const char *id) { @@ -693,7 +687,6 @@ inline void Buffer::EncodedRegion_SetCurrent(const std::string &pID) { } inline bool Buffer::ReplaceData(const size_t pBufferData_Offset, const size_t pBufferData_Count, const uint8_t *pReplace_Data, const size_t pReplace_Count) { - if ((pBufferData_Count == 0) || (pReplace_Count == 0) || (pReplace_Data == nullptr)) { return false; } @@ -809,8 +802,7 @@ inline uint8_t *BufferView::GetPointerAndTailSize(size_t accOffset, size_t& outT } } - if (offset >= buffer->byteLength) - { + if (offset >= buffer->byteLength) { outTailSize = 0; return nullptr; } @@ -2206,29 +2198,27 @@ inline IOStream *Asset::OpenFile(const std::string &path, const char *mode, bool inline std::string Asset::FindUniqueID(const std::string &str, const char *suffix) { std::string id = str; - - if (!id.empty()) { - if (mUsedIds.find(id) == mUsedIds.end()){ - mUsedNamesMap[id] = 0; + int n = 1; + if(!id.empty()) { + n = lastUsedID[id]; + if(!n) { + lastUsedID[id] = n+1; return id; } - id += "_"; } - id += suffix; - - Asset::IdMap::iterator it = mUsedIds.find(id); - if (it == mUsedIds.end()) { - mUsedNamesMap[id] = 0; - return id; + if(suffix) { + id += suffix; + n = lastUsedID[id]; + if(!n) { + lastUsedID[id] = n+1; + return id; + } } - auto key = id; - id += "_" + std::to_string(mUsedNamesMap[key]); - mUsedNamesMap[key] = mUsedNamesMap[key] + 1; - - return id; + lastUsedID[id] = n+1; + return id + "_" + std::to_string(n-1); } #if _MSC_VER diff --git a/code/AssetLib/glTFCommon/glTFCommon.h b/code/AssetLib/glTFCommon/glTFCommon.h index c8d0afd2f..02884c4f8 100644 --- a/code/AssetLib/glTFCommon/glTFCommon.h +++ b/code/AssetLib/glTFCommon/glTFCommon.h @@ -69,7 +69,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # define ai_assert #endif -#if _MSC_VER > 1500 || (defined __GNUC___) +#if _MSC_VER > 1500 || (defined __GNUC__) # define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP #else # define gltf_unordered_map map