All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ResourceNode.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Resources.h"
7 #include "MortonKey.h"
8 #include <vector>
9 
10 namespace Eegeo
11 {
12  namespace Streaming
13  {
14  class ResourceNode : protected Eegeo::NonCopyable
15  {
16  private:
17  typedef std::vector<Resources::IBuiltResource*> TResourceVector;
18  TResourceVector m_resources;
19  int m_numOfPoolAdds;
20  int m_numOfPoolAllocates;
21 
22  public:
23  ResourceNode(const std::vector<Resources::IBuiltResource*>& resources);
24 
25  ~ResourceNode();
26 
27  int count() { return static_cast<int>(m_resources.size()); }
28  const std::vector<Resources::IBuiltResource*> &resources() { return m_resources; }
29 
30  void AddedToSceneGraph(MortonKey key);
31  void RemovedFromSceneGraph();
32 
33  void SetAddedToPool(void)
34  {
35  const bool notInCache = m_numOfPoolAdds == m_numOfPoolAllocates;
36  Eegeo_ASSERT(notInCache, "ResourceNode should not be in cache (%d adds, %d removes)", m_numOfPoolAdds, m_numOfPoolAllocates);
37  m_numOfPoolAdds++;
38  }
39 
40  void SetAllocatedFromPool(void)
41  {
42  const bool isInCache = m_numOfPoolAdds == (m_numOfPoolAllocates + 1);
43  Eegeo_ASSERT(isInCache, "ResourceNode should be in cache (%d adds, %d removes)", m_numOfPoolAdds, m_numOfPoolAllocates);
44  m_numOfPoolAllocates++;
45  }
46  };
47  }
48 }