Panda3D

Loading...
Searching...
No Matches
animControlCollection.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 animControlCollection.h
10 * @author drose
11 * @date 2000-02-22
12 */
13
14#ifndef ANIMCONTROLCOLLECTION_H
15#define ANIMCONTROLCOLLECTION_H
16
17#include "pandabase.h"
18
19#include "animControl.h"
20
21#include "event.h"
22#include "pt_Event.h"
23
24#include "pmap.h"
25
26/**
27 * This is a named collection of AnimControl pointers. An AnimControl may be
28 * added to the collection by name. While an AnimControl is associated, its
29 * reference count is maintained; associating a new AnimControl with the same
30 * name will decrement the previous control's reference count (and possibly
31 * delete it, unbinding its animation).
32 */
33 class EXPCL_PANDA_CHAN AnimControlCollection {
34PUBLISHED:
35 AnimControlCollection();
36 ~AnimControlCollection();
37
38 void store_anim(AnimControl *control, const std::string &name);
39 AnimControl *find_anim(const std::string &name) const;
40 bool unbind_anim(const std::string &name);
41
42 int get_num_anims() const;
43 AnimControl *get_anim(int n) const;
44 std::string get_anim_name(int n) const;
45 MAKE_SEQ(get_anims, get_num_anims, get_anim);
46 MAKE_SEQ(get_anim_names, get_num_anims, get_anim_name);
47
48 void clear_anims();
49
50 // The following functions are convenience functions that vector directly
51 // into the AnimControl's functionality by anim name.
52
53 INLINE bool play(const std::string &anim_name);
54 INLINE bool play(const std::string &anim_name, double from, double to);
55 INLINE bool loop(const std::string &anim_name, bool restart);
56 INLINE bool loop(const std::string &anim_name, bool restart, double from, double to);
57 INLINE bool stop(const std::string &anim_name);
58 INLINE bool pose(const std::string &anim_name, double frame);
59
60 // These functions operate on all anims at once.
61 void play_all();
62 void play_all(double from, double to);
63 void loop_all(bool restart);
64 void loop_all(bool restart, double from, double to);
65 bool stop_all();
66 void pose_all(double frame);
67
68 INLINE int get_frame(const std::string &anim_name) const;
69 INLINE int get_frame() const;
70
71 INLINE int get_num_frames(const std::string &anim_name) const;
72 INLINE int get_num_frames() const;
73
74 INLINE bool is_playing(const std::string &anim_name) const;
75 INLINE bool is_playing() const;
76
77 std::string which_anim_playing() const;
78
79 void output(std::ostream &out) const;
80 void write(std::ostream &out) const;
81
82 private:
83 class ControlDef {
84 public:
85 std::string _name;
86 PT(AnimControl) _control;
87 };
88 typedef pvector<ControlDef> Controls;
89 Controls _controls;
90
91 typedef pmap<std::string, size_t> ControlsByName;
92 ControlsByName _controls_by_name;
93
94 AnimControl *_last_started_control;
95};
96
97INLINE std::ostream &operator << (std::ostream &out, const AnimControlCollection &collection);
98
99#include "animControlCollection.I"
100
101#endif
animControlCollection.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
animControl.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
AnimControlCollection
This is a named collection of AnimControl pointers.
Definition animControlCollection.h:33
AnimControlCollection::get_num_anims
get_num_anims
Returns the number of AnimControls associated with this collection.
Definition animControlCollection.h:45
AnimControlCollection::play
bool play(const std::string &anim_name)
Starts the named animation playing.
Definition animControlCollection.I:18
AnimControlCollection::get_anim
get_anim
Returns the nth AnimControl associated with this collection.
Definition animControlCollection.h:45
AnimControlCollection::stop_all
bool stop_all()
Stops all currently playing animations.
Definition animControlCollection.cxx:204
AnimControlCollection::stop
bool stop(const std::string &anim_name)
Stops the named animation.
Definition animControlCollection.I:74
AnimControlCollection::loop_all
void loop_all(bool restart)
Starts all animations looping.
Definition animControlCollection.cxx:179
AnimControlCollection::get_num_frames
int get_num_frames(const std::string &anim_name) const
Returns the total number of frames in the named animation, or 0 if the animation is not found.
Definition animControlCollection.I:151
AnimControlCollection::is_playing
bool is_playing(const std::string &anim_name) const
Returns true if the named animation is currently playing, false otherwise.
Definition animControlCollection.I:126
AnimControlCollection::clear_anims
void clear_anims()
Disassociates all anims from this collection.
Definition animControlCollection.cxx:146
AnimControlCollection::loop
bool loop(const std::string &anim_name, bool restart)
Starts the named animation looping.
Definition animControlCollection.I:46
AnimControlCollection::AnimControlCollection
AnimControlCollection()
Returns the AnimControl associated with the given name, or NULL if no such control has been associate...
Definition animControlCollection.cxx:24
AnimControlCollection::pose
bool pose(const std::string &anim_name, double frame)
Sets to a particular frame in the named animation.
Definition animControlCollection.I:88
AnimControlCollection::find_anim
AnimControl * find_anim(const std::string &name) const
Returns the AnimControl associated with the given name, or NULL if no such control has been associate...
Definition animControlCollection.cxx:71
AnimControlCollection::store_anim
void store_anim(AnimControl *control, const std::string &name)
Associates the given AnimControl with this collection under the given name.
Definition animControlCollection.cxx:42
AnimControlCollection::which_anim_playing
std::string which_anim_playing() const
Returns the name of the bound AnimControl currently playing, if any.
Definition animControlCollection.cxx:235
AnimControlCollection::pose_all
void pose_all(double frame)
Sets all animations to the indicated frame.
Definition animControlCollection.cxx:221
AnimControlCollection::get_anim_name
get_anim_name
Returns the name of the nth AnimControl associated with this collection.
Definition animControlCollection.h:46
AnimControlCollection::get_frame
int get_frame(const std::string &anim_name) const
Returns the current frame in the named animation, or 0 if the animation is not found.
Definition animControlCollection.I:103
AnimControlCollection::unbind_anim
bool unbind_anim(const std::string &name)
Removes the AnimControl associated with the given name, if any.
Definition animControlCollection.cxx:88
AnimControlCollection::play_all
void play_all()
Starts all animations playing.
Definition animControlCollection.cxx:155
AnimControl
Controls the timing of a character animation.
Definition animControl.h:38
event.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pt_Event.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.