RenderHandler.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 AnimationLocator
  21. {
  22. AnimationPath animation;
  23. int frame = -1;
  24. int group = -1;
  25. bool operator < (const AnimationLocator & other) const
  26. {
  27. if (animation != other.animation)
  28. return animation < other.animation;
  29. if (group != other.group)
  30. return group < other.group;
  31. return frame < other.frame;
  32. }
  33. };
  34. std::map<AnimationPath, std::shared_ptr<CDefFile>> animationFiles;
  35. std::map<AnimationPath, AnimationLayoutMap> animationLayouts;
  36. std::map<ImagePath, std::shared_ptr<IConstImage>> imageFiles;
  37. std::map<AnimationLocator, std::shared_ptr<IConstImage>> animationFrames;
  38. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  39. AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
  40. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);
  41. void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
  42. void addImageListEntries(const EntityService * service);
  43. public:
  44. // IRenderHandler implementation
  45. void onLibraryLoadingFinished(const Services * services) override;
  46. std::shared_ptr<IImage> loadImage(const ImagePath & path) override;
  47. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  48. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group) override;
  49. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path) override;
  50. std::shared_ptr<IImage> createImage(SDL_Surface * source) override;
  51. std::shared_ptr<CAnimation> createAnimation() override;
  52. };