Panda3D
|
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by a BamReader. More...
#include "bamWriter.h"
Public Member Functions | |
BamWriter (DatagramSink *target=NULL) | |
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. More... | |
void | flush () |
Ensures that all data written thus far is manifested on the output stream. More... | |
BamEndian | get_file_endian () const |
Returns the endian preference indicated by the Bam file currently being written. More... | |
bool | get_file_stdfloat_double () const |
Returns true if the file will store all "standard" floats as 64-bit doubles, or false if they are 32-bit floats. More... | |
BamTextureMode | get_file_texture_mode () const |
Returns the BamTextureMode preference indicated by the Bam file currently being written. More... | |
const Filename & | get_filename () const |
If a BAM is a file, then the BamWriter should contain the name of the file. More... | |
DatagramSink * | get_target () |
Returns the current target of the BamWriter as set by set_target() or the constructor. More... | |
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. More... | |
bool | init () |
Initializes the BamWriter prior to writing any objects to its output stream. More... | |
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. More... | |
void | set_file_texture_mode (BamTextureMode file_texture_mode) |
Changes the BamTextureMode preference for the Bam file currently being written. More... | |
void | set_target (DatagramSink *target) |
Changes the destination of future datagrams written by the BamWriter. More... | |
void | write_cdata (Datagram &packet, const PipelineCyclerBase &cycler) |
Writes out the indicated CycleData object. More... | |
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(). More... | |
void | write_file_data (SubfileInfo &result, const Filename &filename) |
Writes a block of auxiliary file data from the indicated file (within the vfs). More... | |
void | write_file_data (SubfileInfo &result, const SubfileInfo &source) |
Writes a block of auxiliary file data from the indicated file (outside of the vfs). More... | |
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(). More... | |
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. More... | |
void | write_pointer (Datagram &packet, const TypedWritable *dest) |
The interface for writing a pointer to another object to a Bam file. More... | |
Friends | |
class | TypedWritable |
Additional Inherited Members | |
![]() | |
enum | BamEndian { BE_bigendian = 0, BE_littleendian = 1, BE_native = 1 } |
enum | BamObjectCode { BOC_push, BOC_pop, BOC_adjunct, BOC_remove, BOC_file_data } |
enum | BamTextureMode { BTM_unchanged, BTM_fullpath, BTM_relative, BTM_basename, BTM_rawdata } |
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 73 of file bamWriter.h.
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 237 of file bamWriter.cxx.
References TypedWritable::get_bam_modified(), and write_pointer().
Referenced by flush(), CFDoCullCommand::update_bam_nested(), and PandaNode::write_recorder().
void BamWriter::flush | ( | void | ) |
Ensures that all data written thus far is manifested on the output stream.
Definition at line 220 of file bamWriter.cxx.
References consider_update().
Referenced by has_object().
|
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 54 of file bamWriter.I.
References get_file_stdfloat_double().
Referenced by GeomVertexArrayData::finalize(), BamFile::get_file_endian(), and get_filename().
|
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 68 of file bamWriter.I.
References get_file_texture_mode().
Referenced by get_file_endian(), and BamFile::get_file_stdfloat_double().
|
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 81 of file bamWriter.I.
References set_file_texture_mode().
Referenced by Texture::finalize(), and get_file_stdfloat_double().
|
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 36 of file bamWriter.I.
References get_file_endian(), and DatagramSink::get_filename().
Referenced by Texture::finalize(), get_target(), and SpeedTreeNode::InstanceList::write_datagram().
|
inline |
Returns the current target of the BamWriter as set by set_target() or the constructor.
Definition at line 23 of file bamWriter.I.
References get_filename().
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 208 of file bamWriter.cxx.
References flush().
Referenced by write_object(), and PandaNode::write_recorder().
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 98 of file bamWriter.cxx.
References Datagram::add_bool(), Datagram::add_uint16(), Datagram::add_uint8(), and write_object().
Referenced by RecorderController::begin_record(), CFChannel::CFChannel(), TypedWritable::encode_to_bam_stream(), Texture::ensure_loader_type(), BamFile::get_writer(), BamCache::list_index(), set_target(), and BamCache::store().
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 437 of file bamWriter.cxx.
References write_handle().
Referenced by write_cdata().
|
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.
Definition at line 94 of file bamWriter.I.
Referenced by Texture::ensure_loader_type(), get_file_texture_mode(), and BamCache::store().
void BamWriter::set_target | ( | DatagramSink * | 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 76 of file bamWriter.cxx.
References init().
Referenced by TypedWritable::encode_to_bam_stream().
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 398 of file bamWriter.cxx.
References Thread::get_current_thread(), PipelineCyclerTrivialImpl::read(), PipelineCyclerTrivialImpl::release_read(), and CycleData::write_datagram().
Referenced by AnimInterface::get_num_frames(), Light::get_viz(), UserVertexSlider::write_datagram(), SwitchNode::write_datagram(), UserVertexTransform::write_datagram(), CallbackNode::write_datagram(), DirectionalLight::write_datagram(), PointLight::write_datagram(), ComputeNode::write_datagram(), TransformTable::write_datagram(), Spotlight::write_datagram(), SheetNode::write_datagram(), SliderTable::write_datagram(), PlaneNode::write_datagram(), TransformBlendTable::write_datagram(), LODNode::write_datagram(), GeomNode::write_datagram(), GeomVertexArrayData::write_datagram(), PartBundle::write_datagram(), RopeNode::write_datagram(), GeomPrimitive::write_datagram(), GeomVertexData::write_datagram(), Geom::write_datagram(), Lens::write_datagram(), PandaNode::write_datagram(), and write_file_data().
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 411 of file bamWriter.cxx.
References Thread::get_current_thread(), PipelineCyclerTrivialImpl::read(), register_pta(), PipelineCyclerTrivialImpl::release_read(), and CycleData::write_datagram().
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 329 of file bamWriter.cxx.
References Datagram::add_uint8().
Referenced by MovieVideo::write_datagram(), and write_pointer().
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 363 of file bamWriter.cxx.
References Datagram::add_uint8(), and write_cdata().
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 487 of file bamWriter.cxx.
References Datagram::add_string(), Datagram::add_uint16(), Datagram::add_uint32(), Datagram::add_uint8(), FactoryBase::find_registered_type(), TypedWritable::get_bam_modified(), BamReader::get_factory(), TypeHandle::get_index(), TypeHandle::get_name(), TypeHandle::get_num_parent_classes(), TypeHandle::get_parent_class(), TypedObject::is_of_type(), TypeHandle::none(), and Datagram::set_stdfloat_double().
Referenced by register_pta(), and RecorderTable::write_datagram().
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 152 of file bamWriter.cxx.
References Datagram::add_uint8(), and has_object().
Referenced by RecorderController::begin_record(), TypedWritable::encode_to_bam_stream(), Texture::ensure_loader_type(), init(), BamCache::list_index(), RecorderController::record_frame(), CFChannel::send_command(), BamCache::store(), and BamFile::write_object().
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 279 of file bamWriter.cxx.
References TypedWritable::get_bam_modified(), and write_file_data().
Referenced by consider_update(), GeomVertexData::CacheEntry::evict_callback(), Geom::CacheEntry::evict_callback(), GeomNode::finalize(), GeomPrimitive::finalize(), PiecewiseCurve::rebuild_curveseg(), AnimGroup::write(), CharacterVertexSlider::write_datagram(), ParamNodePath::write_datagram(), ParamTextureSampler::write_datagram(), AnimBundleNode::write_datagram(), SourceTextureImage::write_datagram(), RecorderFrame::write_datagram(), DataNodeTransmit::write_datagram(), FogAttrib::write_datagram(), MaterialAttrib::write_datagram(), BamCacheIndex::write_datagram(), JointVertexTransform::write_datagram(), CharacterJointEffect::write_datagram(), AnimChannelScalarDynamic::write_datagram(), PalettePage::write_datagram(), PartBundleNode::write_datagram(), OccluderEffect::write_datagram(), CFDoCullCommand::write_datagram(), PaletteGroups::write_datagram(), LensNode::write_datagram(), AnimChannelMatrixDynamic::write_datagram(), CharacterJoint::write_datagram(), GeomVertexColumn::write_datagram(), TextureProperties::write_datagram(), TransformTable::write_datagram(), CollisionNode::write_datagram(), MovingPartBase::write_datagram(), EggFile::write_datagram(), TexMatrixAttrib::write_datagram(), SliderTable::write_datagram(), ParamTextureImage::write_datagram(), TextureReference::write_datagram(), PaletteGroup::write_datagram(), PaletteImage::write_datagram(), TexturePlacement::write_datagram(), PartGroup::write_datagram(), TexGenAttrib::write_datagram(), TransformBlend::write_datagram(), MovieVideoCursor::write_datagram(), ClipPlaneAttrib::write_datagram(), LightAttrib::write_datagram(), Palettizer::write_datagram(), TextureImage::write_datagram(), TextureAttrib::write_datagram(), RenderEffects::write_datagram(), GeomVertexArrayData::write_datagram(), PartBundle::write_datagram(), TextureStage::write_datagram(), RenderState::write_datagram(), and PandaNode::write_recorder().