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  * Tells the BamReader how to create objects of type AnimBundleNode.
73  */
76  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
77 }
78 
79 /**
80  * Writes the contents of this object to the datagram for shipping out to a
81  * Bam file.
82  */
85  PandaNode::write_datagram(manager, dg);
86  manager->write_pointer(dg, _bundle);
87 }
88 
89 /**
90  * Receives an array of pointers, one for each time manager->read_pointer()
91  * was called in fillin(). Returns the number of pointers processed.
92  */
95  int pi = PandaNode::complete_pointers(p_list, manager);
96  _bundle = DCAST(AnimBundle, p_list[pi++]);
97  return pi;
98 }
99 
100 /**
101  * This function is called by the BamReader's factory when a new object of
102  * this type is encountered in the Bam file. It should create the object and
103  * extract its information from the file.
104  */
105 TypedWritable *AnimBundleNode::
106 make_from_bam(const FactoryParams &params) {
107  AnimBundleNode *node = new AnimBundleNode;
108  DatagramIterator scan;
109  BamReader *manager;
110 
111  parse_params(params, scan, manager);
112  node->fillin(scan, manager);
113 
114  return node;
115 }
116 
117 /**
118  * This internal function is called by make_from_bam to read in all of the
119  * relevant data from the BamFile for the new PandaNode.
120  */
121 void AnimBundleNode::
122 fillin(DatagramIterator &scan, BamReader* manager) {
123  PandaNode::fillin(scan, manager);
124  manager->read_pointer(scan);
125 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
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:3589
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PandaNode * get_child(size_t n) const
Returns the nth child of the node.
Definition: pandaNode.I:962
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:29
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.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
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
static AnimBundle * find_anim_bundle(PandaNode *root)
Recursively walks the scene graph beginning at the indicated node (which need not be an AnimBundleNod...
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().
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().
size_t get_num_children() const
Returns the number of children of the node.
Definition: pandaNode.I:953
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_children
Returns an object that can be used to walk through the list of children of the node.
Definition: pandaNode.h:784
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
virtual void write_datagram(BamWriter *manager, Datagram &me)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of Node by duplicating insta...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
static void register_with_read_factory()
Tells the BamReader how to create objects of type AnimBundleNode.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:28
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:81
This is a node that contains a pointer to an AnimBundle.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.