mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
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
This commit is contained in:
parent
ab4fb2a228
commit
c8ec0d5419
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user