AnimEngine
EntitiesBase.hpp
1 #pragma once
2 #ifndef KJY_ANIM_ENGINE_ENTITIES_BASE_HPP_
3 #define KJY_ANIM_ENGINE_ENTITIES_BASE_HPP_
4 
5 #include <string>
6 #include <map>
7 #include <components/inheritable/poseable.hpp>
8 #include <components/attachable/KeyframeAnimation.hpp>
9 #include <components/attachable/AttachableComponent.hpp>
10 #include <util/UUID.hpp>
11 
12 #pragma warning(disable: 4250) // Disable warnings about dominance in MSVC
13 
14 typedef uuid_t ent_uuid_t;
15 
16 std::string uuid_to_string(ent_uuid_t uuid);
17 
18 class Entity : virtual public PureComponent{
19  public:
20  Entity() : uuid(generate_uuid()) {}
21  Entity(const std::string& name) : uuid(generate_uuid()), _name(name) {}
22 
23  inline const ent_uuid_t& UUID() const {return(uuid);}
24 
25  inline const std::string& getName() const {return(_name);}
26  inline void setName(const std::string& name) {_name = name;}
27 
28  void addChild(Entity* entity);
29  virtual void unlink();
30  virtual void link(Entity* parent);
31 
33  virtual Entity* replace(Entity* replacement);
34 
35  inline const std::map<ent_uuid_t, Entity*>& getChildren() const {return(_children);}
36  inline size_t numChildren() const {return(_children.size());}
37  inline bool hasParent() const {return(_parent != nullptr);}
38  inline Entity* getParent() {return(_parent);}
39  inline const Entity* getParent() const {return(_parent);}
40 
41  unsigned int traversal_scratch = 0;
42 
43  protected:
44  std::string _name;
45  Entity* _parent = nullptr;
46  std::map<ent_uuid_t, Entity*> _children;
47 
48  // Needed since sometimes the final world pose is needed for rendering, but determined during animation.
49 
50  private:
51  ent_uuid_t uuid;
52 };
53 
54 class WorldEntity : virtual public Entity, virtual public PosedComponent{
55  public:
56  virtual ~WorldEntity() {};
57 };
58 
59 class PoseableWorldEntity : virtual public WorldEntity, virtual public PoseableComponent{
60  public:
61  virtual ~PoseableWorldEntity() {};
62 };
63 
64 class StaticEmptyEntity : virtual public WorldEntity{
65  public:
67  StaticEmptyEntity(const Pose& pose) : pose(pose) {}
68  virtual const Pose& getPose() const override {return(pose);}
69 
70  protected:
71  Pose pose;
72 };
73 
74 struct EmptyEntity : virtual public StaticEmptyEntity, virtual public PoseableWorldEntity{
75  EmptyEntity(){}
76  EmptyEntity(const Pose& aPose) : StaticEmptyEntity(aPose) {}
77  virtual const Pose& getPose() const override {return(this->pose);}
78  virtual Pose& getMutablePose() {return(this->pose);}
79  virtual void setPose(const Pose& aPose) override {this->pose = aPose;}
80 };
81 
83 {
84  public:
85  virtual const Pose& getCachedFinalPose() const {return(_mCachedFinalPose);}
86  virtual void setCachedFinalPose(const Pose& aPose) {_mCachedFinalPose = aPose;}
87 
88  protected:
89  Pose _mCachedFinalPose;
90 };
91 
92 #endif
Definition: rootcomponent.hpp:5
Definition: EntitiesBase.hpp:54
Definition: EntitiesBase.hpp:82
Definition: poseable.hpp:10
Definition: EntitiesBase.hpp:59
Definition: EntitiesBase.hpp:74
Definition: EntitiesBase.hpp:18
virtual Entity * replace(Entity *replacement)
Replace the node in the tree with &#39;replacement&#39; and return original node (&#39;this&#39;) ...
Definition: EntitiesBase.cpp:29
Definition: EntitiesBase.hpp:64
Definition: poseable.hpp:16
Definition: Pose.hpp:11