Advertisement
Guest User

Untitled

a guest
Jun 17th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | None | 0 0
  1. #ifndef INCLUDE_DISPLAY_CHARACTERDISPLAYER_HPP
  2. #define INCLUDE_DISPLAY_CHARACTERDISPLAYER_HPP
  3.  
  4. #include <string>
  5. #include <vector>
  6. #include <yaml-cpp/yaml.h>
  7. #include "DisplayInterface.hpp"
  8. #include "SpriteDisplayer.hpp"
  9. #include "../ExternalResource.hpp"
  10. #include "../ResourcesHolder.hpp"
  11. #include "../maths/Matrix.hpp"
  12. #include "../maths/Vector.hpp"
  13.  
  14. namespace Display {
  15.     /**
  16.      *
  17.      */
  18.     class CharacterDisplayer {
  19.     public:
  20.         explicit CharacterDisplayer(DisplayInterface&);
  21.  
  22.         /**
  23.          *
  24.          */
  25.         void        setCharacterResource(const std::string&);
  26.  
  27.  
  28.         /**
  29.          * Draws the character using the matrix
  30.          */
  31.         void        draw(const Maths::Matrix<4>&) const;
  32.  
  33.  
  34.  
  35.     private:
  36.         struct BoneAttributes {
  37.             BoneAttributes() : x(0), y(0), rotation(0), scaleX(1), scaleY(1) {}
  38.  
  39.             float               x;
  40.             float               y;
  41.             float               rotation;
  42.             float               scaleX;
  43.             float               scaleY;
  44.         };
  45.  
  46.         struct SlotAttributes {
  47.             std::string         attachment;
  48.             // TODO: color
  49.         };
  50.  
  51.         struct Attachment {
  52.             std::string                             textureName;
  53.             Maths::Matrix<4>                        matrixToSlot;
  54.             std::shared_ptr<SpriteDisplayer>        displayer;
  55.             // TODO: fps and mode
  56.         };
  57.  
  58.         struct BoneTimelineElement {
  59.             float                                           time;
  60.             std::function<float (float)>                    curveFunction;
  61.             BoneTimelineElement*                            next;
  62.             std::function<void (BoneAttributes&)>           apply;
  63.         };
  64.  
  65.         struct SlotTimelineElement {
  66.             float                                           time;
  67.             std::function<float (float)>                    curveFunction;
  68.             SlotTimelineElement*                            next;
  69.             std::function<void (SlotAttributes&)>           apply;
  70.         };
  71.  
  72.         typedef std::vector<std::shared_ptr<BoneTimelineElement>>       BoneTimeline;
  73.         typedef std::vector<std::shared_ptr<SlotTimelineElement>>       SlotTimeline;
  74.  
  75.         struct Animation {
  76.             std::unordered_map<std::string,BoneTimeline>        bonesTimelines;         // for each bone name, a timeline
  77.             std::unordered_map<std::string,SlotTimeline>        slotsTimelines;
  78.             float                                               maxTime;
  79.         };
  80.  
  81.         struct Bone {
  82.             std::string                                                         parentBone;
  83.             BoneAttributes                                                      defaultSetup;
  84.             mutable std::unordered_map<std::string,BoneTimelineElement*>        currentTimelineElements;
  85.         };
  86.  
  87.         struct Slot {
  88.             std::string                                                         bone;
  89.             SlotAttributes                                                      attributes;
  90.             mutable std::unordered_map<std::string,SlotTimelineElement*>        currentTimelineElements;
  91.         };
  92.  
  93.     private:
  94.         DisplayInterface&                               mDisplay;
  95.         mutable ResourcesHolder                         mResources;
  96.         YAML::Node                                      mCharacterInfos;
  97.         std::string                                     mCurrentAnimation;
  98.         mutable float                                   mCurrentAnimationElapsedTime;
  99.  
  100.         std::unordered_map<std::string,Bone>            mBones;
  101.         std::unordered_map<std::string,Slot>            mSlots;
  102.  
  103.         std::unordered_map<std::string,std::unordered_map<std::string,std::unordered_map<std::string,Attachment>>>
  104.                                                         mSkins;
  105.         std::unordered_map<std::string,Animation>       mAnimations;
  106.  
  107.  
  108.     private:
  109.         static std::function<float (float)>             parseCurveFunction(const YAML::Node&);
  110.     };
  111. }
  112.  
  113. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement