mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-16 17:21:10 +00:00
use map instead of linear search to find texture indices for animation
This commit is contained in:
parent
3bd80ab8f6
commit
8ae93fb87f
4 changed files with 42 additions and 22 deletions
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#define TEXTUREID_H
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
@ -66,3 +67,13 @@ public:
|
||||||
constexpr FSetTextureID(int v) : FTextureID(v) {}
|
constexpr FSetTextureID(int v) : FTextureID(v) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef TARRAY_H
|
||||||
|
template<> struct THashTraits<FTextureID>
|
||||||
|
{
|
||||||
|
|
||||||
|
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
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#define TARRAY_H
|
||||||
/*
|
/*
|
||||||
** tarray.h
|
** tarray.h
|
||||||
** Templated, automatically resizing array
|
** Templated, automatically resizing array
|
||||||
|
@ -943,6 +944,17 @@ template<class KT> struct THashTraits
|
||||||
int Compare(const KT left, const KT right) { return left != right; }
|
int Compare(const KT left, const KT right) { return left != right; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef TEXTUREID_H
|
||||||
|
template<> struct THashTraits<FTextureID>
|
||||||
|
{
|
||||||
|
|
||||||
|
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<float>
|
template<> struct THashTraits<float>
|
||||||
{
|
{
|
||||||
// Use all bits when hashing singles instead of converting them to ints.
|
// Use all bits when hashing singles instead of converting them to ints.
|
||||||
|
|
|
@ -88,18 +88,19 @@ void FTextureAnimator::DeleteAll()
|
||||||
FAnimDef *FTextureAnimator::AddAnim (FAnimDef& anim)
|
FAnimDef *FTextureAnimator::AddAnim (FAnimDef& anim)
|
||||||
{
|
{
|
||||||
// Search for existing duplicate.
|
// Search for existing duplicate.
|
||||||
for (unsigned int i = 0; i < mAnimations.Size(); ++i)
|
uint16_t * index = mAnimationIndices.CheckKey(anim.BasePic);
|
||||||
{
|
|
||||||
if (mAnimations[i].BasePic == anim.BasePic)
|
if(index)
|
||||||
{
|
{ // Found one!
|
||||||
// Found one!
|
mAnimations[*index] = anim;
|
||||||
mAnimations[i] = anim;
|
return &mAnimations[*index];
|
||||||
return &mAnimations[i];
|
}
|
||||||
}
|
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)
|
bool FTextureAnimator::InitStandaloneAnimation(FStandaloneAnimation &animInfo, FTextureID tex, uint32_t curTic)
|
||||||
{
|
{
|
||||||
FAnimDef * anim;
|
|
||||||
animInfo.ok = false;
|
animInfo.ok = false;
|
||||||
for(unsigned i = 0; i < mAnimations.Size(); i++)
|
uint16_t * index = mAnimationIndices.CheckKey(tex);
|
||||||
{
|
if(!index) return false;
|
||||||
if(mAnimations[i].BasePic == tex)
|
FAnimDef * anim = &mAnimations[*index];
|
||||||
{
|
|
||||||
animInfo.ok = true;
|
animInfo.ok = true;
|
||||||
animInfo.AnimIndex = i;
|
animInfo.AnimIndex = *index;
|
||||||
anim = &mAnimations[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!animInfo.ok) return false;
|
|
||||||
animInfo.CurFrame = 0;
|
animInfo.CurFrame = 0;
|
||||||
animInfo.SwitchTic = curTic;
|
animInfo.SwitchTic = curTic;
|
||||||
animInfo.AnimType = (anim->AnimType == FAnimDef::ANIM_OscillateDown) ? FAnimDef::ANIM_OscillateUp : anim->AnimType;
|
animInfo.AnimType = (anim->AnimType == FAnimDef::ANIM_OscillateDown) ? FAnimDef::ANIM_OscillateUp : anim->AnimType;
|
||||||
|
|
|
@ -73,6 +73,7 @@ struct FDoorAnimation
|
||||||
|
|
||||||
class FTextureAnimator
|
class FTextureAnimator
|
||||||
{
|
{
|
||||||
|
TMap<FTextureID, uint16_t> mAnimationIndices;
|
||||||
TArray<FAnimDef> mAnimations;
|
TArray<FAnimDef> mAnimations;
|
||||||
TArray<FSwitchDef*> mSwitchDefs;
|
TArray<FSwitchDef*> mSwitchDefs;
|
||||||
TArray<FDoorAnimation> mAnimatedDoors;
|
TArray<FDoorAnimation> mAnimatedDoors;
|
||||||
|
|
Loading…
Reference in a new issue