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) 2024 MAK Technologies, Inc.
3 * All rights reserved.
4 *****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvCore/vrvCore.h>
13 
15 #include <tbb/task_arena.h>
16 
17 #include <boost/thread.hpp>
18 
19 #include <unordered_map>
20 
21 // FIXME:
22 // This should not be in vrvCore!!
23 namespace osgUtil
24 {
25  class StateToCompile;
26 }
27 
28 namespace makVrv
29 {
30  class DtDe;
31  class DtModel;
32  class DtBackgroundLoader;
33  struct DtLoaderHandle;
34 
38  {
39  public:
41  static DtBackgroundLoader& instance(DtDe& de);
42 
44  virtual ~DtBackgroundLoader();
45  protected:
48  private:
50  DtBackgroundLoader() = delete;
52  DtBackgroundLoader(const DtBackgroundLoader&) = delete;
54  DtBackgroundLoader& operator=(const DtBackgroundLoader&) = delete;
55  public:
56 
59  virtual void updateQueue(int max_thread_count, int active_threads);
60 
62  virtual DtLoaderHandle* queueForLoad(DtModel* object);
63 
68  virtual void setForegroundTimeBudget(double budget);
69 
71  virtual void incrementForegroundTime(double time_elapse);
72 
74  virtual bool isForegroundTimeBudgetExpired() const;
75 
77  virtual double timeSpentThisFrame() const;
79 
82  virtual void loadIfPossibleOrAddToQueue(DtModel* object);
83 
85  virtual bool hasActiveAsyncTasks() const;
86 
88  virtual int numModelDefinitionsToIco() const;
90  virtual std::string nextModelDefinitionToIco();
91 
93  virtual int numOfActiveTasks() const;
94 
96  virtual void addToAdditionalIcoList(osgUtil::StateToCompile* compile);
97 
99  virtual std::list<osgUtil::StateToCompile*>& additionalToIcoList();
100 
102  virtual bool multithreadedLoadingActive() const;
104  virtual void setMultithreadedLoadingActive(bool val);
105  protected:
107  virtual void timedForegroundLoad(DtModel* object);
108 
109  virtual void ts_setModelDefinitionLoaded(const std::string& modelDefinition);
110  virtual bool ts_isModelDefinitionLoaded(const std::string& modelDefinition) const;
111 
112  protected:
114 
116 
117  boost::mutex myProducerQueueMutex;
118  std::list< DtLoaderHandle* > myProducerQueue;
119  std::list< DtLoaderHandle* > myForegroundQueue;
120  std::list< std::string > myModelDefsToIcoQueue;
121 
122  std::list<DtLoaderHandle* > myObjectsFinishedWithTBBTask;
123  std::list<osgUtil::StateToCompile* > myAdditionalToIcoList;
124 
125  boost::mutex myTaskFinishedMutex;
126  std::list<DtLoaderHandle* > myObjectsToForegroundLoad;
127 
128  std::map<std::string, bool> myActivelyLoadingModelDefs;
129  std::atomic<int> myNumberOfActiveTasks;
130 
132  mutable boost::mutex myMutableLoadedDefMapMutex;
133  std::unordered_map<std::string, bool> myLoadedDefMap;
134 
137 
138  tbb::task_arena myTaskArena;
139  };
140 };
std::unordered_map< std::string, bool > myLoadedDefMap
Definition: DtBackgroundLoader.h:133
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:128
std::list< DtLoaderHandle * > myForegroundQueue
Definition: DtBackgroundLoader.h:119
tbb::task_arena myTaskArena
Definition: DtBackgroundLoader.h:138
async task that loads a DtModel in the background
Definition: DtBackgroundLoadAsyncTask.h:24
core singleton that manages loading for all the various DtModel subclasses
Definition: DtBackgroundLoader.h:37
boost::mutex myMutableLoadedDefMapMutex
Definition: DtBackgroundLoader.h:132
bool myMultithreadedLoadingActive
Definition: DtBackgroundLoader.h:136
DtDe & myDe
Definition: DtBackgroundLoader.h:113
double myForegroundTimeBudget
Definition: DtBackgroundLoader.h:135
Contains makVrv::DtVirtualBaseClass class.
boost::mutex myTaskFinishedMutex
Definition: DtBackgroundLoader.h:125
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:123
std::list< std::string > myModelDefsToIcoQueue
Definition: DtBackgroundLoader.h:120
std::list< DtLoaderHandle * > myObjectsToForegroundLoad
Definition: DtBackgroundLoader.h:126
std::list< DtLoaderHandle * > myProducerQueue
Definition: DtBackgroundLoader.h:118
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:76
std::atomic< int > myNumberOfActiveTasks
Definition: DtBackgroundLoader.h:129
std::list< DtLoaderHandle * > myObjectsFinishedWithTBBTask
Definition: DtBackgroundLoader.h:122
boost::mutex myProducerQueueMutex
Definition: DtBackgroundLoader.h:117
double myTimeSpentThisFrame
Definition: DtBackgroundLoader.h:131
Contains DLL export macros.

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)