AnimEngine
Scene.hpp
1 #pragma once
2 #ifndef KJY_ANIM_ENGINE_SCENE_HPP_
3 #define KJY_ANIM_ENGINE_SCENE_HPP_
4 #include <vector>
5 #include <iostream>
6 #include "util/Timeline.hpp"
7 #include "components/inheritable/drawable.hpp"
8 #include "components/inheritable/poseable.hpp"
9 #include "components/inheritable/camera.hpp"
10 #include "Entities/TypicalEntities.inl"
11 
12 class Scene {
13  public:
14 
15  void pauseAll() {mGlobalTime.pause(); mAnimationTime.pause(); mEffectTime.pause(); }
16  void unpauseAll() {mGlobalTime.unpause(); mAnimationTime.unpause(); mEffectTime.unpause(); }
17  void togglePauseAll() {mGlobalTime.togglePause(); mAnimationTime.togglePause(); mEffectTime.togglePause(); }
18 
19  void addEntity(Entity* entity);
20 
21 
27  template<typename DynamicType = Entity*>
28  DynamicType findEntityByUUID(ent_uuid_t aId);
29 
35  template<typename DynamicType = Entity*>
36  const DynamicType findConstEntityByUUID(ent_uuid_t aId) const;
37 
45  template<typename DynamicType = Entity*>
46  DynamicType findEntityByName(const std::string& aName);
47 
55  template<typename DynamicType = Entity*>
56  const DynamicType findConstEntityByName(const std::string& aName) const;
57 
58  bool mShouldExit = false;
59 
60  std::vector<BaseCameraEntity*> cameras;
61  size_t mActiveCameraIndex = 0;
62 
63  AnimatorCollection animators;
64 
65  std::unordered_map<ent_uuid_t, Entity*> entities;
66 
67  Timeline mGlobalTime = Timeline(true);
68  Timeline mAnimationTime = Timeline(true);
69  Timeline mEffectTime = Timeline(true);
70 
71  double mFrameTime = 0.0;
72 
73  double mStartTime = 0.0;
74  double mEndTime = -1.0;
75 
76  std::string mSceneSpecialization;
77 
78  std::unordered_map<ent_uuid_t, Entity*> _all_entities;
79 
80  protected:
81  void _traverse_entity_for_bookeeping(Entity* entity);
82 };
83 
84 template<typename DynamicType>
85 DynamicType Scene::findEntityByUUID(ent_uuid_t aId){
86  static_assert(std::is_pointer<DynamicType>::value, "Error: Type parameter given to findEntityByUUID must be a pointer to a type derived from Entity*");
87 
88  auto foundEnt = _all_entities.find(aId);
89  if(foundEnt != _all_entities.end()){
90  return(dynamic_cast<DynamicType>(foundEnt->second));
91  }
92  return(nullptr);
93 }
94 
95 template<typename DynamicType>
96 const DynamicType Scene::findConstEntityByUUID(ent_uuid_t aId) const{
97  static_assert(std::is_pointer<DynamicType>::value, "Error: Type parameter given to findEntityByUUID must be a pointer to a type derived from Entity*");
98 
99  auto foundEnt = _all_entities.find(aId);
100  if(foundEnt != _all_entities.end()){
101  return(dynamic_cast<const DynamicType>(foundEnt->second));
102  }
103  return(nullptr);
104 }
105 
106 template<typename DynamicType>
107 DynamicType Scene::findEntityByName(const std::string& aName){
108  static_assert(std::is_pointer<DynamicType>::value, "Error: Type parameter given to findEntityByName must be a pointer to a type derived from Entity*");
109  for(auto& [uuid, entity] : _all_entities){
110  if(entity->getName() == aName){
111  return(dynamic_cast<DynamicType>(entity));
112  }
113  }
114  return(nullptr);
115 }
116 
117 template<typename DynamicType>
118 const DynamicType Scene::findConstEntityByName(const std::string& aName) const{
119  static_assert(std::is_pointer<DynamicType>::value, "Error: Type parameter given to findEntityByName must be a pointer to a type derived from Entity*");
120  for(auto& [uuid, entity] : _all_entities){
121  if(entity->getName() == aName){
122  return(dynamic_cast<const DynamicType>(entity));
123  }
124  }
125  return(nullptr);
126 }
127 
128 #endif
DynamicType findEntityByName(const std::string &aName)
Definition: Scene.hpp:107
Definition: Timeline.hpp:9
Definition: EntitiesBase.hpp:18
const DynamicType findConstEntityByUUID(ent_uuid_t aId) const
Definition: Scene.hpp:96
const DynamicType findConstEntityByName(const std::string &aName) const
Definition: Scene.hpp:118
DynamicType findEntityByUUID(ent_uuid_t aId)
Definition: Scene.hpp:85
Definition: Scene.hpp:12