panda3d.core.BamCache

from panda3d.core import BamCache
class BamCache

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).

Inheritance diagram

Inheritance diagram of BamCache

__init__() → None
setActive(flag: bool) → None

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.

getActive() → bool

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.

setCacheModels(flag: bool) → None

Indicates whether model files (e.g. egg files and bam files) will be stored in the cache, as bam files.

getCacheModels() → bool

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 getActive() is false.

setCacheTextures(flag: bool) → None

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

getCacheTextures() → bool

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 getActive() is false.

setCacheCompressedTextures(flag: bool) → None

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 setCacheTextures(), or independently of it. If setCacheTextures() is true and this is false, all textures will be cached in their uncompressed form. If setCacheTextures() 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.

getCacheCompressedTextures() → bool

Returns whether compressed texture files will be stored in the cache, as compressed txo files. See setCacheCompressedTextures().

This also returns false if getActive() is false.

setCacheCompiledShaders(flag: bool) → None

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.

getCacheCompiledShaders() → bool

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

This also returns false if getActive() is false.

setRoot(root: Filename) → None

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.

getRoot() → Filename

Returns the current root pathname of the cache. See setRoot().

Return type

Filename

setFlushTime(flush_time: int) → None

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

getFlushTime() → int

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

setCacheMaxKbytes(max_kbytes: int) → None

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.

getCacheMaxKbytes() → int

Returns the maximum size, in kilobytes, which the cache is allowed to grow to. See setCacheMaxKbytes().

setReadOnly(ro: bool) → None

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.

getReadOnly() → bool

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.

lookup(source_filename: Filename, cache_extension: str) → BamCacheRecord

Looks up a file in the cache.

If the file is cacheable, then regardless of whether the file is found in the cache or not, this returns a BamCacheRecord. On the other hand, if the file cannot be cached, returns NULL.

If record->has_data() returns true, then the file was found in the cache, and you may call record->extract_data() to get the object. If record->has_data() returns false, then the file was not found in the cache or the cache was stale; and you should reload the source file (calling record->add_dependent_file() for each file loaded, including the original source file), and then call record->set_data() to record the resulting loaded object; and finally, you should call store() to write the cached record to disk.

Return type

BamCacheRecord

store(record: BamCacheRecord) → bool

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.

considerFlushIndex() → None

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

flushIndex() → None

Ensures the index is written to disk.

listIndex(out: ostream, indent_level: int) → None

Writes the contents of the index to standard output.

static getGlobalPtr() → BamCache

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

Return type

BamCache

static considerFlushGlobalIndex() → None

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

static flushGlobalIndex() → None

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

property active
Getter

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.

Setter

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.

Return type

bool

property cache_models
Getter

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 getActive() is false.

Setter

Indicates whether model files (e.g. egg files and bam files) will be stored in the cache, as bam files.

Return type

bool

property cache_textures
Getter

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 getActive() is false.

Setter

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

Return type

bool

property cache_compressed_textures
Getter

Returns whether compressed texture files will be stored in the cache, as compressed txo files. See setCacheCompressedTextures().

This also returns false if getActive() is false.

Setter

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 setCacheTextures(), or independently of it. If setCacheTextures() is true and this is false, all textures will be cached in their uncompressed form. If setCacheTextures() 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.

Return type

bool

property cache_compiled_shaders
Getter

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

This also returns false if getActive() is false.

Setter

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.

Return type

bool

property root
Getter

Returns the current root pathname of the cache. See setRoot().

Setter

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.

Return type

Filename

property flush_time
Getter

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

Setter

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

Return type

int

property cache_max_kbytes
Getter

Returns the maximum size, in kilobytes, which the cache is allowed to grow to. See setCacheMaxKbytes().

Setter

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.

Return type

int

property read_only
Getter

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.

Setter

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.

Return type

bool