vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Cache.h
Go to the documentation of this file.
1 #ifndef _CACHE
2 #define _CACHE 1
3 
4 #include "ModelManager.h"
6 #include <map>
7 #include <list>
8 #include <string>
9 #include <vrecko/World.h>
10 #include <osg/Timer>
11 #include "model.h"
12 #include "Preloader.h"
13 
14 using namespace vrecko;
15 using namespace ArtificialWorld;
16 
18 class CacheInfo{
19 public:
20  CacheInfo(){};
21  CacheInfo(osg::ref_ptr<EnvironmentObject> _eo, osg::Vec3 _position, osg::Timer_t _timestamp, ModelType _modelType){
22  eo = _eo.get();
23  position = _position;
24  timestamp = _timestamp;
25  modelType = _modelType;
26  };
27 
29  eo = NULL;
30  };
31 
32  bool operator==(const CacheInfo &ci2) const{
33  return (eo == ci2.eo);
34  };
35 
36  bool operator!=(const CacheInfo &ci2) const{
37  return !(*this == ci2);
38  }
40  osg::ref_ptr<EnvironmentObject> eo;
42  osg::Vec3 position;
44  osg::Timer_t timestamp;
47 };
48 
50 class Cache : public GetObserver, public DeleteObserver, public AddObserver, public Ability
51 {
52 public:
53  Cache(): Ability("Cache"){ lastUpdateTime = updateTimer.tick(); };
54  ~Cache(void);
55 
56  void initialize(void);
57 
58  void init(bool useTime, unsigned long time, bool useDistance, unsigned long distance, unsigned long update_time){
59  cacheTimeEnabled = useTime;
60  holding_time = time;
61  cacheDistanceEnabled = useDistance;
62  holding_distance = distance;
63  update_time_ms = update_time;
64  preloader = NULL;
65  usePreloader = false;
66  }
67 
69  void update(void);
70 
72  bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parametersNode);
73 
80  void GetUpdate(string modelFilename, int num, ModelType modelType);
81 
83  void DeleteUpdate(osg::ref_ptr<EnvironmentObject> deletingObject, int num, ModelType modelType);
84 
86  void AddUpdate(string modelFilename, ModelType modelType);
87 
89  void CreatePreloader(BlockUpdater *rootBlockUpdater)
90  {
91  if(preloader != NULL)
92  {
93  DeletePreloader();
94  }
95 
96  preloader = new Preloader(rootBlockUpdater);
97  preloader->Start();
98  usePreloader = true;
99  };
100 
102  void DeletePreloader(void)
103  {
104  if(preloader != NULL)
105  {
106  if(preloader->Running())
107  {
108  preloader->Stop();
109  }
110  delete preloader;
111  preloader = NULL;
112  usePreloader = false;
113  }
114  }
115 
116 private:
118  map<string, CacheInfo*> searchDataNamed;
120  list<CacheInfo> data;
121 
123  unsigned long holding_distance;
125  unsigned long holding_time;
127  unsigned long update_time_ms;
129  bool cacheTimeEnabled;
131  bool cacheDistanceEnabled;
133  bool usePreloader;
135  Preloader *preloader;
136 
138  osg::Timer updateTimer;
140  osg::Timer_t lastUpdateTime;
141 };
142 #endif
143