RenderHandler.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. VCMI_LIB_NAMESPACE_BEGIN
  13. class EntityService;
  14. VCMI_LIB_NAMESPACE_END
  15. class CDefFile;
  16. class SDLImageShared;
  17. class ScalableImageShared;
  18. class AssetGenerator;
  19. class RenderHandler final : public IRenderHandler
  20. {
  21. using AnimationLayoutMap = std::map<size_t, std::vector<ImageLocator>>;
  22. std::map<AnimationPath, std::shared_ptr<CDefFile>> animationFiles;
  23. std::map<AnimationPath, AnimationLayoutMap> animationLayouts;
  24. std::map<SharedImageLocator, std::shared_ptr<ScalableImageShared>> imageFiles;
  25. std::map<EFonts, std::shared_ptr<const IFont>> fonts;
  26. std::unique_ptr<AssetGenerator> assetGenerator;
  27. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  28. AnimationLayoutMap & getAnimationLayout(const AnimationPath & path, int scalingFactor, EImageBlitMode mode);
  29. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config, EImageBlitMode mode) const;
  30. void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
  31. void addImageListEntries(const EntityService * service);
  32. void storeCachedImage(const ImageLocator & locator, std::shared_ptr<ScalableImageShared> image);
  33. std::shared_ptr<ScalableImageShared> loadImageImpl(const ImageLocator & config);
  34. std::shared_ptr<ISharedImage> loadImageFromFileUncached(const ImageLocator & locator);
  35. ImageLocator getLocatorForAnimationFrame(const AnimationPath & path, int frame, int group, int scaling, EImageBlitMode mode);
  36. int getScalingFactor() const;
  37. public:
  38. RenderHandler();
  39. ~RenderHandler();
  40. // IRenderHandler implementation
  41. void onLibraryLoadingFinished(const Services * services) override;
  42. std::shared_ptr<IImage> loadImage(const ImageLocator & locator) override;
  43. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  44. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group, EImageBlitMode mode) override;
  45. std::shared_ptr<SDLImageShared> loadScaledImage(const ImageLocator & locator) override;
  46. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path, EImageBlitMode mode) override;
  47. std::shared_ptr<CanvasImage> createImage(const Point & size, CanvasScalingPolicy scalingPolicy) override;
  48. /// Returns font with specified identifer
  49. std::shared_ptr<const IFont> loadFont(EFonts font) override;
  50. void exportGeneratedAssets() override;
  51. };