VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtBackgroundLoader.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Copyright (c) 2020 MAK Technologies, Inc.
3 * All rights reserved.
4 *****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvCore/vrvCore.h>
13 
15 
16 #include <tbb/atomic.h>
17 #include <tbb/task.h>
18 
19 #include <boost/thread.hpp>
20 
21 #include <unordered_map>
22 
23 // FIXME:
24 // This should not be in vrvCore!!
25 namespace osgUtil
26 {
27  class StateToCompile;
28 }
29 
30 namespace makVrv
31 {
32  class DtDe;
33  class DtModel;
34  class DtBackgroundLoader;
35  struct DtLoaderHandle;
36 
40  {
41  public:
43  static DtBackgroundLoader& instance(DtDe& de);
44 
46  virtual ~DtBackgroundLoader();
47  protected:
50  private:
52  DtBackgroundLoader() = delete;
54  DtBackgroundLoader(const DtBackgroundLoader&) = delete;
56  DtBackgroundLoader& operator=(const DtBackgroundLoader&) = delete;
57  public:
58 
61  virtual void updateQueue(int max_thread_count, int active_threads);
62 
64  virtual DtLoaderHandle* queueForLoad(DtModel* object);
65 
70  virtual void setForegroundTimeBudget(double budget);
71 
73  virtual void incrementForegroundTime(double time_elapse);
74 
76  virtual bool isForegroundTimeBudgetExpired() const;
77 
79  virtual double timeSpentThisFrame() const;
81 
84  virtual void loadIfPossibleOrAddToQueue(DtModel* object);
85 
87  virtual bool hasActiveAsyncTasks() const;
88 
90  virtual int numModelDefinitionsToIco() const;
92  virtual std::string nextModelDefinitionToIco();
93 
95  virtual int numOfActiveTasks() const;
96 
98  virtual void addToAdditionalIcoList(osgUtil::StateToCompile* compile);
99 
101  virtual std::list<osgUtil::StateToCompile*>& additionalToIcoList();
102 
104  virtual bool multithreadedLoadingActive() const;
106  virtual void setMultithreadedLoadingActive(bool val);
107  protected:
109  virtual void timedForegroundLoad(DtModel* object);
110 
111  virtual void ts_setModelDefinitionLoaded(const std::string& modelDefinition);
112  virtual bool ts_isModelDefinitionLoaded(const std::string& modelDefinition) const;
113 
114  protected:
116 
118 
119  boost::mutex myProducerQueueMutex;
120  std::list< DtLoaderHandle* > myProducerQueue;
121  std::list< DtLoaderHandle* > myForegroundQueue;
122  std::list< std::string > myModelDefsToIcoQueue;
123 
124  std::list<DtLoaderHandle* > myObjectsFinishedWithTBBTask;
125  std::list<osgUtil::StateToCompile* > myAdditionalToIcoList;
126 
127  boost::mutex myTaskFinishedMutex;
128  std::list<DtLoaderHandle* > myObjectsToForegroundLoad;
129 
130  std::map<std::string, bool> myActivelyLoadingModelDefs;
131  tbb::atomic<int> myNumberOfActiveTasks;
132 
134  mutable boost::mutex myMutableLoadedDefMapMutex;
135  std::unordered_map<std::string, bool> myLoadedDefMap;
136 
139  };
140 };
std::unordered_map< std::string, bool > myLoadedDefMap
Definition: DtBackgroundLoader.h:135
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
std::map< std::string, bool > myActivelyLoadingModelDefs
Definition: DtBackgroundLoader.h:130
std::list< DtLoaderHandle * > myForegroundQueue
Definition: DtBackgroundLoader.h:121
async task that loads a DtModel in the background
Definition: DtBackgroundLoadAsyncTask.h:26
core singleton that manages loading for all the various DtModel subclasses
Definition: DtBackgroundLoader.h:39
boost::mutex myMutableLoadedDefMapMutex
Definition: DtBackgroundLoader.h:134
bool myMultithreadedLoadingActive
Definition: DtBackgroundLoader.h:138
tbb::atomic< int > myNumberOfActiveTasks
Definition: DtBackgroundLoader.h:131
DtDe & myDe
Definition: DtBackgroundLoader.h:115
double myForegroundTimeBudget
Definition: DtBackgroundLoader.h:137
Contains makVrv::DtVirtualBaseClass class.
boost::mutex myTaskFinishedMutex
Definition: DtBackgroundLoader.h:127
wrapper object that insulates the loader from other threads destroying an object
Definition: DtLoaderHandle.h:23
#define DT_DLL_VRVCORE
Definition: vrvCore.h:20
std::list< osgUtil::StateToCompile * > myAdditionalToIcoList
Definition: DtBackgroundLoader.h:125
std::list< std::string > myModelDefsToIcoQueue
Definition: DtBackgroundLoader.h:122
std::list< DtLoaderHandle * > myObjectsToForegroundLoad
Definition: DtBackgroundLoader.h:128
std::list< DtLoaderHandle * > myProducerQueue
Definition: DtBackgroundLoader.h:120
A model which owns a single model instance. A DtModel is a managing container for a single DtModelIns...
Definition: DtModel.h:56
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
std::list< DtLoaderHandle * > myObjectsFinishedWithTBBTask
Definition: DtBackgroundLoader.h:124
boost::mutex myProducerQueueMutex
Definition: DtBackgroundLoader.h:119
double myTimeSpentThisFrame
Definition: DtBackgroundLoader.h:133
Contains DLL export macros.

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)