Panda3D
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
BamCache Class Reference

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. More...
 
void flush_index ()
 Ensures the index is written to disk. More...
 
bool get_active () const
 
bool get_cache_compiled_shaders () const
 
bool get_cache_compressed_textures () const
 
int get_cache_max_kbytes () const
 
bool get_cache_models () const
 
bool get_cache_textures () const
 
int get_flush_time () const
 
bool get_read_only () const
 
Filename get_root () const
 
void list_index (std::ostream &out, int indent_level=0) const
 Writes the contents of the index to standard output. More...
 
 PT (BamCacheRecord) lookup(const Filename &source_filename
 
void set_active (bool flag)
 
void set_cache_compiled_shaders (bool flag)
 
void set_cache_compressed_textures (bool flag)
 
void set_cache_max_kbytes (int max_kbytes)
 
void set_cache_models (bool flag)
 
void set_cache_textures (bool flag)
 
void set_flush_time (int flush_time)
 
void set_read_only (bool ro)
 
void set_root (const Filename &root)
 
bool store (BamCacheRecord *record)
 Flushes a cache entry to disk. More...
 

Static Public Member Functions

static void consider_flush_global_index ()
 If there is a global BamCache object, calls consider_flush_index() on it. More...
 
static void flush_global_index ()
 If there is a global BamCache object, calls flush_index() on it. More...
 
static BamCacheget_global_ptr ()
 Returns a pointer to the global BamCache object, which is used automatically by the ModelPool and TexturePool. More...
 

Public Attributes

const std::string & cache_extension
 
 get_active
 Returns true if the BamCache is currently active, false if it is not. More...
 
 get_cache_compiled_shaders
 Returns whether compiled shader programs will be stored in the cache, as binary .txo files. More...
 
 get_cache_compressed_textures
 Returns whether compressed texture files will be stored in the cache, as compressed txo files. More...
 
 get_cache_max_kbytes
 Returns the maximum size, in kilobytes, which the cache is allowed to grow to. More...
 
 get_cache_models
 Returns whether model files (e.g. More...
 
 get_cache_textures
 Returns whether texture files (e.g. More...
 
 get_flush_time
 Returns the time in seconds between automatic flushes of the cache index. More...
 
 get_read_only
 Returns true if the cache is in read-only mode. More...
 
 get_root
 Returns the current root pathname of the cache. More...
 
 set_active
 Changes the state of the active flag. More...
 
 set_cache_compiled_shaders
 Indicates whether compiled shader programs will be stored in the cache, as binary .sho files. More...
 
 set_cache_compressed_textures
 Indicates whether compressed texture files will be stored in the cache, as compressed txo files. More...
 
 set_cache_max_kbytes
 Specifies the maximum size, in kilobytes, which the cache is allowed to grow to. More...
 
 set_cache_models
 Indicates whether model files (e.g. More...
 
 set_cache_textures
 Indicates whether texture files will be stored in the cache, as uncompressed txo files. More...
 
 set_flush_time
 Specifies the time in seconds between automatic flushes of the cache index. More...
 
 set_read_only
 Can be used to put the cache in read-only mode, or take it out of read-only mode. More...
 
 set_root
 Changes the current root pathname of the cache. More...
 

Detailed Description

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 42 of file bamCache.h.

Member Function Documentation

◆ consider_flush_global_index()

void BamCache::consider_flush_global_index ( )
inlinestatic

If there is a global BamCache object, calls consider_flush_index() on it.

Definition at line 234 of file bamCache.I.

References consider_flush_index().

Referenced by GraphicsEngine::render_frame().

◆ consider_flush_index()

void BamCache::consider_flush_index ( )

Flushes the index if enough time has elapsed since the index was last flushed.

Definition at line 317 of file bamCache.cxx.

References flush_index(), ReMutexDirect::try_lock(), and ReMutexDirect::unlock().

Referenced by consider_flush_global_index().

◆ flush_global_index()

void BamCache::flush_global_index ( )
inlinestatic

If there is a global BamCache object, calls flush_index() on it.

Definition at line 244 of file bamCache.I.

References flush_index().

◆ flush_index()

void BamCache::flush_index ( )

Ensures the index is written to disk.

Definition at line 342 of file bamCache.cxx.

References Filename::temporary().

Referenced by consider_flush_index(), and flush_global_index().

◆ get_global_ptr()

BamCache * BamCache::get_global_ptr ( )
inlinestatic

Returns a pointer to the global BamCache object, which is used automatically by the ModelPool and TexturePool.

Definition at line 223 of file bamCache.I.

◆ list_index()

void BamCache::list_index ( std::ostream &  out,
int  indent_level = 0 
) const

Writes the contents of the index to standard output.

Definition at line 394 of file bamCache.cxx.

◆ store()

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 188 of file bamCache.cxx.

Member Data Documentation

◆ get_active

bool BamCache::get_active
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 88 of file bamCache.h.

◆ get_cache_compiled_shaders

bool BamCache::get_cache_compiled_shaders
inline

Returns whether compiled shader programs will be stored in the cache, as binary .txo files.

See set_cache_compiled_shaders().

This also returns false if get_active() is false.

Definition at line 94 of file bamCache.h.

◆ get_cache_compressed_textures

bool BamCache::get_cache_compressed_textures
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 92 of file bamCache.h.

◆ get_cache_max_kbytes

int BamCache::get_cache_max_kbytes
inline

Returns the maximum size, in kilobytes, which the cache is allowed to grow to.

See set_cache_max_kbytes().

Definition at line 97 of file bamCache.h.

◆ get_cache_models

bool BamCache::get_cache_models
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 89 of file bamCache.h.

◆ get_cache_textures

bool BamCache::get_cache_textures
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 90 of file bamCache.h.

◆ get_flush_time

int BamCache::get_flush_time
inline

Returns the time in seconds between automatic flushes of the cache index.

Definition at line 96 of file bamCache.h.

◆ get_read_only

bool BamCache::get_read_only
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 98 of file bamCache.h.

◆ get_root

Filename BamCache::get_root
inline

Returns the current root pathname of the cache.

See set_root().

Definition at line 95 of file bamCache.h.

◆ set_active

void BamCache::set_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 88 of file bamCache.h.

◆ set_cache_compiled_shaders

void BamCache::set_cache_compiled_shaders
inline

Indicates whether compiled shader programs will be stored in the cache, as binary .sho files.

This may not be supported by all shader languages or graphics renderers.

Definition at line 94 of file bamCache.h.

◆ set_cache_compressed_textures

void BamCache::set_cache_compressed_textures
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 92 of file bamCache.h.

◆ set_cache_max_kbytes

void BamCache::set_cache_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 97 of file bamCache.h.

◆ set_cache_models

void BamCache::set_cache_models
inline

Indicates whether model files (e.g.

egg files and bam files) will be stored in the cache, as bam files.

Definition at line 89 of file bamCache.h.

◆ set_cache_textures

void BamCache::set_cache_textures
inline

Indicates whether texture files will be stored in the cache, as uncompressed txo files.

Definition at line 90 of file bamCache.h.

◆ set_flush_time

void BamCache::set_flush_time
inline

Specifies the time in seconds between automatic flushes of the cache index.

Definition at line 96 of file bamCache.h.

◆ set_read_only

void BamCache::set_read_only
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 98 of file bamCache.h.

◆ set_root

void BamCache::set_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 95 of file bamCache.h.


The documentation for this class was generated from the following files: