Panda3D
|
This class maintains a cache of Bam and/or Txo objects generated from model files and texture images (as well as possibly other kinds of loadable objects that can be stored in bam file format). More...
#include "bamCache.h"
Public Member Functions | |
void | consider_flush_index () |
Flushes the index if enough time has elapsed since the index was last flushed. | |
void | flush_index () |
Ensures the index is written to disk. | |
bool | get_active () const |
Returns true if the BamCache is currently active, false if it is not. | |
bool | get_cache_compressed_textures () const |
Returns whether compressed texture files will be stored in the cache, as compressed txo files. | |
int | get_cache_max_kbytes () const |
Returns the maximum size, in kilobytes, which the cache is allowed to grow to. | |
bool | get_cache_models () const |
Returns whether model files (e.g. | |
bool | get_cache_textures () const |
Returns whether texture files (e.g. | |
int | get_flush_time () const |
Returns the time in seconds between automatic flushes of the cache index. | |
bool | get_read_only () const |
Returns true if the cache is in read-only mode. | |
Filename | get_root () const |
Returns the current root pathname of the cache. | |
PT (BamCacheRecord) lookup(const Filename &source_filename | |
void | set_active (bool flag) |
Changes the state of the active flag. | |
void | set_cache_compressed_textures (bool flag) |
Indicates whether compressed texture files will be stored in the cache, as compressed txo files. | |
void | set_cache_max_kbytes (int max_kbytes) |
Specifies the maximum size, in kilobytes, which the cache is allowed to grow to. | |
void | set_cache_models (bool flag) |
Indicates whether model files (e.g. | |
void | set_cache_textures (bool flag) |
Indicates whether texture files will be stored in the cache, as uncompressed txo files. | |
void | set_flush_time (int flush_time) |
Specifies the time in seconds between automatic flushes of the cache index. | |
void | set_read_only (bool ro) |
Can be used to put the cache in read-only mode, or take it out of read-only mode. | |
void | set_root (const Filename &root) |
Changes the current root pathname of the cache. | |
bool | store (BamCacheRecord *record) |
Flushes a cache entry to disk. | |
Static Public Member Functions | |
static BamCache * | get_global_ptr () |
Returns a pointer to the global BamCache object, which is used automatically by the ModelPool and TexturePool. | |
Public Attributes | |
const string & | cache_extension |
This class maintains a cache of Bam and/or Txo objects generated from model files and texture images (as well as possibly other kinds of loadable objects that can be stored in bam file format).
This class also maintains a persistent index that lists all of the cached objects (see BamCacheIndex). We go through some considerable effort to make sure this index gets saved correctly to disk, even in the presence of multiple different processes writing to the same index, and without relying too heavily on low-level os-provided file locks (which work poorly with C++ iostreams).
Definition at line 47 of file bamCache.h.
void BamCache::consider_flush_index | ( | ) |
Flushes the index if enough time has elapsed since the index was last flushed.
Definition at line 315 of file bamCache.cxx.
References flush_index().
Referenced by GraphicsEngine::render_frame(), and store().
void BamCache::flush_index | ( | ) |
Ensures the index is written to disk.
Definition at line 331 of file bamCache.cxx.
References VirtualFileSystem::atomic_compare_and_exchange_contents(), VirtualFileSystem::delete_file(), Filename::get_basename(), and get_global_ptr().
Referenced by consider_flush_index(), GraphicsEngine::remove_all_windows(), and set_root().
bool BamCache::get_active | ( | ) | const [inline] |
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.
Definition at line 48 of file bamCache.I.
bool BamCache::get_cache_compressed_textures | ( | ) | const [inline] |
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.
Definition at line 140 of file bamCache.I.
Referenced by Texture::do_reload_ram_image().
int BamCache::get_cache_max_kbytes | ( | ) | const [inline] |
Returns the maximum size, in kilobytes, which the cache is allowed to grow to.
Definition at line 210 of file bamCache.I.
bool BamCache::get_cache_models | ( | ) | const [inline] |
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.
Definition at line 74 of file bamCache.I.
bool BamCache::get_cache_textures | ( | ) | const [inline] |
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.
Definition at line 100 of file bamCache.I.
Referenced by Texture::do_reload_ram_image().
int BamCache::get_flush_time | ( | ) | const [inline] |
Returns the time in seconds between automatic flushes of the cache index.
Definition at line 176 of file bamCache.I.
BamCache * BamCache::get_global_ptr | ( | ) | [inline, static] |
Returns a pointer to the global BamCache object, which is used automatically by the ModelPool and TexturePool.
Definition at line 253 of file bamCache.I.
Referenced by BamCacheRecord::add_dependent_file(), DXTextureContext8::create_texture(), DXTextureContext9::create_texture(), BamCacheRecord::dependents_unchanged(), Texture::do_reload_ram_image(), flush_index(), GraphicsEngine::remove_all_windows(), GraphicsEngine::render_frame(), set_root(), and store().
bool BamCache::get_read_only | ( | ) | const [inline] |
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.
Definition at line 240 of file bamCache.I.
Filename BamCache::get_root | ( | ) | const [inline] |
Returns the current root pathname of the cache.
See set_root().
Definition at line 152 of file bamCache.I.
void BamCache::set_active | ( | bool | active | ) | [inline] |
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.
Definition at line 29 of file bamCache.I.
void BamCache::set_cache_compressed_textures | ( | bool | flag | ) | [inline] |
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.
Definition at line 125 of file bamCache.I.
void BamCache::set_cache_max_kbytes | ( | int | max_kbytes | ) | [inline] |
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.
Definition at line 196 of file bamCache.I.
void BamCache::set_cache_models | ( | bool | flag | ) | [inline] |
Indicates whether model files (e.g.
egg files and bam files) will be stored in the cache, as bam files.
Definition at line 60 of file bamCache.I.
void BamCache::set_cache_textures | ( | bool | flag | ) | [inline] |
Indicates whether texture files will be stored in the cache, as uncompressed txo files.
Definition at line 86 of file bamCache.I.
void BamCache::set_flush_time | ( | int | flush_time | ) | [inline] |
Specifies the time in seconds between automatic flushes of the cache index.
Definition at line 164 of file bamCache.I.
void BamCache::set_read_only | ( | bool | ro | ) | [inline] |
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.
Definition at line 225 of file bamCache.I.
void BamCache::set_root | ( | const Filename & | root | ) |
Changes the current root pathname of the cache.
This specifies where the cache files are stored on disk. This should name a directory that is on a disk local to the machine (not on a network-mounted disk), for instance, /tmp/panda-cache or /c/panda-cache.
If the directory does not already exist, it will be created as a result of this call.
Definition at line 116 of file bamCache.cxx.
References flush_index(), get_global_ptr(), VirtualFileSystem::is_directory(), and VirtualFileSystem::make_directory_full().
bool BamCache::store | ( | BamCacheRecord * | record | ) |
Flushes a cache entry to disk.
You must have retrieved the cache record via a prior call to lookup(), and then stored the data via record->set_data(). Returns true on success, false on failure.
Definition at line 192 of file bamCache.cxx.
References DatagramOutputFile::close(), consider_flush_index(), VirtualFileSystem::delete_file(), VirtualFileSystem::exists(), TypeRegistry::find_type(), Thread::get_current_thread(), BamCacheRecord::get_data(), DatagramOutputFile::get_file_pos(), get_global_ptr(), Thread::get_unique_id(), BamCacheRecord::has_data(), BamWriter::init(), Filename::is_local(), TypedObject::is_of_type(), DatagramOutputFile::open(), TypeRegistry::ptr(), VirtualFileSystem::rename_file(), Filename::set_binary(), BamWriter::set_file_texture_mode(), DatagramOutputFile::write_header(), and BamWriter::write_object().
Referenced by DXTextureContext8::create_texture(), DXTextureContext9::create_texture(), and Texture::do_reload_ram_image().