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