浏览代码

Added caching for creature icons in garrisons

More complete version of caching will be done for 1.4
Fixes freezes on hero movement when hota mod is used
Ivan Savenko 2 年之前
父节点
当前提交
c8ec0d5419
共有 3 个文件被更改,包括 20 次插入2 次删除
  1. 14 0
      client/render/Graphics.cpp
  2. 4 0
      client/render/Graphics.h
  3. 2 2
      client/widgets/CGarrisonInt.cpp

+ 14 - 0
client/render/Graphics.cpp

@@ -299,3 +299,17 @@ void Graphics::initializeImageLists()
 	addImageListEntries(CGI->spells());
 	addImageListEntries(CGI->skills());
 }
+
+std::shared_ptr<CAnimation> Graphics::getAnimation(const std::string & path)
+{
+	ResourceID animationPath(path, EResType::ANIMATION);
+
+	if (cachedAnimations.count(animationPath.getName()) != 0)
+		return cachedAnimations.at(animationPath.getName());
+
+	auto newAnimation = std::make_shared<CAnimation>(animationPath.getName());
+
+	newAnimation->preload();
+	cachedAnimations[animationPath.getName()] = newAnimation;
+	return newAnimation;
+}

+ 4 - 0
client/render/Graphics.h

@@ -47,7 +47,11 @@ class Graphics
 	void loadFonts();
 	void initializeImageLists();
 
+	std::map<std::string, std::shared_ptr<CAnimation>> cachedAnimations;
+
 public:
+	std::shared_ptr<CAnimation> getAnimation(const std::string & path);
+
 	//Fonts
 	static const int FONTS_NUMBER = 9;
 	std::array< std::shared_ptr<IFont>, FONTS_NUMBER> fonts;

+ 2 - 2
client/widgets/CGarrisonInt.cpp

@@ -422,10 +422,10 @@ CGarrisonSlot::CGarrisonSlot(CGarrisonInt * Owner, int x, int y, SlotID IID, EGa
 
 	std::string imgName = owner->smallIcons ? "cprsmall" : "TWCRPORT";
 
-	creatureImage = std::make_shared<CAnimImage>(imgName, 0);
+	creatureImage = std::make_shared<CAnimImage>(graphics->getAnimation(imgName), 0);
 	creatureImage->disable();
 
-	selectionImage = std::make_shared<CAnimImage>(imgName, 1);
+	selectionImage = std::make_shared<CAnimImage>(graphics->getAnimation(imgName), 1);
 	selectionImage->disable();
 
 	if(Owner->smallIcons)