Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarNetworkedAnimator.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-26 21:39:22 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-26 21:39:22 +1000
commitf2fedb0c878120d4887ae9c1c14d4ac1a8881d85 (patch)
treec2608376bbc22ddf3763e21c442c27b36a6cf383 /source/game/StarNetworkedAnimator.cpp
parent14ef69c0f6309d64a358b25cf6395bc80a4c6ff5 (diff)
cache NetworkedAnimator drawables
could use a LruCache later
Diffstat (limited to 'source/game/StarNetworkedAnimator.cpp')
-rw-r--r--source/game/StarNetworkedAnimator.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/source/game/StarNetworkedAnimator.cpp b/source/game/StarNetworkedAnimator.cpp
index 5c5c3fb..c5b3591 100644
--- a/source/game/StarNetworkedAnimator.cpp
+++ b/source/game/StarNetworkedAnimator.cpp
@@ -255,6 +255,7 @@ NetworkedAnimator& NetworkedAnimator::operator=(NetworkedAnimator&& animator) {
m_animationRate = move(animator.m_animationRate);
m_globalTags = move(animator.m_globalTags);
m_partTags = move(animator.m_partTags);
+ m_cachedPartDrawables = move(animator.m_cachedPartDrawables);
setupNetStates();
@@ -278,6 +279,7 @@ NetworkedAnimator& NetworkedAnimator::operator=(NetworkedAnimator const& animato
m_animationRate = animator.m_animationRate;
m_globalTags = animator.m_globalTags;
m_partTags = animator.m_partTags;
+ m_cachedPartDrawables = animator.m_cachedPartDrawables;
setupNetStates();
@@ -638,7 +640,20 @@ List<pair<Drawable, float>> NetworkedAnimator::drawablesWithZLevel(Vec2F const&
if (usedImage[0] != '/')
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();
for (Directives const& directives : baseProcessingDirectives)
imagePart.addDirectives(directives);