cache NetworkedAnimator drawables
could use a LruCache later
This commit is contained in:
parent
14ef69c0f6
commit
f2fedb0c87
@ -174,6 +174,7 @@ ImageOperation imageOperationFromString(StringView string) {
|
|||||||
char ch = *ptr;
|
char ch = *ptr;
|
||||||
|
|
||||||
if (ch == '=' || ch == ';' || ptr == end) {
|
if (ch == '=' || ch == ';' || ptr == end) {
|
||||||
|
if (hexLen != 0) {
|
||||||
char* c = which ? a : b;
|
char* c = which ? a : b;
|
||||||
|
|
||||||
if (hexLen == 3) {
|
if (hexLen == 3) {
|
||||||
@ -205,6 +206,7 @@ ImageOperation imageOperationFromString(StringView string) {
|
|||||||
|
|
||||||
hexLen = 0;
|
hexLen = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (!hexLen++)
|
else if (!hexLen++)
|
||||||
hexPtr = ptr;
|
hexPtr = ptr;
|
||||||
|
|
||||||
|
@ -255,6 +255,7 @@ NetworkedAnimator& NetworkedAnimator::operator=(NetworkedAnimator&& animator) {
|
|||||||
m_animationRate = move(animator.m_animationRate);
|
m_animationRate = move(animator.m_animationRate);
|
||||||
m_globalTags = move(animator.m_globalTags);
|
m_globalTags = move(animator.m_globalTags);
|
||||||
m_partTags = move(animator.m_partTags);
|
m_partTags = move(animator.m_partTags);
|
||||||
|
m_cachedPartDrawables = move(animator.m_cachedPartDrawables);
|
||||||
|
|
||||||
setupNetStates();
|
setupNetStates();
|
||||||
|
|
||||||
@ -278,6 +279,7 @@ NetworkedAnimator& NetworkedAnimator::operator=(NetworkedAnimator const& animato
|
|||||||
m_animationRate = animator.m_animationRate;
|
m_animationRate = animator.m_animationRate;
|
||||||
m_globalTags = animator.m_globalTags;
|
m_globalTags = animator.m_globalTags;
|
||||||
m_partTags = animator.m_partTags;
|
m_partTags = animator.m_partTags;
|
||||||
|
m_cachedPartDrawables = animator.m_cachedPartDrawables;
|
||||||
|
|
||||||
setupNetStates();
|
setupNetStates();
|
||||||
|
|
||||||
@ -638,7 +640,20 @@ List<pair<Drawable, float>> NetworkedAnimator::drawablesWithZLevel(Vec2F const&
|
|||||||
if (usedImage[0] != '/')
|
if (usedImage[0] != '/')
|
||||||
relativeImage = AssetPath::relativeTo(m_relativePath, usedImage);
|
relativeImage = AssetPath::relativeTo(m_relativePath, usedImage);
|
||||||
|
|
||||||
auto drawable = Drawable::makeImage(!relativeImage.empty() ? relativeImage : usedImage, 1.0f / TilePixels, centered, Vec2F());
|
size_t hash = hashOf(relativeImage);
|
||||||
|
auto find = m_cachedPartDrawables.find(partName);
|
||||||
|
bool fail = find == m_cachedPartDrawables.end() || find->second.first != hash;
|
||||||
|
if (fail) {
|
||||||
|
Drawable drawable = Drawable::makeImage(!relativeImage.empty() ? relativeImage : usedImage, 1.0f / TilePixels, centered, Vec2F());
|
||||||
|
if (find == m_cachedPartDrawables.end())
|
||||||
|
find = m_cachedPartDrawables.emplace(partName, std::pair{ hash, move(drawable) }).first;
|
||||||
|
else {
|
||||||
|
find->second.first = hash;
|
||||||
|
find->second.second = move(drawable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Drawable drawable = find->second.second;
|
||||||
auto& imagePart = drawable.imagePart();
|
auto& imagePart = drawable.imagePart();
|
||||||
for (Directives const& directives : baseProcessingDirectives)
|
for (Directives const& directives : baseProcessingDirectives)
|
||||||
imagePart.addDirectives(directives);
|
imagePart.addDirectives(directives);
|
||||||
|
@ -324,6 +324,7 @@ private:
|
|||||||
|
|
||||||
NetElementHashMap<String, String> m_globalTags;
|
NetElementHashMap<String, String> m_globalTags;
|
||||||
StableStringMap<NetElementHashMap<String, String>> m_partTags;
|
StableStringMap<NetElementHashMap<String, String>> m_partTags;
|
||||||
|
mutable StringMap<std::pair<size_t, Drawable>> m_cachedPartDrawables;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user