All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PayloadBuildManager.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Tasks.h"
7 #include "Streaming.h"
8 #include "Resources.h"
9 #include "Helpers.h"
10 #include <vector>
11 
12 namespace Eegeo
13 {
14  namespace Streaming
15  {
16  class ResourceNodeCache;
17  class BuildWorkItem;
18 
20  {
21  // this limits total number of async inflates in progress. We can't cancel a build job once issued,
22  // so need to keep this reasonably small to avoid a backlog of unwanted builds when moving around rapidly
23  // static const int buildWorkItemPoolSize = 20;
24 
25  // alter this to throttle number of async builds issued in any one frame. Smaller values
26  // help avoid many requests completing on same frame and causing hitching as we do finalise on
27  // main thread
28 #ifdef EMSCRIPTEN
29  static const int maxPayloadBuildsIssuedPerFrame = 1;
30 #else
31  static const int maxPayloadBuildsIssuedPerFrame = 5;
32 #endif
33 
34  private:
35  BuildPrioritiser& m_buildPrioritiser;
36  ResourceNodeCache& m_resourceNodeCache;
38  Helpers::IHttpCache& m_httpCache;
39  size_t m_activeJobs;
40 
41  std::vector<Payload*> m_prioritisedPayloads;
42 
43  public:
45  BuildPrioritiser& buildPrioritiser,
46  ResourceNodeCache& resourceNodeCache,
48  Helpers::IHttpCache& httpCache);
50  void UpdateBuilds(float deltaTimeMs, int updateCount);
51  void HandleWorkItemCompleted(BuildWorkItem* pCompletedItem);
52  Helpers::IHttpCache& GetHttpCache() const;
53 
54  private:
55  BuildWorkItem* GetNextAvailableWorkItem();
56  void BuildAsync(BuildWorkItem& workItem, Payload& pPayload, Concurrency::Tasks::Priority::Values priority);
57  };
58  }
59 }