Panda3D
animBundle.cxx
1 // Filename: animBundle.cxx
2 // Created by: drose (21Feb99)
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 
16 #include "animBundle.h"
17 
18 #include "indent.h"
19 #include "datagram.h"
20 #include "datagramIterator.h"
21 #include "bamReader.h"
22 #include "bamWriter.h"
23 
24 TypeHandle AnimBundle::_type_handle;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: AnimBundle::Copy Constructor
28 // Access: Protected
29 // Description: Creates a new AnimBundle, just like this one, without
30 // copying any children. The new copy is added to the
31 // indicated parent. Intended to be called by
32 // make_copy() only.
33 ////////////////////////////////////////////////////////////////////
34 AnimBundle::
35 AnimBundle(AnimGroup *parent, const AnimBundle &copy) :
36  AnimGroup(parent, copy),
37  _fps(copy._fps),
38  _num_frames(copy._num_frames)
39 {
40  nassertv(_root == (AnimBundle *)NULL);
41  _root = this;
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: AnimBundle::copy_bundle
46 // Access: Published
47 // Description: Returns a full copy of the bundle and its entire tree
48 // of nested AnimGroups. However, the actual data
49 // stored in the leaves--that is, animation tables, such
50 // as those stored in an AnimChannelMatrixXfmTable--will
51 // be shared.
52 ////////////////////////////////////////////////////////////////////
53 PT(AnimBundle) AnimBundle::
54 copy_bundle() const {
55  PT(AnimGroup) group = copy_subtree((AnimGroup *)NULL);
56  return DCAST(AnimBundle, group.p());
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: AnimBundle::output
61 // Access: Public, Virtual
62 // Description: Writes a one-line description of the bundle.
63 ////////////////////////////////////////////////////////////////////
64 void AnimBundle::
65 output(ostream &out) const {
66  out << get_type() << " " << get_name() << ", " << get_num_frames()
67  << " frames at " << get_base_frame_rate() << " fps";
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: AnimBundle::make_copy
72 // Access: Protected, Virtual
73 // Description: Returns a copy of this object, and attaches it to the
74 // indicated parent (which may be NULL only if this is
75 // an AnimBundle). Intended to be called by
76 // copy_subtree() only.
77 ////////////////////////////////////////////////////////////////////
78 AnimGroup *AnimBundle::
79 make_copy(AnimGroup *parent) const {
80  return new AnimBundle(parent, *this);
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: AnimBundle::write_datagram
85 // Access: Public
86 // Description: Function to write the important information in
87 // the particular object to a Datagram
88 ////////////////////////////////////////////////////////////////////
89 void AnimBundle::
90 write_datagram(BamWriter *manager, Datagram &me) {
91  AnimGroup::write_datagram(manager, me);
92  me.add_stdfloat(_fps);
93  me.add_uint16(_num_frames);
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: AnimBundle::fillin
98 // Access: Protected
99 // Description: Function that reads out of the datagram (or asks
100 // manager to read) all of the data that is needed to
101 // re-create this object and stores it in the appropiate
102 // place
103 ////////////////////////////////////////////////////////////////////
104 void AnimBundle::
105 fillin(DatagramIterator &scan, BamReader *manager) {
106  AnimGroup::fillin(scan, manager);
107  _fps = scan.get_stdfloat();
108  _num_frames = scan.get_uint16();
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: AnimBundle::make_AnimBundle
113 // Access: Protected
114 // Description: Factory method to generate a AnimBundle object
115 ////////////////////////////////////////////////////////////////////
118  AnimBundle *me = new AnimBundle;
119  DatagramIterator scan;
120  BamReader *manager;
121 
122  parse_params(params, scan, manager);
123  me->fillin(scan, manager);
124  return me;
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: AnimBundle::register_with_factory
129 // Access: Public, Static
130 // Description: Factory method to generate a AnimBundle object
131 ////////////////////////////////////////////////////////////////////
132 void AnimBundle::
135 }
136 
int get_num_frames() const
Returns the number of frames of animation, or 0 if the animation has no fixed number of frames...
Definition: animBundle.I:58
virtual void output(ostream &out) const
Writes a one-line description of the group.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:31
virtual void write_datagram(BamWriter *manager, Datagram &me)
Writes the contents of this object to the datagram for shipping out to a Bam file.
double get_base_frame_rate() const
Returns the ideal number of frames per second of the animation, when it is running at normal speed...
Definition: animBundle.I:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
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 fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
static TypedWritable * make_AnimBundle(const FactoryParams &params)
Factory method to generate a AnimBundle object.
Definition: animBundle.cxx:117
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
static void register_with_read_factory()
Factory method to generate a AnimBundle object.
Definition: animBundle.cxx:133
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
Definition: datagram.I:240
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:36
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
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
Definition: datagram.I:181
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