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