diff --git a/src/common/textures/textureid.h b/src/common/textures/textureid.h index 5237acdae3..49ff595a2f 100644 --- a/src/common/textures/textureid.h +++ b/src/common/textures/textureid.h @@ -1,4 +1,5 @@ #pragma once +#define TEXTUREID_H #include @@ -66,3 +67,13 @@ public: constexpr FSetTextureID(int v) : FTextureID(v) {} }; +#ifdef TARRAY_H +template<> struct THashTraits +{ + + hash_t Hash(const FTextureID key) { return (hash_t)key.GetIndex(); } + + // Compares two keys, returning zero if they are the same. + int Compare(const FTextureID left, const FTextureID right) { return left != right; } +}; +#endif \ No newline at end of file diff --git a/src/common/utility/tarray.h b/src/common/utility/tarray.h index a420b078a8..055229f2c4 100644 --- a/src/common/utility/tarray.h +++ b/src/common/utility/tarray.h @@ -1,4 +1,5 @@ #pragma once +#define TARRAY_H /* ** tarray.h ** Templated, automatically resizing array @@ -943,6 +944,17 @@ template struct THashTraits int Compare(const KT left, const KT right) { return left != right; } }; +#ifdef TEXTUREID_H +template<> struct THashTraits +{ + + hash_t Hash(const FTextureID key) { return (hash_t)key.GetIndex(); } + + // Compares two keys, returning zero if they are the same. + int Compare(const FTextureID left, const FTextureID right) { return left != right; } +}; +#endif + template<> struct THashTraits { // Use all bits when hashing singles instead of converting them to ints. diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index 0fcf16a010..d40f2c7c50 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -88,18 +88,19 @@ void FTextureAnimator::DeleteAll() FAnimDef *FTextureAnimator::AddAnim (FAnimDef& anim) { // Search for existing duplicate. - for (unsigned int i = 0; i < mAnimations.Size(); ++i) - { - if (mAnimations[i].BasePic == anim.BasePic) - { - // Found one! - mAnimations[i] = anim; - return &mAnimations[i]; - } + uint16_t * index = mAnimationIndices.CheckKey(anim.BasePic); + + if(index) + { // Found one! + mAnimations[*index] = anim; + return &mAnimations[*index]; + } + else + { // Didn't find one, so add it at the end. + mAnimationIndices.Insert(anim.BasePic, mAnimations.Size()); + mAnimations.Push (anim); + return &mAnimations.Last(); } - // Didn't find one, so add it at the end. - mAnimations.Push (anim); - return &mAnimations.Last(); } //========================================================================== @@ -982,18 +983,13 @@ constexpr double msPerTic = 1'000.0 / TICRATE; bool FTextureAnimator::InitStandaloneAnimation(FStandaloneAnimation &animInfo, FTextureID tex, uint32_t curTic) { - FAnimDef * anim; animInfo.ok = false; - for(unsigned i = 0; i < mAnimations.Size(); i++) - { - if(mAnimations[i].BasePic == tex) - { - animInfo.ok = true; - animInfo.AnimIndex = i; - anim = &mAnimations[i]; - } - } - if(!animInfo.ok) return false; + uint16_t * index = mAnimationIndices.CheckKey(tex); + if(!index) return false; + FAnimDef * anim = &mAnimations[*index]; + + animInfo.ok = true; + animInfo.AnimIndex = *index; animInfo.CurFrame = 0; animInfo.SwitchTic = curTic; animInfo.AnimType = (anim->AnimType == FAnimDef::ANIM_OscillateDown) ? FAnimDef::ANIM_OscillateUp : anim->AnimType; diff --git a/src/gamedata/textures/animations.h b/src/gamedata/textures/animations.h index a89edf59be..aa6b00e4e1 100644 --- a/src/gamedata/textures/animations.h +++ b/src/gamedata/textures/animations.h @@ -73,6 +73,7 @@ struct FDoorAnimation class FTextureAnimator { + TMap mAnimationIndices; TArray mAnimations; TArray mSwitchDefs; TArray mAnimatedDoors;