BamCache

from panda3d.core import BamCache
class BamCache

Bases: DTOOL_SUPER_BASE

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__(*args, **kwargs)
active
cache_compiled_shaders
cache_compressed_textures
cache_max_kbytes
cache_models
cache_textures
considerFlushGlobalIndex()

C++ Interface: consider_flush_global_index()

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

*/

considerFlushIndex()

C++ Interface: consider_flush_index(const BamCache self)

/**
  • Flushes the index if enough time has elapsed since the index was last

  • flushed.

*/

consider_flush_global_index()

C++ Interface: consider_flush_global_index()

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

*/

consider_flush_index()

C++ Interface: consider_flush_index(const BamCache self)

/**
  • Flushes the index if enough time has elapsed since the index was last

  • flushed.

*/

flushGlobalIndex()

C++ Interface: flush_global_index()

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

*/

flushIndex()

C++ Interface: flush_index(const BamCache self)

/**
  • Ensures the index is written to disk.

*/

flush_global_index()

C++ Interface: flush_global_index()

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

*/

flush_index()

C++ Interface: flush_index(const BamCache self)

/**
  • Ensures the index is written to disk.

*/

flush_time
getActive()

C++ Interface: get_active(BamCache self)

/**
  • 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.

*/

getCacheCompiledShaders()

C++ Interface: get_cache_compiled_shaders(BamCache self)

/**
  • 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.

*/

getCacheCompressedTextures()

C++ Interface: get_cache_compressed_textures(BamCache self)

/**
  • 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.

*/

getCacheMaxKbytes()

C++ Interface: get_cache_max_kbytes(BamCache self)

/**
  • Returns the maximum size, in kilobytes, which the cache is allowed to grow

  • to. See set_cache_max_kbytes().

*/

getCacheModels()

C++ Interface: get_cache_models(BamCache self)

/**
  • 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.

*/

getCacheTextures()

C++ Interface: get_cache_textures(BamCache self)

/**
  • 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.

*/

getFlushTime()

C++ Interface: get_flush_time(BamCache self)

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

*/

getGlobalPtr()

C++ Interface: get_global_ptr()

/**
  • Returns a pointer to the global BamCache object, which is used

  • automatically by the ModelPool and TexturePool.

*/

getReadOnly()

C++ Interface: get_read_only(BamCache self)

/**
  • 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.

*/

getRoot()

C++ Interface: get_root(BamCache self)

/**
  • Returns the current root pathname of the cache. See set_root().

*/

get_active()

C++ Interface: get_active(BamCache self)

/**
  • 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.

*/

get_cache_compiled_shaders()

C++ Interface: get_cache_compiled_shaders(BamCache self)

/**
  • 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.

*/

get_cache_compressed_textures()

C++ Interface: get_cache_compressed_textures(BamCache self)

/**
  • 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.

*/

get_cache_max_kbytes()

C++ Interface: get_cache_max_kbytes(BamCache self)

/**
  • Returns the maximum size, in kilobytes, which the cache is allowed to grow

  • to. See set_cache_max_kbytes().

*/

get_cache_models()

C++ Interface: get_cache_models(BamCache self)

/**
  • 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.

*/

get_cache_textures()

C++ Interface: get_cache_textures(BamCache self)

/**
  • 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.

*/

get_flush_time()

C++ Interface: get_flush_time(BamCache self)

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

*/

get_global_ptr()

C++ Interface: get_global_ptr()

/**
  • Returns a pointer to the global BamCache object, which is used

  • automatically by the ModelPool and TexturePool.

*/

get_read_only()

C++ Interface: get_read_only(BamCache self)

/**
  • 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.

*/

get_root()

C++ Interface: get_root(BamCache self)

/**
  • Returns the current root pathname of the cache. See set_root().

*/

listIndex()

C++ Interface: list_index(BamCache self, ostream out, int indent_level)

/**
  • Writes the contents of the index to standard output.

*/

list_index()

C++ Interface: list_index(BamCache self, ostream out, int indent_level)

/**
  • Writes the contents of the index to standard output.

*/

lookup()

C++ Interface: lookup(const BamCache self, const Filename source_filename, str cache_extension)

/**
  • 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.

*/

read_only
root
setActive()

C++ Interface: set_active(const BamCache self, bool flag)

/**
  • 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.

*/

setCacheCompiledShaders()

C++ Interface: set_cache_compiled_shaders(const BamCache self, bool flag)

/**
  • 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.

*/

setCacheCompressedTextures()

C++ Interface: set_cache_compressed_textures(const BamCache self, bool flag)

/**
  • 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.

*/

setCacheMaxKbytes()

C++ Interface: set_cache_max_kbytes(const BamCache self, int max_kbytes)

/**
  • 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.

*/

setCacheModels()

C++ Interface: set_cache_models(const BamCache self, bool flag)

/**
  • Indicates whether model files (e.g. egg files and bam files) will be

  • stored in the cache, as bam files.

*/

setCacheTextures()

C++ Interface: set_cache_textures(const BamCache self, bool flag)

/**
  • Indicates whether texture files will be stored in the cache, as

  • uncompressed txo files.

*/

setFlushTime()

C++ Interface: set_flush_time(const BamCache self, int flush_time)

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

*/

setReadOnly()

C++ Interface: set_read_only(const BamCache self, bool ro)

/**
  • 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.

*/

setRoot()

C++ Interface: set_root(const BamCache self, 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.

*/

set_active()

C++ Interface: set_active(const BamCache self, bool flag)

/**
  • 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.

*/

set_cache_compiled_shaders()

C++ Interface: set_cache_compiled_shaders(const BamCache self, bool flag)

/**
  • 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.

*/

set_cache_compressed_textures()

C++ Interface: set_cache_compressed_textures(const BamCache self, bool flag)

/**
  • 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.

*/

set_cache_max_kbytes()

C++ Interface: set_cache_max_kbytes(const BamCache self, int max_kbytes)

/**
  • 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.

*/

set_cache_models()

C++ Interface: set_cache_models(const BamCache self, bool flag)

/**
  • Indicates whether model files (e.g. egg files and bam files) will be

  • stored in the cache, as bam files.

*/

set_cache_textures()

C++ Interface: set_cache_textures(const BamCache self, bool flag)

/**
  • Indicates whether texture files will be stored in the cache, as

  • uncompressed txo files.

*/

set_flush_time()

C++ Interface: set_flush_time(const BamCache self, int flush_time)

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

*/

set_read_only()

C++ Interface: set_read_only(const BamCache self, bool ro)

/**
  • 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.

*/

set_root()

C++ Interface: set_root(const BamCache self, 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.

*/

store()

C++ Interface: store(const BamCache self, 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.

*/