RenderHandler.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 IConstImage;
  17. class RenderHandler : public IRenderHandler
  18. {
  19. using AnimationLayoutMap = std::map<size_t, std::vector<JsonNode>>;
  20. struct ImageLocator
  21. {
  22. ImagePath image;
  23. AnimationPath animation;
  24. int frame = -1;
  25. int group = -1;
  26. bool verticalFlip = false;
  27. bool horizontalFlip = false;
  28. ImageLocator(const JsonNode & config);
  29. ImageLocator(const ImagePath & path);
  30. ImageLocator(const AnimationPath & path, int frame, int group);
  31. bool operator < (const ImageLocator & other) const;
  32. };
  33. std::map<AnimationPath, std::shared_ptr<CDefFile>> animationFiles;
  34. std::map<AnimationPath, AnimationLayoutMap> animationLayouts;
  35. std::map<ImageLocator, std::shared_ptr<IConstImage>> imageFiles;
  36. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  37. AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
  38. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);
  39. void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
  40. void addImageListEntries(const EntityService * service);
  41. std::shared_ptr<IConstImage> loadImageFromSingleFile(const ImagePath & path);
  42. std::shared_ptr<IConstImage> loadImageFromAnimationFileUncached(const AnimationPath & path, int frame, int group);
  43. std::shared_ptr<IConstImage> loadImageFromAnimationFile(const AnimationPath & path, int frame, int group);
  44. std::shared_ptr<IConstImage> loadImageImpl(const ImageLocator & config);
  45. public:
  46. // IRenderHandler implementation
  47. void onLibraryLoadingFinished(const Services * services) override;
  48. std::shared_ptr<IImage> loadImage(const JsonNode & config, EImageBlitMode mode) override;
  49. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  50. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group, EImageBlitMode mode) override;
  51. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path, EImageBlitMode mode) override;
  52. std::shared_ptr<IImage> createImage(SDL_Surface * source) override;
  53. };