Panda3D

cullBinAttrib.cxx

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