All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
InteriorsInstanceRepository.h
1 // Copyright eeGeo Ltd (2012-2016), All Rights Reserved
2 
3 #pragma once
4 
5 
6 #include "Interiors.h"
7 
8 #include "Types.h"
9 #include "Rendering.h"
10 #include "InteriorsCellResourceObserver.h"
11 #include "CallbackCollection.h"
12 #include "CollisionBvh.h"
13 
14 #include <map>
15 #include <vector>
16 #include <set>
17 #include <string>
18 
19 
20 namespace Eegeo
21 {
22  namespace Resources
23  {
24  namespace Interiors
25  {
27  {
28  std::string InstanceId;
29  int FloorNum;
30  std::string InteriorId;
31  int TransformIndexInRenderable;
33  const Collision::CollisionBvh* CollisionBvh;
34 
35  InstanceStore() :
36  InstanceId(""),
37  FloorNum(-1),
38  InteriorId(""),
39  TransformIndexInRenderable(0),
40  Renderable(nullptr),
41  CollisionBvh(nullptr)
42  {}
43 
44  InstanceStore(const std::string& instanceId, Rendering::Renderables::InstancedInteriorFloorRenderable* renderable, const Collision::CollisionBvh* collisionBvh, int floor, const std::string& interiorId, int transformIndexInRenderable) :
45  InstanceId(instanceId),
46  FloorNum(floor),
47  InteriorId(interiorId),
48  TransformIndexInRenderable(transformIndexInRenderable),
49  Renderable(renderable),
50  CollisionBvh(collisionBvh)
51  {
52  }
53  };
54 
56  {
57  std::map<std::string, std::map<std::string, InstanceStore>> m_instanceIdMappings;
58 
59  InteriorsCellResourceObserver& m_cellResourceObserver;
61 
62  Helpers::CallbackCollection0 m_changedCallbacks;
63 
64  void HandleFloorCellDeleted(const InteriorsCellResource& interiorCellResource);
65 
66  void NotifyChanged();
67 
68  bool ContainsInstanceIdMapForInterior(const std::string& interiorId) const;
69 
70  std::map<std::string, std::set<const Collision::CollisionBvh*>> m_interiorBvhMappings;
71 
72  public:
75 
76  struct InstanceData
77  {
78  std::string id;
80  const Collision::CollisionBvh* pBvh;
81  int transformIndexInRenderable;
82  };
83 
84  void AddInstance(const InstanceData& data, int floorNum, const std::string& interiorId);
85  void AddInstances(const std::vector<InstanceData>& instanceDatas, int floorNum, const std::string& interiorId);
86 
87  bool Contains(const std::string& interiorId, const std::string& id) const;
88  bool TryGet(const std::string& interiorId, const std::string& id, InstanceStore& out_instanceStore) const;
89  bool TryGetInteriorIdForInstance(const std::string& id, std::string& out_interiorId) const;
90 
91  void RemoveId(const std::string& interiorId, const std::string& id);
92 
94  bool Contains(const std::string& id) const;
96  InstanceStore Get(const std::string& id) const;
98  void RemoveId(const std::string& id);
99 
100  const std::vector<InstanceStore> GetInstancesInInterior(const std::string& interiorId) const;
101  const std::vector<InstanceStore> GetInstancesOnFloor(const std::string& interiorId, int floorNum) const;
102 
103  void RegisterChangedCallback(Helpers::ICallback0& callback);
104  void UnregisterChangedCallback(Helpers::ICallback0& callback);
105  private:
106  void DoAddInstance(const InstanceData& data, int floorNum, const std::string& interiorId);
107  };
108  }
109  }
110 }