Panda3D
|
00001 // Filename: showBoundsEffect.cxx 00002 // Created by: drose (25Mar02) 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 "showBoundsEffect.h" 00016 #include "bamReader.h" 00017 #include "bamWriter.h" 00018 #include "datagram.h" 00019 #include "datagramIterator.h" 00020 00021 TypeHandle ShowBoundsEffect::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: ShowBoundsEffect::make 00025 // Access: Published, Static 00026 // Description: Constructs a new ShowBoundsEffect object. 00027 //////////////////////////////////////////////////////////////////// 00028 CPT(RenderEffect) ShowBoundsEffect:: 00029 make(bool tight) { 00030 ShowBoundsEffect *effect = new ShowBoundsEffect; 00031 effect->_tight = tight; 00032 return return_new(effect); 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: ShowBoundsEffect::safe_to_combine 00037 // Access: Public, Virtual 00038 // Description: Returns true if this kind of effect can safely be 00039 // combined with sibling nodes that share the exact same 00040 // effect, or false if this is not a good idea. 00041 //////////////////////////////////////////////////////////////////// 00042 bool ShowBoundsEffect:: 00043 safe_to_combine() const { 00044 return false; 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: ShowBoundsEffect::compare_to_impl 00049 // Access: Protected, Virtual 00050 // Description: Intended to be overridden by derived ShowBoundsEffect 00051 // types to return a unique number indicating whether 00052 // this ShowBoundsEffect is equivalent to the other one. 00053 // 00054 // This should return 0 if the two ShowBoundsEffect objects 00055 // are equivalent, a number less than zero if this one 00056 // should be sorted before the other one, and a number 00057 // greater than zero otherwise. 00058 // 00059 // This will only be called with two ShowBoundsEffect 00060 // objects whose get_type() functions return the same. 00061 //////////////////////////////////////////////////////////////////// 00062 int ShowBoundsEffect:: 00063 compare_to_impl(const RenderEffect *other) const { 00064 const ShowBoundsEffect *ta; 00065 DCAST_INTO_R(ta, other, 0); 00066 00067 return (int)_tight - (int)ta->_tight; 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: ShowBoundsEffect::register_with_read_factory 00072 // Access: Public, Static 00073 // Description: Tells the BamReader how to create objects of type 00074 // ShowBoundsEffect. 00075 //////////////////////////////////////////////////////////////////// 00076 void ShowBoundsEffect:: 00077 register_with_read_factory() { 00078 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: ShowBoundsEffect::write_datagram 00083 // Access: Public, Virtual 00084 // Description: Writes the contents of this object to the datagram 00085 // for shipping out to a Bam file. 00086 //////////////////////////////////////////////////////////////////// 00087 void ShowBoundsEffect:: 00088 write_datagram(BamWriter *manager, Datagram &dg) { 00089 RenderEffect::write_datagram(manager, dg); 00090 dg.add_bool(_tight); 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: ShowBoundsEffect::make_from_bam 00095 // Access: Protected, Static 00096 // Description: This function is called by the BamReader's factory 00097 // when a new object of type ShowBoundsEffect is encountered 00098 // in the Bam file. It should create the ShowBoundsEffect 00099 // and extract its information from the file. 00100 //////////////////////////////////////////////////////////////////// 00101 TypedWritable *ShowBoundsEffect:: 00102 make_from_bam(const FactoryParams ¶ms) { 00103 ShowBoundsEffect *effect = new ShowBoundsEffect; 00104 DatagramIterator scan; 00105 BamReader *manager; 00106 00107 parse_params(params, scan, manager); 00108 effect->fillin(scan, manager); 00109 00110 return effect; 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: ShowBoundsEffect::fillin 00115 // Access: Protected 00116 // Description: This internal function is called by make_from_bam to 00117 // read in all of the relevant data from the BamFile for 00118 // the new ShowBoundsEffect. 00119 //////////////////////////////////////////////////////////////////// 00120 void ShowBoundsEffect:: 00121 fillin(DatagramIterator &scan, BamReader *manager) { 00122 RenderEffect::fillin(scan, manager); 00123 _tight = scan.get_bool(); 00124 }