All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
AggregateSceneElementInGraphObserver.h
1 #pragma once
2 
3 #include "ISceneElementInGraphObserver.h"
4 #include <vector>
5 
6 namespace Eegeo
7 {
8  namespace Rendering
9  {
10  namespace Scene
11  {
12  // Scene elements only have a single observer. Adding an array of observers to every scene element was thought to be a potential
13  // performance risk, so this type has been added to help the situation where we need multiple observers to be informed of something
14  // being added to or removed from the scenegraph. At the time of writing this only applies to custom landmarks on Unity.
15  template<typename T>
16  class AggregateSceneElementInGraphObserver : public ISceneElementInGraphObserver<T>
17  {
18  public:
19 
20  AggregateSceneElementInGraphObserver(const std::vector<ISceneElementInGraphObserver<T>*>& observers)
21  : m_observers(observers)
22  {
23 
24  }
25 
26  virtual void OnAddedToSceneGraph(SceneElement<T>* resource) override
27  {
28  for (auto pObserver : m_observers)
29  {
30  pObserver->OnAddedToSceneGraph(resource);
31  }
32  }
33 
34  virtual void OnRemovedFromSceneGraph(SceneElement<T>* resource) override
35  {
36  for (auto pObserver : m_observers)
37  {
38  pObserver->OnRemovedFromSceneGraph(resource);
39  }
40  }
41 
42  private:
43 
44  std::vector<ISceneElementInGraphObserver<T>*> m_observers;
45  };
46  }
47  }
48 }
49