Panda3D
 All Classes Functions Variables Enumerations
animBundleNode.cxx
1 // Filename: animBundleNode.cxx
2 // Created by: drose (06Mar02)
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 "animBundleNode.h"
16 #include "datagram.h"
17 #include "datagramIterator.h"
18 #include "bamReader.h"
19 #include "bamWriter.h"
20 
21 TypeHandle AnimBundleNode::_type_handle;
22 
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: AnimBundleNode::make_copy
26 // Access: Public, Virtual
27 // Description:
28 ////////////////////////////////////////////////////////////////////
30 make_copy() const {
31  return new AnimBundleNode(*this);
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: AnimBundleNode::safe_to_flatten
36 // Access: Public, Virtual
37 // Description: Returns true if it is generally safe to flatten out
38 // this particular kind of Node by duplicating
39 // instances, false otherwise (for instance, a Camera
40 // cannot be safely flattened, because the Camera
41 // pointer itself is meaningful).
42 ////////////////////////////////////////////////////////////////////
44 safe_to_flatten() const {
45  return false;
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: AnimBundleNode::find_anim_bundle
50 // Access: Published, Static
51 // Description: Recursively walks the scene graph beginning at the
52 // indicated node (which need not be an AnimBundleNode),
53 // and returns the first AnimBundle found. Returns NULL
54 // if no AnimBundle can be found.
55 ////////////////////////////////////////////////////////////////////
58  nassertr(root != (PandaNode *)NULL, NULL);
59 
60  if (root->is_of_type(AnimBundleNode::get_class_type())) {
61  AnimBundleNode *anode = DCAST(AnimBundleNode, root);
62  AnimBundle *anim = anode->get_bundle();
63  if (anim != (AnimBundle *)NULL) {
64  return anim;
65  }
66  }
67 
68  Children cr = root->get_children();
69  int num_children = cr.get_num_children();
70  for (int i = 0; i < num_children; i++) {
71  AnimBundle *anim = find_anim_bundle(cr.get_child(i));
72  if (anim != (AnimBundle *)NULL) {
73  return anim;
74  }
75  }
76 
77  return NULL;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: AnimBundleNode::register_with_read_factory
82 // Access: Public, Static
83 // Description: Tells the BamReader how to create objects of type
84 // AnimBundleNode.
85 ////////////////////////////////////////////////////////////////////
88  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: AnimBundleNode::write_datagram
93 // Access: Public, Virtual
94 // Description: Writes the contents of this object to the datagram
95 // for shipping out to a Bam file.
96 ////////////////////////////////////////////////////////////////////
99  PandaNode::write_datagram(manager, dg);
100  manager->write_pointer(dg, _bundle);
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function: AnimBundleNode::complete_pointers
105 // Access: Public, Virtual
106 // Description: Receives an array of pointers, one for each time
107 // manager->read_pointer() was called in fillin().
108 // Returns the number of pointers processed.
109 ////////////////////////////////////////////////////////////////////
112  int pi = PandaNode::complete_pointers(p_list, manager);
113  _bundle = DCAST(AnimBundle, p_list[pi++]);
114  return pi;
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: AnimBundleNode::make_from_bam
119 // Access: Protected, Static
120 // Description: This function is called by the BamReader's factory
121 // when a new object of this type is encountered
122 // in the Bam file. It should create the object
123 // and extract its information from the file.
124 ////////////////////////////////////////////////////////////////////
125 TypedWritable *AnimBundleNode::
126 make_from_bam(const FactoryParams &params) {
127  AnimBundleNode *node = new AnimBundleNode;
128  DatagramIterator scan;
129  BamReader *manager;
130 
131  parse_params(params, scan, manager);
132  node->fillin(scan, manager);
133 
134  return node;
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: AnimBundleNode::fillin
139 // Access: Protected
140 // Description: This internal function is called by make_from_bam to
141 // read in all of the relevant data from the BamFile for
142 // the new PandaNode.
143 ////////////////////////////////////////////////////////////////////
144 void AnimBundleNode::
145 fillin(DatagramIterator &scan, BamReader* manager) {
146  PandaNode::fillin(scan, manager);
147  manager->read_pointer(scan);
148 }
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
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:4164
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
PandaNode * get_child(int n) const
Returns the nth child of the node.
Definition: pandaNode.I:1174
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:31
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:63
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
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 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-&gt;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-&gt;read_pointer() was called in fillin()...
int get_num_children() const
Returns the number of children of the node.
Definition: pandaNode.I:1163
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
Children get_children(Thread *current_thread=Thread::get_current_thread()) const
Returns an object that can be used to walk through the list of children of the node.
Definition: pandaNode.I:773
virtual void write_datagram(BamWriter *manager, Datagram &me)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
static void register_with_read_factory()
Tells the BamReader how to create objects of type AnimBundleNode.
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
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:43
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:279
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:652