Panda3D

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
BamWriter Class Reference

This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by a BamReader. More...

`#include "bamWriter.h"`

Inheritance diagram for BamWriter:

## Public Member Functions
| BamWriter (DatagramSink *target=nullptr)
void | consider_update (const TypedWritable *obj)
| Should be called from TypedWritable::update_bam_nested() to recursively check the entire hiererachy of writable objects for needed updates.
void | flush ()
| Ensures that all data written thus far is manifested on the output stream.
BamEndian | get_file_endian () const
int | get_file_major_ver () const
| Returns the major version number of the Bam file currently being written.
int | get_file_minor_ver () const
| Returns the minor version number of the Bam file currently being written.
bool | get_file_stdfloat_double () const
BamTextureMode | get_file_texture_mode () const
const Filename & | get_filename () const
TypedWritable * | get_root_node () const
DatagramSink * | get_target ()
bool | has_object (const TypedWritable *obj) const
| Returns true if the object has previously been written (or at least requested to be written) to the bam file, or false if we've never heard of it before.
bool | init ()
| Initializes the BamWriter prior to writing any objects to its output stream.
bool | register_pta (Datagram &packet, const void *ptr)
| Prepares to write a PointerToArray to the Bam file, unifying references to the same pointer across the Bam file.
void | set_file_minor_ver (int minor_ver)
| Changes the minor .bam version to write.
void | set_file_texture_mode (BamTextureMode file_texture_mode)
void | set_root_node (TypedWritable *root_node)
void | set_target (DatagramSink *target)
void | write_cdata (Datagram &packet, const PipelineCyclerBase &cycler)
| Writes out the indicated CycleData object.
void | write_cdata (Datagram &packet, const PipelineCyclerBase &cycler, void *extra_data)
| This version of write_cdata allows passing an additional parameter to cdata->write_datagram().
void | write_file_data (SubfileInfo &result, const Filename &filename)
| Writes a block of auxiliary file data from the indicated file (within the vfs).
void | write_file_data (SubfileInfo &result, const SubfileInfo &source)
| Writes a block of auxiliary file data from the indicated file (outside of the vfs).
void | write_handle (Datagram &packet, TypeHandle type)
| Writes a TypeHandle to the file in such a way that the BamReader can read the same TypeHandle later via read_handle().
bool | write_object (const TypedWritable *obj)
| Writes a single object to the Bam file, so that the BamReader::read_object() can later correctly restore the object and all its pointers.
void | write_pointer (Datagram &packet, const TypedWritable *dest)
| The interface for writing a pointer to another object to a Bam file.

## Static Public Member Functions
static std::string | get_obsolete_type_name (TypeHandle type, int major, int minor)
| Returns the name that the given type had in an older .bam version.
static void | record_obsolete_type_name (TypeHandle type, std::string name, int before_major, int before_minor)
| Registers the given type as having an older name in .bam files *before* the indicated version.

## Public Attributes
| get_file_endian
| Returns the endian preference indicated by the Bam file currently being written.
| get_file_stdfloat_double
| Returns true if the file will store all "standard" floats as 64-bit doubles, or false if they are 32-bit floats.
| get_file_texture_mode
| Returns the BamTextureMode preference indicated by the Bam file currently being written.
| get_file_version
| get_filename
| If a BAM is a file, then the BamWriter should contain the name of the file.
| get_root_node
| Returns the root node of the part of the scene graph we are currently writing out.
| get_target
| Returns the current target of the BamWriter as set by set_target() or the constructor.
| set_file_texture_mode
| Changes the BamTextureMode preference for the Bam file currently being written.
| set_root_node
| Sets the root node of the part of the scene graph we are currently writing out.
| set_target
| Changes the destination of future datagrams written by the BamWriter.

## Friends
class | TypedWritable

