Panda3D
animInterface.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 animInterface.h
10  * @author drose
11  * @date 2005-09-20
12  */
13 
14 #ifndef ANIMINTERFACE_H
15 #define ANIMINTERFACE_H
16 
17 #include "pandabase.h"
18 #include "typeHandle.h"
19 #include "register_type.h"
20 #include "cycleData.h"
21 #include "cycleDataReader.h"
22 #include "cycleDataWriter.h"
23 #include "pipelineCycler.h"
24 
25 class BamWriter;
26 class BamReader;
27 class Datagram;
28 class DatagramIterator;
29 
30 /**
31  * This is the fundamental interface for things that have a play/loop/stop
32  * type interface for frame-based animation, such as animated characters.
33  * This is the base class for AnimControl and other, similar classes.
34  */
35 class EXPCL_PANDA_PUTIL AnimInterface {
36 protected:
37  AnimInterface();
38  AnimInterface(const AnimInterface &copy);
39 
40 PUBLISHED:
41  virtual ~AnimInterface();
42  INLINE void play();
43  INLINE void play(double from, double to);
44  INLINE void loop(bool restart);
45  INLINE void loop(bool restart, double from, double to);
46  INLINE void pingpong(bool restart);
47  INLINE void pingpong(bool restart, double from, double to);
48  INLINE void stop();
49  INLINE void pose(double frame);
50 
51  INLINE void set_play_rate(double play_rate);
52  INLINE double get_play_rate() const;
53  INLINE double get_frame_rate() const;
54  virtual int get_num_frames() const;
55 
56  INLINE int get_frame() const;
57  INLINE int get_next_frame() const;
58  INLINE double get_frac() const;
59  INLINE int get_full_frame() const;
60  INLINE double get_full_fframe() const;
61  INLINE bool is_playing() const;
62 
63  virtual void output(std::ostream &out) const;
64 
65 PUBLISHED:
66  MAKE_PROPERTY(play_rate, get_play_rate, set_play_rate);
67  MAKE_PROPERTY(frame_rate, get_frame_rate);
68  MAKE_PROPERTY(num_frames, get_num_frames);
69 
70  MAKE_PROPERTY(frame, get_frame);
71  MAKE_PROPERTY(next_frame, get_next_frame);
72  MAKE_PROPERTY(frac, get_frac);
73  MAKE_PROPERTY(full_frame, get_full_frame);
74  MAKE_PROPERTY(full_fframe, get_full_fframe);
75  MAKE_PROPERTY(playing, is_playing);
76 
77 protected:
78  INLINE void set_frame_rate(double frame_rate);
79  INLINE void set_num_frames(int num_frames);
80  virtual void animation_activated();
81 
82 private:
83  enum PlayMode {
84  PM_pose,
85  PM_play,
86  PM_loop,
87  PM_pingpong,
88  };
89 
90  // This data is not cycled, because it is a semi-permanent part of the
91  // interface. Also, some derivatives of AnimInterface don't even use it.
92  int _num_frames;
93 
94  // This is the data that must be cycled between pipeline stages.
95  class EXPCL_PANDA_PUTIL CData : public CycleData {
96  public:
97  CData();
98  CData(const CData &copy);
99  virtual CycleData *make_copy() const;
100  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
101  virtual void fillin(DatagramIterator &scan, BamReader *manager);
102  virtual TypeHandle get_parent_type() const {
103  return AnimInterface::get_class_type();
104  }
105 
106  void play(double from, double to);
107  void loop(bool restart, double from, double to);
108  void pingpong(bool restart, double from, double to);
109  void pose(double frame);
110 
111  INLINE double get_frac() const;
112  int get_full_frame(int increment) const;
113  double get_full_fframe() const;
114  bool is_playing() const;
115 
116  virtual void output(std::ostream &out) const;
117 
118  void internal_set_rate(double frame_rate, double play_rate);
119  double get_f() const;
120 
121  double _frame_rate;
122 
123  PlayMode _play_mode;
124  double _start_time;
125  double _start_frame;
126  double _play_frames;
127  int _from_frame;
128  int _to_frame;
129 
130  double _play_rate;
131  double _effective_frame_rate;
132  bool _paused;
133  double _paused_f;
134  };
135 
136  PipelineCycler<CData> _cycler;
137  typedef CycleDataReader<CData> CDReader;
138  typedef CycleDataWriter<CData> CDWriter;
139 
140 protected:
141  virtual void write_datagram(BamWriter *manager, Datagram &dg);
142  void fillin(DatagramIterator &scan, BamReader *manager);
143 
144 public:
145  static TypeHandle get_class_type() {
146  return _type_handle;
147  }
148  static void init_type() {
149  register_type(_type_handle, "AnimInterface");
150  }
151 
152 private:
153  static TypeHandle _type_handle;
154 };
155 
156 INLINE std::ostream &operator << (std::ostream &out, const AnimInterface &ai);
157 
158 #include "animInterface.I"
159 
160 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:47
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:76
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is the fundamental interface for things that have a play/loop/stop type interface for frame-base...
Definition: animInterface.h:35
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
virtual void write_datagram(BamWriter *, Datagram &) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: cycleData.cxx:32
virtual void output(std::ostream &out) const
Formats the contents of the CycleData in some meaningful way for humans.
Definition: cycleData.cxx:85
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 template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition: cycleData.cxx:58
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.