Panda3D
animBundleNode.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 animBundleNode.cxx
10  * @author drose
11  * @date 2002-03-06
12  */
13 
14 #include "animBundleNode.h"
15 #include "datagram.h"
16 #include "datagramIterator.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 
20 TypeHandle AnimBundleNode::_type_handle;
21 
22 
23 /**
24  *
25  */
27 make_copy() const {
28  return new AnimBundleNode(*this);
29 }
30 
31 /**
32  * Returns true if it is generally safe to flatten out this particular kind of
33  * Node by duplicating instances, false otherwise (for instance, a Camera
34  * cannot be safely flattened, because the Camera pointer itself is
35  * meaningful).
36  */
38 safe_to_flatten() const {
39  return false;
40 }
41 
42 /**
43  * Recursively walks the scene graph beginning at the indicated node (which
44  * need not be an AnimBundleNode), and returns the first AnimBundle found.
45  * Returns NULL if no AnimBundle can be found.
46  */
49  nassertr(root != nullptr, nullptr);
50 
51  if (root->is_of_type(AnimBundleNode::get_class_type())) {
52  AnimBundleNode *anode = DCAST(AnimBundleNode, root);
53  AnimBundle *anim = anode->get_bundle();
54  if (anim != nullptr) {
55  return anim;
56  }
57  }
58 
59  Children cr = root->get_children();
60  int num_children = cr.get_num_children();
61  for (int i = 0; i < num_children; i++) {
62  AnimBundle *anim = find_anim_bundle(cr.get_child(i));
63  if (anim != nullptr) {
64  return anim;
65  }
66  }
67 
68  return nullptr;
69 }
70 
71 /**
72  *
73  */
74 void AnimBundleNode::
75 output(std::ostream &out) const {
76  PandaNode::output(out);
77  if (_bundle != nullptr) {
78  out << " (";
79  _bundle->output(out);
80  out << ")";
81  }
82 }
83 
84 /**
85  * Tells the BamReader how to create objects of type AnimBundleNode.
86  */
89  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
90 }
91 
92 /**
93  * Writes the contents of this object to the datagram for shipping out to a
94  * Bam file.
95  */
97 write_datagram(BamWriter *manager, Datagram &dg) {
98  PandaNode::write_datagram(manager, dg);
99  manager->write_pointer(dg, _bundle);
100 }
101 
102 /**
103  * Receives an array of pointers, one for each time manager->read_pointer()
104  * was called in fillin(). Returns the number of pointers processed.
105  */
107 complete_pointers(TypedWritable **p_list, BamReader* manager) {
108  int pi = PandaNode::complete_pointers(p_list, manager);
109  _bundle = DCAST(AnimBundle, p_list[pi++]);
110  return pi;
111 }
112 
113 /**
114  * This function is called by the BamReader's factory when a new object of
115  * this type is encountered in the Bam file. It should create the object and
116  * extract its information from the file.
117  */
118 TypedWritable *AnimBundleNode::
119 make_from_bam(const FactoryParams &params) {
120  AnimBundleNode *node = new AnimBundleNode;
121  DatagramIterator scan;
122  BamReader *manager;
123 
124  parse_params(params, scan, manager);
125  node->fillin(scan, manager);
126 
127  return node;
128 }
129 
130 /**
131  * This internal function is called by make_from_bam to read in all of the
132  * relevant data from the BamFile for the new PandaNode.
133  */
134 void AnimBundleNode::
135 fillin(DatagramIterator &scan, BamReader* manager) {
136  PandaNode::fillin(scan, manager);
137  manager->read_pointer(scan);
138 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 a node that contains a pointer to an AnimBundle.
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of Node by duplicating insta...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
static void register_with_read_factory()
Tells the BamReader how to create objects of type AnimBundleNode.
static AnimBundle * find_anim_bundle(PandaNode *root)
Recursively walks the scene graph beginning at the indicated node (which need not be an AnimBundleNod...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:29
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
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
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:317
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
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
PandaNode * get_child(size_t n) const
Returns the nth child of the node.
Definition: pandaNode.I:962
size_t get_num_children() const
Returns the number of children of the node.
Definition: pandaNode.I:953
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
get_children
Returns an object that can be used to walk through the list of children of the node.
Definition: pandaNode.h:782
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:3583
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:28
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.