## Additional Inherited Members
Public Types inherited from BamEnums
enum | BamEndian { BE_bigendian = 0 , BE_littleendian = 1 , BE_native = 1 }
| This defines an enumerated type used to represent the endianness of certain numeric values stored in a Bam file. More...
enum | BamObjectCode { BOC_push , BOC_pop , BOC_adjunct , BOC_remove , BOC_file_data }
| This is the code written along with each object. More...
enum | BamTextureMode { BTM_unchanged , BTM_fullpath , BTM_relative , BTM_basename , BTM_rawdata }

## Detailed Description

This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by a BamReader.

A Bam file can be thought of as a linear collection of objects. Each object is an instance of a class that inherits, directly or indirectly, from TypedWritable. The objects may include pointers to other objects; the BamWriter automatically manages these (with help from code within each class) and writes all referenced objects to the file in such a way that the pointers may be correctly restored later.

This is the abstract interface and does not specifically deal with disk files, but rather with a DatagramSink of some kind, which simply accepts a linear stream of Datagrams. It is probably written to a disk file, but it might conceivably be streamed directly to a network or some such nonsense.

Bam files are most often used to store scene graphs or subgraphs, and by convention they are given filenames ending in the extension ".bam" when they are used for this purpose. However, a Bam file may store any arbitrary list of TypedWritable objects; in this more general usage, they are given filenames ending in ".boo" to differentiate them from the more common scene graph files.

See also BamFile, which defines a higher-level interface to read and write Bam files on disk.

Definition at line 63 of file bamWriter.h.

## Constructor & Destructor Documentation

## ◆ BamWriter()

BamWriter::BamWriter | ( | DatagramSink * | target = nullptr | ) |
| explicit

Definition at line 48 of file bamWriter.cxx.

## ◆ ~BamWriter()

BamWriter::~BamWriter | ( |  | ) |

Definition at line 108 of file bamWriter.cxx.

## Member Function Documentation

## ◆ consider_update()

void BamWriter::consider_update | ( | const TypedWritable * | object | ) |

Should be called from TypedWritable::update_bam_nested() to recursively check the entire hiererachy of writable objects for needed updates.

This tests the indicated TypedWritable object and writes it to the bam stream if it has recently been modified, then recurses through update_bam_nested.

Definition at line 278 of file bamWriter.cxx.

References TypedWritable::get_bam_modified().

## ◆ flush()

void BamWriter::flush | ( |  | ) |

Ensures that all data written thus far is manifested on the output stream.

Definition at line 266 of file bamWriter.cxx.

## ◆ get_file_major_ver()

int BamWriter::get_file_major_ver | ( |  | ) | const
| inline

Returns the major version number of the Bam file currently being written.

Definition at line 40 of file bamWriter.I.

## ◆ get_file_minor_ver()

int BamWriter::get_file_minor_ver | ( |  | ) | const
| inline

Returns the minor version number of the Bam file currently being written.

Definition at line 58 of file bamWriter.I.

Referenced by BillboardEffect::write_datagram(), Camera::write_datagram(), ClipPlaneAttrib::write_datagram(), ColorBlendAttrib::write_datagram(), CompassEffect::write_datagram(), DepthOffsetAttrib::write_datagram(), DirectionalLight::write_datagram(), GeomVertexArrayFormat::write_datagram(), GeomVertexColumn::write_datagram(), LensNode::write_datagram(), LightAttrib::write_datagram(), Material::write_datagram(), MatrixLens::write_datagram(), ModelRoot::write_datagram(), OccluderEffect::write_datagram(), ParamNodePath::write_datagram(), PointLight::write_datagram(), ScissorAttrib::write_datagram(), Spotlight::write_datagram(), StencilAttrib::write_datagram(), TexMatrixAttrib::write_datagram(), TextureAttrib::write_datagram(), TextureStage::write_datagram(), and UvScrollNode::write_datagram().

## ◆ get_obsolete_type_name()

std::string BamWriter::get_obsolete_type_name | ( | TypeHandle | type,
|  | int | major,
|  | int | minor )
| static

Returns the name that the given type had in an older .bam version.

Definition at line 550 of file bamWriter.cxx.

References TypeRegistry::get_name(), and TypeRegistry::ptr().

Referenced by write_handle().

## ◆ has_object()

