forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbamCache.I
More file actions
271 lines (253 loc) · 10.5 KB
/
bamCache.I
File metadata and controls
271 lines (253 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// Filename: bamCache.I
// Created by: drose (09Jun06)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: BamCache::set_active
// Access: Published
// Description: Changes the state of the active flag. "active" means
// that the cache should be consulted automatically on
// loads, "not active" means that objects should be
// loaded directly without consulting the cache.
//
// This represents the global flag. Also see the
// individual cache_models, cache_textures,
// cache_compressed_textures flags.
////////////////////////////////////////////////////////////////////
INLINE void BamCache::
set_active(bool active) {
ReMutexHolder holder(_lock);
_active = active;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_active
// Access: Published
// Description: Returns true if the BamCache is currently active,
// false if it is not. "active" means that the cache
// should be consulted automatically on loads, "not
// active" means that objects should be loaded directly
// without consulting the cache.
//
// This represents the global flag. Also see the
// individual cache_models, cache_textures,
// cache_compressed_textures flags.
////////////////////////////////////////////////////////////////////
INLINE bool BamCache::
get_active() const {
ReMutexHolder holder(_lock);
return _active;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::set_cache_models
// Access: Published
// Description: Indicates whether model files (e.g. egg files and bam
// files) will be stored in the cache, as bam files.
////////////////////////////////////////////////////////////////////
INLINE void BamCache::
set_cache_models(bool flag) {
ReMutexHolder holder(_lock);
_cache_models = flag;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_cache_models
// Access: Published
// Description: Returns whether model files (e.g. egg files and bam
// files) will be stored in the cache, as bam files.
//
// This also returns false if get_active() is false.
////////////////////////////////////////////////////////////////////
INLINE bool BamCache::
get_cache_models() const {
ReMutexHolder holder(_lock);
return _cache_models && _active;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::set_cache_textures
// Access: Published
// Description: Indicates whether texture files will be stored in the
// cache, as uncompressed txo files.
////////////////////////////////////////////////////////////////////
INLINE void BamCache::
set_cache_textures(bool flag) {
ReMutexHolder holder(_lock);
_cache_textures = flag;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_cache_textures
// Access: Published
// Description: Returns whether texture files (e.g. egg files and bam
// files) will be stored in the cache, as txo files.
//
// This also returns false if get_active() is false.
////////////////////////////////////////////////////////////////////
INLINE bool BamCache::
get_cache_textures() const {
ReMutexHolder holder(_lock);
return _cache_textures && _active;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::set_cache_compressed_textures
// Access: Published
// Description: Indicates whether compressed texture files will be
// stored in the cache, as compressed txo files. The
// compressed data may either be generated in-CPU, via
// the squish library, or it may be extracted from the
// GSG after the texture has been loaded.
//
// This may be set in conjunction with
// set_cache_textures(), or independently of it. If
// set_cache_textures() is true and this is false, all
// textures will be cached in their uncompressed form.
// If set_cache_textures() is false and this is true,
// only compressed textures will be cached, and they
// will be cached in their compressed form. If both are
// true, all textures will be cached, in their
// uncompressed or compressed form appropriately.
////////////////////////////////////////////////////////////////////
INLINE void BamCache::
set_cache_compressed_textures(bool flag) {
ReMutexHolder holder(_lock);
_cache_compressed_textures = flag;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_cache_compressed_textures
// Access: Published
// Description: Returns whether compressed texture files will be
// stored in the cache, as compressed txo files. See
// set_cache_compressed_textures().
//
// This also returns false if get_active() is false.
////////////////////////////////////////////////////////////////////
INLINE bool BamCache::
get_cache_compressed_textures() const {
ReMutexHolder holder(_lock);
return _cache_compressed_textures && _active;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_root
// Access: Published
// Description: Returns the current root pathname of the cache. See
// set_root().
////////////////////////////////////////////////////////////////////
INLINE Filename BamCache::
get_root() const {
ReMutexHolder holder(_lock);
return _root;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::set_flush_time
// Access: Published
// Description: Specifies the time in seconds between automatic
// flushes of the cache index.
////////////////////////////////////////////////////////////////////
INLINE void BamCache::
set_flush_time(int flush_time) {
ReMutexHolder holder(_lock);
_flush_time = flush_time;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_flush_time
// Access: Published
// Description: Returns the time in seconds between automatic
// flushes of the cache index.
////////////////////////////////////////////////////////////////////
INLINE int BamCache::
get_flush_time() const {
ReMutexHolder holder(_lock);
return _flush_time;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::set_cache_max_kbytes
// Access: Published
// Description: Specifies the maximum size, in kilobytes, which the
// cache is allowed to grow to. If a newly cached file
// would exceed this size, an older file is removed from
// the cache.
//
// Note that in the case of multiple different processes
// simultaneously operating on the same cache directory,
// the actual cache size may slightly exceed this value
// from time to time due to latency in checking between
// the processes.
////////////////////////////////////////////////////////////////////
INLINE void BamCache::
set_cache_max_kbytes(int max_kbytes) {
ReMutexHolder holder(_lock);
_max_kbytes = max_kbytes;
check_cache_size();
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_cache_max_kbytes
// Access: Published
// Description: Returns the maximum size, in kilobytes, which the
// cache is allowed to grow to. See
// set_cache_max_kbytes().
////////////////////////////////////////////////////////////////////
INLINE int BamCache::
get_cache_max_kbytes() const {
ReMutexHolder holder(_lock);
return _max_kbytes;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::set_read_only
// Access: Published
// Description: Can be used to put the cache in read-only mode,
// or take it out of read-only mode. Note that if you
// put it into read-write mode, and it discovers that
// it does not have write access, it will put itself
// right back into read-only mode.
////////////////////////////////////////////////////////////////////
INLINE void BamCache::
set_read_only(bool ro) {
ReMutexHolder holder(_lock);
_read_only = ro;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_read_only
// Access: Published
// Description: Returns true if the cache is in read-only mode.
// Normally, the cache starts in read-write mode. It
// can put itself into read-only mode automatically if
// it discovers that it does not have write access to
// the cache.
////////////////////////////////////////////////////////////////////
INLINE bool BamCache::
get_read_only() const {
ReMutexHolder holder(_lock);
return _read_only;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::get_global_ptr
// Access: Published, Static
// Description: Returns a pointer to the global BamCache object,
// which is used automatically by the ModelPool and
// TexturePool.
////////////////////////////////////////////////////////////////////
INLINE BamCache *BamCache::
get_global_ptr() {
if (_global_ptr == (BamCache *)NULL) {
make_global();
}
return _global_ptr;
}
////////////////////////////////////////////////////////////////////
// Function: BamCache::mark_index_stale
// Access: Private
// Description: Indicates that the index has been modified and will
// need to be written to disk eventually.
////////////////////////////////////////////////////////////////////
INLINE void BamCache::
mark_index_stale() {
if (_index_stale_since == 0) {
_index_stale_since = time(NULL);
}
}