Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef INCLUDE_DISPLAY_CHARACTERDISPLAYER_HPP
- #define INCLUDE_DISPLAY_CHARACTERDISPLAYER_HPP
- #include <string>
- #include <vector>
- #include <yaml-cpp/yaml.h>
- #include "DisplayInterface.hpp"
- #include "SpriteDisplayer.hpp"
- #include "../ExternalResource.hpp"
- #include "../ResourcesHolder.hpp"
- #include "../maths/Matrix.hpp"
- #include "../maths/Vector.hpp"
- namespace Display {
- /**
- *
- */
- class CharacterDisplayer {
- public:
- explicit CharacterDisplayer(DisplayInterface&);
- /**
- *
- */
- void setCharacterResource(const std::string&);
- /**
- * Draws the character using the matrix
- */
- void draw(const Maths::Matrix<4>&) const;
- private:
- struct BoneAttributes {
- BoneAttributes() : x(0), y(0), rotation(0), scaleX(1), scaleY(1) {}
- float x;
- float y;
- float rotation;
- float scaleX;
- float scaleY;
- };
- struct SlotAttributes {
- std::string attachment;
- // TODO: color
- };
- struct Attachment {
- std::string textureName;
- Maths::Matrix<4> matrixToSlot;
- std::shared_ptr<SpriteDisplayer> displayer;
- // TODO: fps and mode
- };
- struct BoneTimelineElement {
- float time;
- std::function<float (float)> curveFunction;
- BoneTimelineElement* next;
- std::function<void (BoneAttributes&)> apply;
- };
- struct SlotTimelineElement {
- float time;
- std::function<float (float)> curveFunction;
- SlotTimelineElement* next;
- std::function<void (SlotAttributes&)> apply;
- };
- typedef std::vector<std::shared_ptr<BoneTimelineElement>> BoneTimeline;
- typedef std::vector<std::shared_ptr<SlotTimelineElement>> SlotTimeline;
- struct Animation {
- std::unordered_map<std::string,BoneTimeline> bonesTimelines; // for each bone name, a timeline
- std::unordered_map<std::string,SlotTimeline> slotsTimelines;
- float maxTime;
- };
- struct Bone {
- std::string parentBone;
- BoneAttributes defaultSetup;
- mutable std::unordered_map<std::string,BoneTimelineElement*> currentTimelineElements;
- };
- struct Slot {
- std::string bone;
- SlotAttributes attributes;
- mutable std::unordered_map<std::string,SlotTimelineElement*> currentTimelineElements;
- };
- private:
- DisplayInterface& mDisplay;
- mutable ResourcesHolder mResources;
- YAML::Node mCharacterInfos;
- std::string mCurrentAnimation;
- mutable float mCurrentAnimationElapsedTime;
- std::unordered_map<std::string,Bone> mBones;
- std::unordered_map<std::string,Slot> mSlots;
- std::unordered_map<std::string,std::unordered_map<std::string,std::unordered_map<std::string,Attachment>>>
- mSkins;
- std::unordered_map<std::string,Animation> mAnimations;
- private:
- static std::function<float (float)> parseCurveFunction(const YAML::Node&);
- };
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement