Panda3D
Loading...
Searching...
No Matches
animBundle.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 animBundle.cxx
10 * @author drose
11 * @date 1999-02-21
12 */
13
14#include "animBundle.h"
15
16#include "indent.h"
17#include "datagram.h"
18#include "datagramIterator.h"
19#include "bamReader.h"
20#include "bamWriter.h"
21
22TypeHandle AnimBundle::_type_handle;
23
24/**
25 * Creates a new AnimBundle, just like this one, without copying any children.
26 * The new copy is added to the indicated parent. Intended to be called by
27 * make_copy() only.
28 */
29AnimBundle::
30AnimBundle(AnimGroup *parent, const AnimBundle &copy) :
31 AnimGroup(parent, copy),
32 _fps(copy._fps),
33 _num_frames(copy._num_frames)
34{
35 nassertv(_root == nullptr);
36 _root = this;
37}
38
39/**
40 * Returns a full copy of the bundle and its entire tree of nested AnimGroups.
41 * However, the actual data stored in the leaves--that is, animation tables,
42 * such as those stored in an AnimChannelMatrixXfmTable--will be shared.
43 */
44PT(AnimBundle) AnimBundle::
45copy_bundle() const {
46 PT(AnimGroup) group = copy_subtree(nullptr);
47 return DCAST(AnimBundle, group.p());
48}
49
50/**
51 * Writes a one-line description of the bundle.
52 */
53void AnimBundle::
54output(std::ostream &out) const {
55 out << get_type() << " " << get_name() << ", " << get_num_frames()
56 << " frames at " << get_base_frame_rate() << " fps";
57}
58
59/**
60 * Returns a copy of this object, and attaches it to the indicated parent
61 * (which may be NULL only if this is an AnimBundle). Intended to be called
62 * by copy_subtree() only.
63 */
64AnimGroup *AnimBundle::
65make_copy(AnimGroup *parent) const {
66 return new AnimBundle(parent, *this);
67}
68
69/**
70 * Function to write the important information in the particular object to a
71 * Datagram
72 */
73void AnimBundle::
74write_datagram(BamWriter *manager, Datagram &me) {
75 AnimGroup::write_datagram(manager, me);
76 me.add_stdfloat(_fps);
77 me.add_uint16(_num_frames);
78}
79
80/**
81 * Function that reads out of the datagram (or asks manager to read) all of
82 * the data that is needed to re-create this object and stores it in the
83 * appropiate place
84 */
85void AnimBundle::
86fillin(DatagramIterator &scan, BamReader *manager) {
87 AnimGroup::fillin(scan, manager);
88 _fps = scan.get_stdfloat();
89 _num_frames = scan.get_uint16();
90}
91
92/**
93 * Factory method to generate a AnimBundle object
94 */
96make_AnimBundle(const FactoryParams &params) {
97 AnimBundle *me = new AnimBundle;
99 BamReader *manager;
100
101 parse_params(params, scan, manager);
102 me->fillin(scan, manager);
103 return me;
104}
105
106/**
107 * Factory method to generate a AnimBundle object
108 */
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 the root of an AnimChannel hierarchy.
Definition animBundle.h:29
static TypedWritable * make_AnimBundle(const FactoryParams &params)
Factory method to generate a AnimBundle object.
get_base_frame_rate
Returns the ideal number of frames per second of the animation, when it is running at normal speed.
Definition animBundle.h:41
static void register_with_read_factory()
Factory method to generate a AnimBundle object.
virtual void output(std::ostream &out) const
Writes a one-line description of the group.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Writes the contents of this object to the datagram for shipping out to a Bam file.
get_num_frames
Returns the number of frames of animation, or 0 if the animation has no fixed number of frames.
Definition animBundle.h:42
This is the base class for AnimChannel and AnimBundle.
Definition animGroup.h:33
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 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.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
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:133
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
Definition datagram.I:85
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.