All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
StreamingController.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Streaming.h"
7 #include "Web.h"
8 #include "AsyncTexturing.h"
9 #include "AsyncModels.h"
10 #include "Rendering.h"
11 #include "CameraFrustumStreamingVolume.h"
12 #include "Camera.h"
13 #include "MortonKey.h"
14 #include "ICallback.h"
15 #include "CallbackCollection.h"
16 #include <vector>
17 
18 namespace Eegeo
19 {
20  namespace Streaming
21  {
23  {
24  public:
25  virtual bool operator()(const Payload& payload) const = 0;
26  };
27 
29 
30 
32  {
33  private:
34 
35  std::vector<MortonKey> m_keysThatAreNowVisible;
36  std::vector<MortonKey> m_keysThatAreNoLongerVisible;
37  std::vector<MortonKey> m_currentlyVisibleKeys;
38 
39  PayloadWebLoader* m_pPayloadWebLoader;
40  PayloadBuildManager *m_pBuildManager;
41  CameraFrustumStreamingVolume *m_pStreamingVolume;
42  StreamingVolumeController *m_pStreamingVolumeController;
43  QuadTreeCube *m_pQuadTreeCube;
44  QuadTreeVisibilityUpdater *m_pVisibilityUpdater;
45  LoadPrioritiser *m_pLoadPrioritiser;
46  PayloadPool *m_pPayloadPool;
47  PayloadEvicter *m_pPayloadEvicter;
48  SceneGraphUpdater *m_pSceneGraphUpdater;
49  RedundantNodeEvicter *m_pNodeEvicter;
50  PayloadSlotStreamMap *m_pPayloadSlotStreamMap;
51  PayloadPlaceholderBuilder *m_pPayloadPlaceholderBuilder;
52  TerrainPlaceholderInserter *m_pTerrainPlaceholderInserter;
53  ResourceNodeCache* m_pResourceNodeCache;
54  Web::PrecacheService *m_pPrecachingService;
55  Rendering::AsyncTexturing::HttpAsyncTextureLoader& m_httpAsyncTextureLoader;
56  Rendering::AsyncTexturing::HttpAsyncCubeTextureLoader& m_httpAsyncCubeTextureLoader;
57  Io::AsyncModels::HttpAsyncModelLoader& m_asyncModelLoader;
58 
59  int m_updateCount;
60  bool m_enabled;
61  bool m_evictAllOnNextUpdate;
62 
63  std::vector<Payload*> m_payloadsToLoadInPriorityOrder;
64 
65  // Temporary visibility set observation
66  std::vector<TKeysCallback*> m_keyVisibleCallbacks;
67  std::vector<TKeysCallback*> m_keyInvisibleCallbacks;
68 
69  Web::WebConnectivityValidator& m_webConnectivityValidator;
70  Helpers::TCallback0<StreamingController> m_webConnectivityStateChangedCallback;
71  Helpers::CallbackCollection0 m_streamsChangedCallbacks;
72 
73  public:
74  StreamingController(PayloadWebLoader* pPayloadWebLoader,
75  PayloadBuildManager *pBuildManager,
76  CameraFrustumStreamingVolume *pStreamingVolume,
77  StreamingVolumeController *pStreamingVolumeController,
78  QuadTreeCube *pQuadTreeCube,
79  QuadTreeVisibilityUpdater *pVisibilityUpdater,
80  LoadPrioritiser *pLoadPrioritiser,
81  PayloadPool *pPayloadPool,
82  PayloadEvicter *pPayloadEvicter,
83  SceneGraphUpdater *pSceneGraphUpdater,
84  RedundantNodeEvicter *pNodeEvicter,
85  PayloadSlotStreamMap *pPayloadSlotStreamMap,
86  PayloadPlaceholderBuilder *pPayloadPlaceholderBuilder,
87  TerrainPlaceholderInserter *pTerrainPlaceholderInserter,
88  ResourceNodeCache* pResourceNodeCache,
89  Web::PrecacheService *pPrecachingService,
93  Web::WebConnectivityValidator& webConnectivityValidator);
94 
95  virtual ~StreamingController();
96 
97  void SetLODStreams(const std::vector<Eegeo::Streaming::LodStreamMap>& lodStreamMaps);
98  void Render();
99  void Update(float deltaSeconds,
100  const Camera::RenderCamera& renderCamera,
101  const dv3& ecefInterestPoint,
102  Streaming::IStreamingVolume& streamingVolume);
103  int numPayloadsWaitingToLoad();
104  int numPayloadsWaitingToBuild();
105  int numPayloadsPendingLoadCompletion() const;
106  int numPayloadsFailedLoad();
107  int numPayloadsCompleted(const IStreamingControllerPayloadFilter* payloadFilter=NULL) const;
108  int totalPayloadsAllocated(const IStreamingControllerPayloadFilter* payloadFilter=NULL) const;
109  bool AllPayloadsAreInSceneOrErrored(const IStreamingControllerPayloadFilter* payloadFilter=NULL);
110  bool AnyPayloadsInScene() const;
111  PayloadStateStats GetPayloadStateStats() const;
112  void evictAllOnNextUpdate();
113  void SetEnabled(bool enabled);
114  bool Enabled();
115  bool AllTexturesLoadedOrErrored() const;
116 
117  void RegisterStreamsChangedCallback(Helpers::ICallback0& callback);
118 
119  void UnregisterStreamsChangedCallback(Helpers::ICallback0& callback);
120 
121  void RegisterKeyVisibleCallback(TKeysCallback* callback);
122  void UnregisterKeyVisibleCallback(TKeysCallback* callback);
123  void RegisterKeyInvisibleCallback(TKeysCallback* callback);
124  void UnregisterKeyInvisibleCallback(TKeysCallback* callback);
125 
126  void CallKeyVisibleCallbacks(const std::vector<MortonKey>& newlyVisibleKeys);
127  void CallKeyInvisibleCallbacks(const std::vector<MortonKey>& newlyInvisibleKeys);
128 
129  const std::vector<MortonKey>& GetCurrentlyVisibleMortonKeys() const;
130 
131  private:
132  void issueLoadRequests(int updateCount);
133 
134  void OnWebConnectivityStateChanged();
135  };
136  }
137 }