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 */
33class EXPCL_PANDA_CHAN AnimControlCollection {
34PUBLISHED:
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
82private:
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
100
101#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a named collection of AnimControl pointers.
get_num_anims
Returns the number of AnimControls associated with this collection.
bool play(const std::string &anim_name)
Starts the named animation playing.
get_anim
Returns the nth AnimControl associated with this collection.
bool stop_all()
Stops all currently playing animations.
bool stop(const std::string &anim_name)
Stops the named animation.
void loop_all(bool restart)
Starts all animations looping.
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.
bool is_playing(const std::string &anim_name) const
Returns true if the named animation is currently playing, false otherwise.
void clear_anims()
Disassociates all anims from this collection.
bool loop(const std::string &anim_name, bool restart)
Starts the named animation looping.
AnimControlCollection()
Returns the AnimControl associated with the given name, or NULL if no such control has been associate...
bool pose(const std::string &anim_name, double frame)
Sets to a particular frame in the named animation.
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...
void store_anim(AnimControl *control, const std::string &name)
Associates the given AnimControl with this collection under the given name.
std::string which_anim_playing() const
Returns the name of the bound AnimControl currently playing, if any.
void pose_all(double frame)
Sets all animations to the indicated frame.
get_anim_name
Returns the name of the nth AnimControl associated with this collection.
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.
bool unbind_anim(const std::string &name)
Removes the AnimControl associated with the given name, if any.
void play_all()
Starts all animations playing.
Controls the timing of a character animation.
Definition animControl.h:38
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.