Panda3D
 All Classes Functions Variables Enumerations
bamCache.I
00001 // Filename: bamCache.I
00002 // Created by:  drose (09Jun06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: BamCache::set_active
00018 //       Access: Published
00019 //  Description: Changes the state of the active flag.  "active" means
00020 //               that the cache should be consulted automatically on
00021 //               loads, "not active" means that objects should be
00022 //               loaded directly without consulting the cache.
00023 //
00024 //               This represents the global flag.  Also see the
00025 //               individual cache_models, cache_textures,
00026 //               cache_compressed_textures flags.
00027 ////////////////////////////////////////////////////////////////////
00028 INLINE void BamCache::
00029 set_active(bool active) {
00030   ReMutexHolder holder(_lock);
00031   _active = active;
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: BamCache::get_active
00036 //       Access: Published
00037 //  Description: Returns true if the BamCache is currently active,
00038 //               false if it is not.  "active" means that the cache
00039 //               should be consulted automatically on loads, "not
00040 //               active" means that objects should be loaded directly
00041 //               without consulting the cache.
00042 //
00043 //               This represents the global flag.  Also see the
00044 //               individual cache_models, cache_textures,
00045 //               cache_compressed_textures flags.
00046 ////////////////////////////////////////////////////////////////////
00047 INLINE bool BamCache::
00048 get_active() const {
00049   ReMutexHolder holder(_lock);
00050   return _active;
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: BamCache::set_cache_models
00055 //       Access: Published
00056 //  Description: Indicates whether model files (e.g. egg files and bam
00057 //               files) will be stored in the cache, as bam files.
00058 ////////////////////////////////////////////////////////////////////
00059 INLINE void BamCache::
00060 set_cache_models(bool flag) {
00061   ReMutexHolder holder(_lock);
00062   _cache_models = flag;
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: BamCache::get_cache_models
00067 //       Access: Published
00068 //  Description: Returns whether model files (e.g. egg files and bam
00069 //               files) will be stored in the cache, as bam files.
00070 //
00071 //               This also returns false if get_active() is false.
00072 ////////////////////////////////////////////////////////////////////
00073 INLINE bool BamCache::
00074 get_cache_models() const {
00075   ReMutexHolder holder(_lock);
00076   return _cache_models && _active;
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: BamCache::set_cache_textures
00081 //       Access: Published
00082 //  Description: Indicates whether texture files will be stored in the
00083 //               cache, as uncompressed txo files.
00084 ////////////////////////////////////////////////////////////////////
00085 INLINE void BamCache::
00086 set_cache_textures(bool flag) {
00087   ReMutexHolder holder(_lock);
00088   _cache_textures = flag;
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: BamCache::get_cache_textures
00093 //       Access: Published
00094 //  Description: Returns whether texture files (e.g. egg files and bam
00095 //               files) will be stored in the cache, as txo files.
00096 //
00097 //               This also returns false if get_active() is false.
00098 ////////////////////////////////////////////////////////////////////
00099 INLINE bool BamCache::
00100 get_cache_textures() const {
00101   ReMutexHolder holder(_lock);
00102   return _cache_textures && _active;
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: BamCache::set_cache_compressed_textures
00107 //       Access: Published
00108 //  Description: Indicates whether compressed texture files will be
00109 //               stored in the cache, as compressed txo files.  The
00110 //               compressed data may either be generated in-CPU, via
00111 //               the squish library, or it may be extracted from the
00112 //               GSG after the texture has been loaded.
00113 //
00114 //               This may be set in conjunction with
00115 //               set_cache_textures(), or independently of it.  If
00116 //               set_cache_textures() is true and this is false, all
00117 //               textures will be cached in their uncompressed form.
00118 //               If set_cache_textures() is false and this is true,
00119 //               only compressed textures will be cached, and they
00120 //               will be cached in their compressed form.  If both are
00121 //               true, all textures will be cached, in their
00122 //               uncompressed or compressed form appropriately.
00123 ////////////////////////////////////////////////////////////////////
00124 INLINE void BamCache::
00125 set_cache_compressed_textures(bool flag) {
00126   ReMutexHolder holder(_lock);
00127   _cache_compressed_textures = flag;
00128 }
00129 
00130 ////////////////////////////////////////////////////////////////////
00131 //     Function: BamCache::get_cache_compressed_textures
00132 //       Access: Published
00133 //  Description: Returns whether compressed texture files will be
00134 //               stored in the cache, as compressed txo files.  See
00135 //               set_cache_compressed_textures().
00136 //
00137 //               This also returns false if get_active() is false.
00138 ////////////////////////////////////////////////////////////////////
00139 INLINE bool BamCache::
00140 get_cache_compressed_textures() const {
00141   ReMutexHolder holder(_lock);
00142   return _cache_compressed_textures && _active;
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: BamCache::get_root
00147 //       Access: Published
00148 //  Description: Returns the current root pathname of the cache.  See
00149 //               set_root().
00150 ////////////////////////////////////////////////////////////////////
00151 INLINE Filename BamCache::
00152 get_root() const {
00153   ReMutexHolder holder(_lock);
00154   return _root;
00155 }
00156 
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: BamCache::set_flush_time
00159 //       Access: Published
00160 //  Description: Specifies the time in seconds between automatic
00161 //               flushes of the cache index.
00162 ////////////////////////////////////////////////////////////////////
00163 INLINE void BamCache::
00164 set_flush_time(int flush_time) {
00165   ReMutexHolder holder(_lock);
00166   _flush_time = flush_time;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: BamCache::get_flush_time
00171 //       Access: Published
00172 //  Description: Returns the time in seconds between automatic
00173 //               flushes of the cache index.
00174 ////////////////////////////////////////////////////////////////////
00175 INLINE int BamCache::
00176 get_flush_time() const {
00177   ReMutexHolder holder(_lock);
00178   return _flush_time;
00179 }
00180 
00181 ////////////////////////////////////////////////////////////////////
00182 //     Function: BamCache::set_cache_max_kbytes
00183 //       Access: Published
00184 //  Description: Specifies the maximum size, in kilobytes, which the
00185 //               cache is allowed to grow to.  If a newly cached file
00186 //               would exceed this size, an older file is removed from
00187 //               the cache.
00188 //
00189 //               Note that in the case of multiple different processes
00190 //               simultaneously operating on the same cache directory,
00191 //               the actual cache size may slightly exceed this value
00192 //               from time to time due to latency in checking between
00193 //               the processes.
00194 ////////////////////////////////////////////////////////////////////
00195 INLINE void BamCache::
00196 set_cache_max_kbytes(int max_kbytes) {
00197   ReMutexHolder holder(_lock);
00198   _max_kbytes = max_kbytes;
00199   check_cache_size();
00200 }
00201 
00202 ////////////////////////////////////////////////////////////////////
00203 //     Function: BamCache::get_cache_max_kbytes
00204 //       Access: Published
00205 //  Description: Returns the maximum size, in kilobytes, which the
00206 //               cache is allowed to grow to.  See
00207 //               set_cache_max_kbytes().
00208 ////////////////////////////////////////////////////////////////////
00209 INLINE int BamCache::
00210 get_cache_max_kbytes() const {
00211   ReMutexHolder holder(_lock);
00212   return _max_kbytes;
00213 }
00214 
00215 ////////////////////////////////////////////////////////////////////
00216 //     Function: BamCache::set_read_only
00217 //       Access: Published
00218 //  Description: Can be used to put the cache in read-only mode,
00219 //               or take it out of read-only mode.  Note that if you
00220 //               put it into read-write mode, and it discovers that
00221 //               it does not have write access, it will put itself
00222 //               right back into read-only mode.
00223 ////////////////////////////////////////////////////////////////////
00224 INLINE void BamCache::
00225 set_read_only(bool ro) {
00226   ReMutexHolder holder(_lock);
00227   _read_only = ro;
00228 }
00229 
00230 ////////////////////////////////////////////////////////////////////
00231 //     Function: BamCache::get_read_only
00232 //       Access: Published
00233 //  Description: Returns true if the cache is in read-only mode.
00234 //               Normally, the cache starts in read-write mode.  It
00235 //               can put itself into read-only mode automatically if
00236 //               it discovers that it does not have write access to
00237 //               the cache.
00238 ////////////////////////////////////////////////////////////////////
00239 INLINE bool BamCache::
00240 get_read_only() const {
00241   ReMutexHolder holder(_lock);
00242   return _read_only;
00243 }
00244 
00245 ////////////////////////////////////////////////////////////////////
00246 //     Function: BamCache::get_global_ptr
00247 //       Access: Published, Static
00248 //  Description: Returns a pointer to the global BamCache object,
00249 //               which is used automatically by the ModelPool and
00250 //               TexturePool.
00251 ////////////////////////////////////////////////////////////////////
00252 INLINE BamCache *BamCache::
00253 get_global_ptr() {
00254   if (_global_ptr == (BamCache *)NULL) {
00255     make_global();
00256   }
00257   return _global_ptr;
00258 }
00259 
00260 ////////////////////////////////////////////////////////////////////
00261 //     Function: BamCache::mark_index_stale
00262 //       Access: Private
00263 //  Description: Indicates that the index has been modified and will
00264 //               need to be written to disk eventually.
00265 ////////////////////////////////////////////////////////////////////
00266 INLINE void BamCache::
00267 mark_index_stale() {
00268   if (_index_stale_since == 0) {
00269     _index_stale_since = time(NULL);
00270   }
00271 }
 All Classes Functions Variables Enumerations