RenderHandler.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. class CDefFile;
  13. class IConstImage;
  14. class RenderHandler : public IRenderHandler
  15. {
  16. using AnimationLayoutMap = std::map<size_t, std::vector<JsonNode>>;
  17. struct AnimationLocator
  18. {
  19. AnimationPath animation;
  20. int frame = -1;
  21. int group = -1;
  22. bool operator < (const AnimationLocator & other) const
  23. {
  24. if (animation != other.animation)
  25. return animation < other.animation;
  26. if (group != other.group)
  27. return group < other.group;
  28. return frame < other.frame;
  29. }
  30. };
  31. std::map<AnimationPath, std::shared_ptr<CDefFile>> animationFiles;
  32. std::map<AnimationPath, AnimationLayoutMap> animationLayouts;
  33. std::map<ImagePath, std::shared_ptr<IConstImage>> imageFiles;
  34. std::map<AnimationLocator, std::shared_ptr<IConstImage>> animationFrames;
  35. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  36. const AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
  37. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);
  38. public:
  39. // IRenderHandler implementation
  40. std::shared_ptr<IImage> loadImage(const ImagePath & path) override;
  41. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  42. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group) override;
  43. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path) override;
  44. std::shared_ptr<IImage> createImage(SDL_Surface * source) override;
  45. std::shared_ptr<CAnimation> createAnimation() override;
  46. };