Panda3D
 All Classes Functions Variables Enumerations
showBoundsEffect.cxx
1 // Filename: showBoundsEffect.cxx
2 // Created by: drose (25Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "showBoundsEffect.h"
16 #include "bamReader.h"
17 #include "bamWriter.h"
18 #include "datagram.h"
19 #include "datagramIterator.h"
20 
21 TypeHandle ShowBoundsEffect::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: ShowBoundsEffect::make
25 // Access: Published, Static
26 // Description: Constructs a new ShowBoundsEffect object.
27 ////////////////////////////////////////////////////////////////////
29 make(bool tight) {
30  ShowBoundsEffect *effect = new ShowBoundsEffect;
31  effect->_tight = tight;
32  return return_new(effect);
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: ShowBoundsEffect::safe_to_combine
37 // Access: Public, Virtual
38 // Description: Returns true if this kind of effect can safely be
39 // combined with sibling nodes that share the exact same
40 // effect, or false if this is not a good idea.
41 ////////////////////////////////////////////////////////////////////
42 bool ShowBoundsEffect::
43 safe_to_combine() const {
44  return false;
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: ShowBoundsEffect::compare_to_impl
49 // Access: Protected, Virtual
50 // Description: Intended to be overridden by derived ShowBoundsEffect
51 // types to return a unique number indicating whether
52 // this ShowBoundsEffect is equivalent to the other one.
53 //
54 // This should return 0 if the two ShowBoundsEffect objects
55 // are equivalent, a number less than zero if this one
56 // should be sorted before the other one, and a number
57 // greater than zero otherwise.
58 //
59 // This will only be called with two ShowBoundsEffect
60 // objects whose get_type() functions return the same.
61 ////////////////////////////////////////////////////////////////////
62 int ShowBoundsEffect::
63 compare_to_impl(const RenderEffect *other) const {
64  const ShowBoundsEffect *ta;
65  DCAST_INTO_R(ta, other, 0);
66 
67  return (int)_tight - (int)ta->_tight;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: ShowBoundsEffect::register_with_read_factory
72 // Access: Public, Static
73 // Description: Tells the BamReader how to create objects of type
74 // ShowBoundsEffect.
75 ////////////////////////////////////////////////////////////////////
78  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: ShowBoundsEffect::write_datagram
83 // Access: Public, Virtual
84 // Description: Writes the contents of this object to the datagram
85 // for shipping out to a Bam file.
86 ////////////////////////////////////////////////////////////////////
89  RenderEffect::write_datagram(manager, dg);
90  dg.add_bool(_tight);
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: ShowBoundsEffect::make_from_bam
95 // Access: Protected, Static
96 // Description: This function is called by the BamReader's factory
97 // when a new object of type ShowBoundsEffect is encountered
98 // in the Bam file. It should create the ShowBoundsEffect
99 // and extract its information from the file.
100 ////////////////////////////////////////////////////////////////////
101 TypedWritable *ShowBoundsEffect::
102 make_from_bam(const FactoryParams &params) {
103  ShowBoundsEffect *effect = new ShowBoundsEffect;
104  DatagramIterator scan;
105  BamReader *manager;
106 
107  parse_params(params, scan, manager);
108  effect->fillin(scan, manager);
109 
110  return effect;
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: ShowBoundsEffect::fillin
115 // Access: Protected
116 // Description: This internal function is called by make_from_bam to
117 // read in all of the relevant data from the BamFile for
118 // the new ShowBoundsEffect.
119 ////////////////////////////////////////////////////////////////////
120 void ShowBoundsEffect::
121 fillin(DatagramIterator &scan, BamReader *manager) {
122  RenderEffect::fillin(scan, manager);
123  _tight = scan.get_bool();
124 }
static void register_with_read_factory()
Tells the BamReader how to create objects of type ShowBoundsEffect.
bool get_bool()
Extracts a boolean value.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
Applied to a GeomNode to cause a visible bounding volume to be drawn for this node.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is the base class for a number of special render effects that may be set on scene graph nodes to...
Definition: renderEffect.h:56
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void add_bool(bool value)
Adds a boolean value to the datagram.
Definition: datagram.I:118
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43