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

panda/src/pgraph/cullBinAttrib.cxx

Go to the documentation of this file.
00001 // Filename: cullBinAttrib.cxx
00002 // Created by:  drose (01Mar02)
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 "cullBinAttrib.h"
00020 #include "bamReader.h"
00021 #include "bamWriter.h"
00022 #include "datagram.h"
00023 #include "datagramIterator.h"
00024 
00025 TypeHandle CullBinAttrib::_type_handle;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: CullBinAttrib::make
00029 //       Access: Published, Static
00030 //  Description: Constructs a new CullBinAttrib assigning geometry
00031 //               into the named bin.  If the bin name is the empty
00032 //               string, the default bin is used.
00033 //
00034 //               The draw_order specifies further ordering information
00035 //               which is relevant only to certain kinds of bins (in
00036 //               particular CullBinFixed type bins).
00037 ////////////////////////////////////////////////////////////////////
00038 CPT(RenderAttrib) CullBinAttrib::
00039 make(const string &bin_name, int draw_order) {
00040   CullBinAttrib *attrib = new CullBinAttrib;
00041   attrib->_bin_name = bin_name;
00042   attrib->_draw_order = draw_order;
00043   return return_new(attrib);
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: CullBinAttrib::output
00048 //       Access: Public, Virtual
00049 //  Description: 
00050 ////////////////////////////////////////////////////////////////////
00051 void CullBinAttrib::
00052 output(ostream &out) const {
00053   out << get_type() << ":";
00054   if (_bin_name.empty()) {
00055     out << "(default)";
00056   } else {
00057     out << _bin_name;
00058   }
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: CullBinAttrib::compare_to_impl
00063 //       Access: Protected, Virtual
00064 //  Description: Intended to be overridden by derived CullBinAttrib
00065 //               types to return a unique number indicating whether
00066 //               this CullBinAttrib is equivalent to the other one.
00067 //
00068 //               This should return 0 if the two CullBinAttrib objects
00069 //               are equivalent, a number less than zero if this one
00070 //               should be sorted before the other one, and a number
00071 //               greater than zero otherwise.
00072 //
00073 //               This will only be called with two CullBinAttrib
00074 //               objects whose get_type() functions return the same.
00075 ////////////////////////////////////////////////////////////////////
00076 int CullBinAttrib::
00077 compare_to_impl(const RenderAttrib *other) const {
00078   const CullBinAttrib *ta;
00079   DCAST_INTO_R(ta, other, 0);
00080   if (_draw_order != ta->_draw_order) {
00081     return _draw_order - ta->_draw_order;
00082   }
00083   return strcmp(_bin_name.c_str(), ta->_bin_name.c_str());
00084 }
00085 
00086 ////////////////////////////////////////////////////////////////////
00087 //     Function: CullBinAttrib::make_default_impl
00088 //       Access: Protected, Virtual
00089 //  Description: Intended to be overridden by derived CullBinAttrib
00090 //               types to specify what the default property for a
00091 //               CullBinAttrib of this type should be.
00092 //
00093 //               This should return a newly-allocated CullBinAttrib of
00094 //               the same type that corresponds to whatever the
00095 //               standard default for this kind of CullBinAttrib is.
00096 ////////////////////////////////////////////////////////////////////
00097 RenderAttrib *CullBinAttrib::
00098 make_default_impl() const {
00099   return new CullBinAttrib;
00100 }
00101 
00102 ////////////////////////////////////////////////////////////////////
00103 //     Function: CullBinAttrib::register_with_read_factory
00104 //       Access: Public, Static
00105 //  Description: Tells the BamReader how to create objects of type
00106 //               CullBinAttrib.
00107 ////////////////////////////////////////////////////////////////////
00108 void CullBinAttrib::
00109 register_with_read_factory() {
00110   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00111 }
00112 
00113 ////////////////////////////////////////////////////////////////////
00114 //     Function: CullBinAttrib::write_datagram
00115 //       Access: Public, Virtual
00116 //  Description: Writes the contents of this object to the datagram
00117 //               for shipping out to a Bam file.
00118 ////////////////////////////////////////////////////////////////////
00119 void CullBinAttrib::
00120 write_datagram(BamWriter *manager, Datagram &dg) {
00121   RenderAttrib::write_datagram(manager, dg);
00122 
00123   dg.add_string(_bin_name);
00124   dg.add_int32(_draw_order);
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: CullBinAttrib::make_from_bam
00129 //       Access: Protected, Static
00130 //  Description: This function is called by the BamReader's factory
00131 //               when a new object of type CullBinAttrib is encountered
00132 //               in the Bam file.  It should create the CullBinAttrib
00133 //               and extract its information from the file.
00134 ////////////////////////////////////////////////////////////////////
00135 TypedWritable *CullBinAttrib::
00136 make_from_bam(const FactoryParams &params) {
00137   CullBinAttrib *attrib = new CullBinAttrib;
00138   DatagramIterator scan;
00139   BamReader *manager;
00140 
00141   parse_params(params, scan, manager);
00142   attrib->fillin(scan, manager);
00143 
00144   return attrib;
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: CullBinAttrib::fillin
00149 //       Access: Protected
00150 //  Description: This internal function is called by make_from_bam to
00151 //               read in all of the relevant data from the BamFile for
00152 //               the new CullBinAttrib.
00153 ////////////////////////////////////////////////////////////////////
00154 void CullBinAttrib::
00155 fillin(DatagramIterator &scan, BamReader *manager) {
00156   RenderAttrib::fillin(scan, manager);
00157 
00158   _bin_name = scan.get_string();
00159   _draw_order = scan.get_int32();
00160 }

Generated on Fri May 2 00:41:23 2003 for Panda by doxygen1.3