Panda3D
Classes | Public Member Functions | Friends

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:
BamEnums

List of all members.

Classes

class  StoreState

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.
void flush ()
 Ensures that all data written thus far is manifested on the output stream.
BamEndian get_file_endian () const
 Returns the endian preference indicated by the Bam file currently being written.
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.
BamTextureMode get_file_texture_mode () const
 Returns the BamTextureMode preference indicated by the Bam file currently being written.
const Filenameget_filename () const
 If a BAM is a file, then the BamWriter should contain the name of the file.
DatagramSinkget_target ()
 Returns the current target of the BamWriter as set by set_target() or the constructor.
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_texture_mode (BamTextureMode file_texture_mode)
 Changes the BamTextureMode preference for the Bam file currently being written.
void set_target (DatagramSink *target)
 Changes the destination of future datagrams written by the BamWriter.
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 SubfileInfo &source)
 Writes a block of auxiliary file data from the indicated file (outside of the vfs).
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_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.

Friends

class TypedWritable

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 73 of file bamWriter.h.


Member Function Documentation

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 242 of file bamWriter.cxx.

References TypedWritable::get_bam_modified().

Referenced by CFDoCullCommand::update_bam_nested().

void BamWriter::flush ( void  )

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

Definition at line 225 of file bamWriter.cxx.

BamWriter::BamEndian BamWriter::get_file_endian ( ) const [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.

Referenced by BamFile::get_file_endian().

bool BamWriter::get_file_stdfloat_double ( ) const [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.

Referenced by BamFile::get_file_stdfloat_double().

BamWriter::BamTextureMode BamWriter::get_file_texture_mode ( ) const [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.

Referenced by Texture::do_write_datagram_header().

const Filename & BamWriter::get_filename ( ) const [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 DatagramSink::get_filename().

Referenced by Texture::do_write_datagram_header(), and SpeedTreeNode::InstanceList::write_datagram().

DatagramSink * BamWriter::get_target ( ) [inline]

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

Definition at line 23 of file bamWriter.I.

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 213 of file bamWriter.cxx.

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 103 of file bamWriter.cxx.

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

Referenced by RecorderController::begin_record(), CFChannel::CFChannel(), TypedWritable::encode_to_bam_stream(), 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 442 of file bamWriter.cxx.

void BamWriter::set_file_texture_mode ( BamTextureMode  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.

Definition at line 94 of file bamWriter.I.

Referenced by 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 81 of file bamWriter.cxx.

References init().

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

void BamWriter::write_cdata ( Datagram packet,
const PipelineCyclerBase cycler 
)
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 416 of file bamWriter.cxx.

References Thread::get_current_thread(), PipelineCyclerTrivialImpl::read(), 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 334 of file bamWriter.cxx.

References Datagram::add_uint8(), and DatagramSink::copy_datagram().

Referenced by MovieVideo::write_datagram().

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 368 of file bamWriter.cxx.

References Datagram::add_uint8(), and DatagramSink::copy_datagram().

void BamWriter::write_handle ( Datagram packet,
TypeHandle  type 
)
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 157 of file bamWriter.cxx.

References Datagram::add_uint8().

Referenced by RecorderController::begin_record(), TypedWritable::encode_to_bam_stream(), NodePath::encode_to_bam_stream(), 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 284 of file bamWriter.cxx.

References TypedWritable::get_bam_modified().

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


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations