RenderHandler.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * RenderHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../render/IRenderHandler.h"
  12. #include "../render/CDefFile.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class EntityService;
  15. VCMI_LIB_NAMESPACE_END
  16. class CDefFile;
  17. class SDLImageShared;
  18. class ScalableImageShared;
  19. class AssetGenerator;
  20. class HdImageLoader;
  21. class RenderHandler final : public IRenderHandler
  22. {
  23. using AnimationLayoutMap = std::map<size_t, std::vector<ImageLocator>>;
  24. std::map<AnimationPath, std::map<int, std::map<int, std::pair<std::string, CDefFile::SSpriteDef>>>> animationSpriteDefs;
  25. std::map<AnimationPath, std::weak_ptr<CDefFile>> animationFiles;
  26. std::map<AnimationPath, AnimationLayoutMap> animationLayouts;
  27. std::map<SharedImageLocator, std::weak_ptr<ScalableImageShared>> imageFiles;
  28. std::map<EFonts, std::shared_ptr<const IFont>> fonts;
  29. std::shared_ptr<AssetGenerator> assetGenerator;
  30. std::shared_ptr<HdImageLoader> hdImageLoader;
  31. std::mutex animationCacheMutex;
  32. std::pair<std::string, CDefFile::SSpriteDef> getAnimationSpriteDef(const AnimationPath & path, int frame, int group);
  33. ImagePath getAnimationFrameName(const AnimationPath & path, int frame, int group);
  34. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  35. AnimationLayoutMap & getAnimationLayout(const AnimationPath & path, int scalingFactor, EImageBlitMode mode);
  36. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config, EImageBlitMode mode) const;
  37. void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
  38. void addImageListEntries(const EntityService * service);
  39. void storeCachedImage(const ImageLocator & locator, std::shared_ptr<ScalableImageShared> image);
  40. std::shared_ptr<ScalableImageShared> loadImageImpl(const ImageLocator & config);
  41. std::shared_ptr<ISharedImage> loadImageFromFileUncached(const ImageLocator & locator);
  42. ImageLocator getLocatorForAnimationFrame(const AnimationPath & path, int frame, int group, int scaling, EImageBlitMode mode);
  43. int getScalingFactor() const;
  44. public:
  45. RenderHandler();
  46. ~RenderHandler();
  47. // IRenderHandler implementation
  48. void onLibraryLoadingFinished(const Services * services) override;
  49. std::shared_ptr<IImage> loadImage(const ImageLocator & locator) override;
  50. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  51. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group, EImageBlitMode mode) override;
  52. std::shared_ptr<SDLImageShared> loadScaledImage(const ImageLocator & locator) override;
  53. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path, EImageBlitMode mode) override;
  54. std::shared_ptr<CanvasImage> createImage(const Point & size, CanvasScalingPolicy scalingPolicy) override;
  55. /// Returns font with specified identifer
  56. std::shared_ptr<const IFont> loadFont(EFonts font) override;
  57. void exportGeneratedAssets() override;
  58. std::shared_ptr<AssetGenerator> getAssetGenerator() override;
  59. void updateGeneratedAssets() override;
  60. };