Panda3D
Loading...
Searching...
No Matches
animControl.h
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 animControl.h
10 * @author drose
11 * @date 1999-02-19
12 */
13
14#ifndef ANIMCONTROL_H
15#define ANIMCONTROL_H
16
17#include "pandabase.h"
18
19#include "animInterface.h"
20#include "animBundle.h"
21#include "partGroup.h"
22#include "bitArray.h"
23#include "pandaNode.h"
24#include "typedReferenceCount.h"
25#include "namable.h"
26#include "pmutex.h"
27#include "conditionVarFull.h"
28
29class PartBundle;
30class AnimChannelBase;
31
32/**
33 * Controls the timing of a character animation. An AnimControl object is
34 * created for each character/bundle binding and manages the state of the
35 * animation: whether started, stopped, or looping, and the current frame
36 * number and play rate.
37 */
38class EXPCL_PANDA_CHAN AnimControl : public TypedReferenceCount, public AnimInterface, public Namable {
39public:
40 AnimControl(const std::string &name, PartBundle *part,
41 double frame_rate, int num_frames);
42 AnimControl(const AnimControl &copy) = delete;
43
44 void setup_anim(PartBundle *part, AnimBundle *anim, int channel_index,
45 const BitArray &bound_joints);
46 void set_bound_joints(const BitArray &bound_joints);
47 void fail_anim(PartBundle *part);
48
49PUBLISHED:
50 virtual ~AnimControl();
51
52 INLINE bool is_pending() const;
53 void wait_pending();
54 INLINE bool has_anim() const;
55 void set_pending_done_event(const std::string &done_event);
56 std::string get_pending_done_event() const;
57
58 PartBundle *get_part() const;
59 INLINE AnimBundle *get_anim() const;
60 INLINE int get_channel_index() const;
61 INLINE const BitArray &get_bound_joints() const;
62
63 INLINE void set_anim_model(PandaNode *model);
64 INLINE PandaNode *get_anim_model() const;
65
66 virtual void output(std::ostream &out) const;
67
68public:
69 // The following functions aren't really part of the public interface;
70 // they're just public so we don't have to declare a bunch of friends.
71
72 bool channel_has_changed(AnimChannelBase *channel, bool frame_blend_flag) const;
73 void mark_channels(bool frame_blend_flag);
74
75protected:
76 virtual void animation_activated();
77
78private:
79 bool _pending;
80 std::string _pending_done_event;
81 Mutex _pending_lock; // protects the above two.
82 ConditionVarFull _pending_cvar; // signals when _pending goes true.
83
84 // This is a PT(PartGroup) instead of a PT(PartBundle), just because we
85 // can't include partBundle.h for circular reasons. But it actually keeps a
86 // pointer to a PartBundle.
87 const PT(PartGroup) _part;
88 PT(AnimBundle) _anim;
89 int _channel_index;
90
91 // This is the frame number as of the last call to mark_channels(). In
92 // frame_blend mode, we also record the fractional part of the frame number.
93 int _marked_frame;
94 double _marked_frac;
95
96 // This is the bitmask of joints andor sliders from the animation that we
97 // have actually bound into this AnimControl. See get_bound_joints().
98 BitArray _bound_joints;
99
100 PT(PandaNode) _anim_model;
101
102public:
103 virtual TypeHandle get_type() const {
104 return get_class_type();
105 }
106 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
107
108 static TypeHandle get_class_type() {
109 return _type_handle;
110 }
111 static void init_type() {
112 TypedReferenceCount::init_type();
113 AnimInterface::init_type();
114 register_type(_type_handle, "AnimControl",
115 TypedReferenceCount::get_class_type(),
116 AnimInterface::get_class_type());
117 }
118
119private:
120 static TypeHandle _type_handle;
121};
122
123INLINE std::ostream &operator << (std::ostream &out, const AnimControl &control);
124
125#include "animControl.I"
126
127#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the root of an AnimChannel hierarchy.
Definition animBundle.h:29
Parent class for all animation channels.
Controls the timing of a character animation.
Definition animControl.h:38
AnimControl(const std::string &name, PartBundle *part, double frame_rate, int num_frames)
This constructor is used to create a temporarily uninitialized AnimControl that will serve as a place...
void set_bound_joints(const BitArray &bound_joints)
Called to initialize the AnimControl with its array of bound_joints, before setup_anim() has complete...
void mark_channels(bool frame_blend_flag)
Marks this point as the point of reference for the next call to channel_has_changed().
const BitArray & get_bound_joints() const
Returns the subset of joints controlled by this AnimControl.
Definition animControl.I:64
void fail_anim(PartBundle *part)
This can only be called once for a given AnimControl.
bool is_pending() const
Returns true if the AnimControl is being bound asynchronously, and has not yet finished.
Definition animControl.I:21
void wait_pending()
Blocks the current thread until the AnimControl has finished loading and is fully bound.
void setup_anim(PartBundle *part, AnimBundle *anim, int channel_index, const BitArray &bound_joints)
This can only be called once for a given AnimControl.
std::string get_pending_done_event() const
Returns the event name that will be thrown when the AnimControl is finished binding asynchronously.
void set_pending_done_event(const std::string &done_event)
Specifies an event name that will be thrown when the AnimControl is finished binding asynchronously.
AnimBundle * get_anim() const
Returns the AnimBundle bound in with this AnimControl.
Definition animControl.I:38
void set_anim_model(PandaNode *model)
Associates the indicated PandaNode with the AnimControl.
Definition animControl.I:79
bool channel_has_changed(AnimChannelBase *channel, bool frame_blend_flag) const
Returns true if the indicated channel value has changed since the last call to mark_channels().
bool has_anim() const
Returns true if the AnimControl was successfully loaded, or false if there was a problem.
Definition animControl.I:30
PandaNode * get_anim_model() const
Retrieves the pointer set via set_anim_model().
Definition animControl.I:87
PartBundle * get_part() const
Returns the PartBundle bound in with this AnimControl.
int get_channel_index() const
Returns the particular channel index associated with this AnimControl.
Definition animControl.I:52
A dynamic array with an unlimited number of bits.
Definition bitArray.h:40
This class implements a condition variable; see ConditionVar for a brief introduction to this class.
A standard mutex, or mutual exclusion lock.
Definition pmutex.h:40
void output(std::ostream &out) const
Outputs the Namable.
Definition namable.I:61
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
This is the root of a MovingPart hierarchy.
Definition partBundle.h:46
This is the base class for PartRoot and MovingPart.
Definition partGroup.h:43
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.