Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgraph/switchNode.cxx

Go to the documentation of this file.
00001 // Filename: switchNode.cxx
00002 // Created by:  drose (31Jul02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "pandabase.h"
00020 #include "switchNode.h"
00021 #include "cullTraverser.h"
00022 
00023 TypeHandle SwitchNode::_type_handle;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: SwitchNode::CData::make_copy
00027 //       Access: Public, Virtual
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 CycleData *SwitchNode::CData::
00031 make_copy() const {
00032   return new CData(*this);
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: SwitchNode::safe_to_combine
00037 //       Access: Public, Virtual
00038 //  Description: Returns true if it is generally safe to combine this
00039 //               particular kind of PandaNode with other kinds of
00040 //               PandaNodes, adding children or whatever.  For
00041 //               instance, an LODNode should not be combined with any
00042 //               other PandaNode, because its set of children is
00043 //               meaningful.
00044 ////////////////////////////////////////////////////////////////////
00045 bool SwitchNode::
00046 safe_to_combine() const {
00047   return false;
00048 }
00049 
00050 ////////////////////////////////////////////////////////////////////
00051 //     Function: SwitchNode::CData::write_datagram
00052 //       Access: Public, Virtual
00053 //  Description: Writes the contents of this object to the datagram
00054 //               for shipping out to a Bam file.
00055 ////////////////////////////////////////////////////////////////////
00056 void SwitchNode::CData::
00057 write_datagram(BamWriter *manager, Datagram &dg) const {
00058   dg.add_int32(_visible_child);
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: SwitchNode::CData::fillin
00063 //       Access: Public, Virtual
00064 //  Description: This internal function is called by make_from_bam to
00065 //               read in all of the relevant data from the BamFile for
00066 //               the new SwitchNode.
00067 ////////////////////////////////////////////////////////////////////
00068 void SwitchNode::CData::
00069 fillin(DatagramIterator &scan, BamReader *manager) {
00070   _visible_child = scan.get_int32();
00071 }
00072 
00073 ////////////////////////////////////////////////////////////////////
00074 //     Function: SwitchNode::Copy Constructor
00075 //       Access: Protected
00076 //  Description:
00077 ////////////////////////////////////////////////////////////////////
00078 SwitchNode::
00079 SwitchNode(const SwitchNode &copy) :
00080   SelectiveChildNode(copy),
00081   _cycler(copy._cycler)
00082 {
00083 }
00084 
00085 ////////////////////////////////////////////////////////////////////
00086 //     Function: SwitchNode::make_copy
00087 //       Access: Public, Virtual
00088 //  Description: Returns a newly-allocated Node that is a shallow copy
00089 //               of this one.  It will be a different Node pointer,
00090 //               but its internal data may or may not be shared with
00091 //               that of the original Node.
00092 ////////////////////////////////////////////////////////////////////
00093 PandaNode *SwitchNode::
00094 make_copy() const {
00095   return new SwitchNode(*this);
00096 }
00097 
00098 ////////////////////////////////////////////////////////////////////
00099 //     Function: SwitchNode::has_cull_callback
00100 //       Access: Public, Virtual
00101 //  Description: Should be overridden by derived classes to return
00102 //               true if cull_callback() has been defined.  Otherwise,
00103 //               returns false to indicate cull_callback() does not
00104 //               need to be called for this node during the cull
00105 //               traversal.
00106 ////////////////////////////////////////////////////////////////////
00107 bool SwitchNode::
00108 has_cull_callback() const {
00109   return true;
00110 }
00111 
00112 ////////////////////////////////////////////////////////////////////
00113 //     Function: SwitchNode::cull_callback
00114 //       Access: Public, Virtual
00115 //  Description: If has_cull_callback() returns true, this function
00116 //               will be called during the cull traversal to perform
00117 //               any additional operations that should be performed at
00118 //               cull time.  This may include additional manipulation
00119 //               of render state or additional visible/invisible
00120 //               decisions, or any other arbitrary operation.
00121 //
00122 //               By the time this function is called, the node has
00123 //               already passed the bounding-volume test for the
00124 //               viewing frustum, and the node's transform and state
00125 //               have already been applied to the indicated
00126 //               CullTraverserData object.
00127 //
00128 //               The return value is true if this node should be
00129 //               visible, or false if it should be culled.
00130 ////////////////////////////////////////////////////////////////////
00131 bool SwitchNode::
00132 cull_callback(CullTraverser *, CullTraverserData &) {
00133   select_child(get_visible_child());
00134   return true;
00135 }
00136 
00137 ////////////////////////////////////////////////////////////////////
00138 //     Function: SwitchNode::has_single_child_visibility
00139 //       Access: Public, Virtual
00140 //  Description: Should be overridden by derived classes to return
00141 //               true if this kind of node has the special property
00142 //               that just one of its children is visible at any given
00143 //               time, and furthermore that the particular visible
00144 //               child can be determined without reference to any
00145 //               external information (such as a camera).  At present,
00146 //               only SequenceNodes and SwitchNodes fall into this
00147 //               category.
00148 //
00149 //               If this function returns true, get_visible_child()
00150 //               can be called to return the index of the
00151 //               currently-visible child.
00152 ////////////////////////////////////////////////////////////////////
00153 bool SwitchNode::
00154 has_single_child_visibility() const {
00155   return true;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: SwitchNode::get_visible_child
00160 //       Access: Published, Virtual
00161 //  Description: Returns the index of the child that should be visible.
00162 ////////////////////////////////////////////////////////////////////
00163 int SwitchNode::
00164 get_visible_child() const {
00165   CDReader cdata(_cycler);
00166   return cdata->_visible_child;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: SwitchNode::register_with_read_factory
00171 //       Access: Public, Static
00172 //  Description: Tells the BamReader how to create objects of type
00173 //               SwitchNode.
00174 ////////////////////////////////////////////////////////////////////
00175 void SwitchNode::
00176 register_with_read_factory() {
00177   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: SwitchNode::write_datagram
00182 //       Access: Public, Virtual
00183 //  Description: Writes the contents of this object to the datagram
00184 //               for shipping out to a Bam file.
00185 ////////////////////////////////////////////////////////////////////
00186 void SwitchNode::
00187 write_datagram(BamWriter *manager, Datagram &dg) {
00188   SelectiveChildNode::write_datagram(manager, dg);
00189   manager->write_cdata(dg, _cycler);
00190 }
00191 
00192 ////////////////////////////////////////////////////////////////////
00193 //     Function: SwitchNode::make_from_bam
00194 //       Access: Protected, Static
00195 //  Description: This function is called by the BamReader's factory
00196 //               when a new object of type SwitchNode is encountered
00197 //               in the Bam file.  It should create the SwitchNode
00198 //               and extract its information from the file.
00199 ////////////////////////////////////////////////////////////////////
00200 TypedWritable *SwitchNode::
00201 make_from_bam(const FactoryParams &params) {
00202   SwitchNode *node = new SwitchNode("");
00203   DatagramIterator scan;
00204   BamReader *manager;
00205 
00206   parse_params(params, scan, manager);
00207   node->fillin(scan, manager);
00208 
00209   return node;
00210 }
00211 
00212 ////////////////////////////////////////////////////////////////////
00213 //     Function: SwitchNode::fillin
00214 //       Access: Protected
00215 //  Description: This internal function is called by make_from_bam to
00216 //               read in all of the relevant data from the BamFile for
00217 //               the new SwitchNode.
00218 ////////////////////////////////////////////////////////////////////
00219 void SwitchNode::
00220 fillin(DatagramIterator &scan, BamReader *manager) {
00221   SelectiveChildNode::fillin(scan, manager);
00222   manager->read_cdata(scan, _cycler);
00223 }

Generated on Fri May 2 00:42:25 2003 for Panda by doxygen1.3