bool BamWriter::has_object | ( | const TypedWritable * | obj | ) | const

Returns true if the object has previously been written (or at least requested to be written) to the bam file, or false if we've never heard of it before.

Definition at line 257 of file bamWriter.cxx.

## ◆ init()

bool BamWriter::init | ( |  | ) |

Initializes the BamWriter prior to writing any objects to its output stream.

This includes writing out the Bam header.

This returns true if the BamWriter successfully initialized, false otherwise.

Definition at line 146 of file bamWriter.cxx.

References Datagram::add_bool(), Datagram::add_uint16(), and Datagram::add_uint8().

Referenced by TypedWritable::encode_to_bam_stream(), and BamCache::store().

## ◆ record_obsolete_type_name()

void BamWriter::record_obsolete_type_name | ( | TypeHandle | type,
|  | std::string | name,
|  | int | before_major,
|  | int | before_minor )
| static

Registers the given type as having an older name in .bam files *before* the indicated version.

You can call this multiple times for the same type in order to establish a history of renames for this type.

Definition at line 573 of file bamWriter.cxx.

References TypeRegistry::ptr(), and TypeRegistry::record_alternate_name().

Referenced by init_libcollide().

## ◆ register_pta()

bool BamWriter::register_pta | ( | Datagram & | packet,
|  | const void * | ptr )

Prepares to write a PointerToArray to the Bam file, unifying references to the same pointer across the Bam file.

The writing object should call this prior to writing out a PointerToArray. It will return true if the same pointer has been written previously, in which case the writing object need do nothing further; or it will return false if this particular pointer has not yet been written, in which case the writing object must then write out the contents of the array.

Also see the WRITE_PTA() macro, which consolidates the work that must be done to write a PTA.

Definition at line 456 of file bamWriter.cxx.

## ◆ set_file_minor_ver()

void BamWriter::set_file_minor_ver | ( | int | minor_ver | ) |
| inline

Changes the minor .bam version to write.

This should be called before init(). Each Panda version has only a fairly narrow range of versions it is able to write; consult the .bam documentation for more information.

Definition at line 50 of file bamWriter.I.

## ◆ write_cdata() [1/2]

void BamWriter::write_cdata | ( | Datagram & | packet,
|  | const PipelineCyclerBase & | cycler )

Writes out the indicated CycleData object.

This should be used by classes that store some or all of their data within a CycleData subclass, in support of pipelining. This will call the virtual CycleData::write_datagram() method to do the actual writing.

Definition at line 424 of file bamWriter.cxx.

References Thread::get_current_thread, PipelineCyclerTrivialImpl::read(), PipelineCyclerTrivialImpl::release_read(), and CycleData::write_datagram().

Referenced by CallbackNode::write_datagram(), ComputeNode::write_datagram(), DirectionalLight::write_datagram(), Geom::write_datagram(), GeomNode::write_datagram(), GeomPrimitive::write_datagram(), GeomVertexArrayData::write_datagram(), GeomVertexData::write_datagram(), Lens::write_datagram(), LODNode::write_datagram(), PandaNode::write_datagram(), PartBundle::write_datagram(), PlaneNode::write_datagram(), PointLight::write_datagram(), RectangleLight::write_datagram(), RopeNode::write_datagram(), SheetNode::write_datagram(), SliderTable::write_datagram(), SphereLight::write_datagram(), Spotlight::write_datagram(), SwitchNode::write_datagram(), TransformBlendTable::write_datagram(), TransformTable::write_datagram(), UserVertexSlider::write_datagram(), and UserVertexTransform::write_datagram().

## ◆ write_cdata() [2/2]

void BamWriter::write_cdata | ( | Datagram & | packet,
|  | const PipelineCyclerBase & | cycler,
|  | void * | extra_data )

This version of write_cdata allows passing an additional parameter to cdata->write_datagram().

Definition at line 435 of file bamWriter.cxx.

References Thread::get_current_thread, PipelineCyclerTrivialImpl::read(), PipelineCyclerTrivialImpl::release_read(), and CycleData::write_datagram().

## ◆ write_file_data() [1/2]

void BamWriter::write_file_data | ( | SubfileInfo & | result,
|  | const Filename & | filename )

Writes a block of auxiliary file data from the indicated file (within the vfs).

This can be a block of arbitrary size, and it is assumed it may be quite large. This must be balanced by a matching call to read_file_data() on restore.

Definition at line 362 of file bamWriter.cxx.

References Datagram::add_uint8().

Referenced by MovieVideo::write_datagram().

## ◆ write_file_data() [2/2]

void BamWriter::write_file_data | ( | SubfileInfo & | result,
|  | const SubfileInfo & | source )

Writes a block of auxiliary file data from the indicated file (outside of the vfs).

This can be a block of arbitrary size, and it is assumed it may be quite large. This must be balanced by a matching call to read_file_data() on restore.

Definition at line 393 of file bamWriter.cxx.

References Datagram::add_uint8().

## ◆ write_handle()

void BamWriter::write_handle | ( | Datagram & | packet,
|  | TypeHandle | type )

Writes a TypeHandle to the file in such a way that the BamReader can read the same TypeHandle later via read_handle().

Definition at line 503 of file bamWriter.cxx.

References Datagram::add_string(), Datagram::add_uint16(), Datagram::add_uint8(), TypeHandle::get_index, TypeHandle::get_name, TypeHandle::get_num_parent_classes, get_obsolete_type_name(), TypeHandle::get_parent_class, and write_handle().

Referenced by ModelRoot::write_datagram(), RecorderTable::write_datagram(), and write_handle().

## ◆ write_object()

bool BamWriter::write_object | ( | const TypedWritable * | object | ) |

Writes a single object to the Bam file, so that the BamReader::read_object() can later correctly restore the object and all its pointers.

This implicitly also writes any additional objects this object references (if they haven't already been written), so that pointers may be fully resolved.

This may be called repeatedly to write a sequence of objects to the Bam file, but typically (especially for scene graph files, indicated with the .bam extension), only one object is written directly from the Bam file: the root of the scene graph. The remaining objects will all be written recursively by the first object.

Returns true if the object is successfully written, false otherwise.

Definition at line 203 of file bamWriter.cxx.

References Datagram::add_uint8().

Referenced by NodePath::encode_to_bam_stream(), TypedWritable::encode_to_bam_stream(), and BamCache::store().

## ◆ write_pointer()

void BamWriter::write_pointer | ( | Datagram & | packet,
|  | const TypedWritable * | object )

The interface for writing a pointer to another object to a Bam file.

This is intended to be called by the various objects that write themselves to the Bam file, within the write_datagram() method.

This writes the pointer out in such a way that the BamReader will be able to restore the pointer later. If the pointer is to an object that has not yet itself been written to the Bam file, that object will automatically be written.

Definition at line 316 of file bamWriter.cxx.

References TypedWritable::get_bam_modified().

Referenced by AnimBundleNode::write_datagram(), AnimChannelMatrixDynamic::write_datagram(), AnimChannelScalarDynamic::write_datagram(), BamCacheIndex::write_datagram(), BulletBodyNode::write_datagram(), BulletMinkowskiSumShape::write_datagram(), BulletTriangleMeshShape::write_datagram(), Camera::write_datagram(), CharacterJoint::write_datagram(), CharacterJointEffect::write_datagram(), CharacterVertexSlider::write_datagram(), ClipPlaneAttrib::write_datagram(), CollisionNode::write_datagram(), DataNodeTransmit::write_datagram(), EggFile::write_datagram(), FogAttrib::write_datagram(), GeomVertexArrayData::write_datagram(), GeomVertexColumn::write_datagram(), GeomVertexFormat::write_datagram(), JointVertexTransform::write_datagram(), LensNode::write_datagram(), LightAttrib::write_datagram(), MaterialAttrib::write_datagram(), MovieVideoCursor::write_datagram(), MovingPartBase::write_datagram(), NodePath::write_datagram(), OccluderEffect::write_datagram(), PaletteGroup::write_datagram(), PaletteGroups::write_datagram(), PaletteImage::write_datagram(), PalettePage::write_datagram(), Palettizer::write_datagram(), ParamNodePath::write_datagram(), ParamTextureImage::write_datagram(), ParamTextureSampler::write_datagram(), PartBundle::write_datagram(), PartBundleNode::write_datagram(), PartGroup::write_datagram(), RecorderFrame::write_datagram(), RenderEffects::write_datagram(), RenderState::write_datagram(), SliderTable::write_datagram(), SourceTextureImage::write_datagram(), TexGenAttrib::write_datagram(), TexMatrixAttrib::write_datagram(), TextureAttrib::write_datagram(), TextureImage::write_datagram(), TexturePlacement::write_datagram(), TextureProperties::write_datagram(), TextureReference::write_datagram(), TextureStage::write_datagram(), TransformBlend::write_datagram(), and TransformTable::write_datagram().

## Friends And Related Symbol Documentation

## ◆ TypedWritable

friend class TypedWritable
| friend

Definition at line 195 of file bamWriter.h.

## Member Data Documentation

## ◆ get_file_endian

BamWriter::BamEndian BamWriter::get_file_endian
| inline

Returns the endian preference indicated by the Bam file currently being written.

This does not imply that every number is stored using the indicated convention, but individual objects may choose to respect this flag when recording data.

Definition at line 97 of file bamWriter.h.

## ◆ get_file_stdfloat_double

bool BamWriter::get_file_stdfloat_double
| inline

Returns true if the file will store all "standard" floats as 64-bit doubles, or false if they are 32-bit floats.

This isn't runtime settable; it's based on the compilation flags of the version of Panda that generated this file.

Definition at line 98 of file bamWriter.h.

## ◆ get_file_texture_mode

BamWriter::BamTextureMode BamWriter::get_file_texture_mode
| inline

Returns the BamTextureMode preference indicated by the Bam file currently being written.

Texture objects written to this Bam file will be encoded according to the specified mode.

Definition at line 99 of file bamWriter.h.

## ◆ get_file_version

BamWriter::get_file_version

Definition at line 96 of file bamWriter.h.

## ◆ get_filename

const Filename & BamWriter::get_filename
| inline

If a BAM is a file, then the BamWriter should contain the name of the file.

This enables the writer to convert pathnames in the BAM to relative to the directory containing the BAM.

Definition at line 95 of file bamWriter.h.

Referenced by SpeedTreeNode::InstanceList::write_datagram().

## ◆ get_root_node

TypedWritable * BamWriter::get_root_node
| inline

Returns the root node of the part of the scene graph we are currently writing out.

This is used for determining what to make NodePaths relative to.

Definition at line 100 of file bamWriter.h.

Referenced by NodePath::write_datagram().

## ◆ get_target

DatagramSink * BamWriter::get_target
| inline

Returns the current target of the BamWriter as set by set_target() or the constructor.

Definition at line 94 of file bamWriter.h.

## ◆ set_file_texture_mode

void BamWriter::set_file_texture_mode
| inline

Changes the BamTextureMode preference for the Bam file currently being written.

Texture objects written to this Bam file will be encoded according to the specified mode.

This should be called after the call to init(), or it will be overwritten with the default mode in the config file.

Definition at line 99 of file bamWriter.h.

Referenced by BamCache::store().

## ◆ set_root_node

void BamWriter::set_root_node
| inline

Sets the root node of the part of the scene graph we are currently writing out.

NodePaths written to this bam file will be relative to this node.

Definition at line 100 of file bamWriter.h.

Referenced by NodePath::encode_to_bam_stream(), and BamCache::store().

## ◆ set_target

void BamWriter::set_target

Changes the destination of future datagrams written by the BamWriter.

This also implicitly calls init() if it has not already been called.

Definition at line 94 of file bamWriter.h.

Referenced by NodePath::encode_to_bam_stream(), and TypedWritable::encode_to_bam_stream().

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

- panda/src/putil/bamWriter.h
- panda/src/putil/bamWriter.cxx
- panda/src/putil/bamWriter.I