Panda3D
 All Classes Functions Variables Enumerations
recorderController.h
1 // Filename: recorderController.h
2 // Created by: drose (25Jan04)
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 RECORDERCONTROLLER_H
16 #define RECORDERCONTROLLER_H
17 
18 #include "pandabase.h"
19 #include "datagramOutputFile.h"
20 #include "datagramInputFile.h"
21 #include "recorderTable.h"
22 #include "recorderHeader.h"
23 #include "typedReferenceCount.h"
24 #include "factory.h"
25 
26 class RecorderBase;
27 class RecorderFrame;
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : RecorderController
31 // Description : This object manages the process of recording the
32 // user's runtime inputs to a bam file so that the
33 // session can be recreated later.
34 ////////////////////////////////////////////////////////////////////
35 class EXPCL_PANDA_RECORDER RecorderController : public TypedReferenceCount {
36 PUBLISHED:
39 
40  bool begin_record(const Filename &filename);
41  bool begin_playback(const Filename &filename);
42  void close();
43 
44  INLINE time_t get_start_time() const;
45 
46  INLINE void set_random_seed(int random_seed);
47  INLINE int get_random_seed() const;
48 
49  INLINE bool is_recording() const;
50  INLINE bool is_playing() const;
51  INLINE bool is_open() const;
52  INLINE const Filename &get_filename() const;
53 
54  INLINE bool is_error();
55  INLINE double get_clock_offset() const;
56  INLINE int get_frame_offset() const;
57 
58  INLINE void add_recorder(const string &name, RecorderBase *recorder);
59  INLINE bool has_recorder(const string &name) const;
60  INLINE RecorderBase *get_recorder(const string &name) const;
61  INLINE bool remove_recorder(const string &name);
62 
63  INLINE void set_frame_tie(bool frame_tie);
64  INLINE bool get_frame_tie() const;
65 
66  void record_frame();
67  void play_frame();
68 
69 public:
71 
72  INLINE static RecorderFactory *get_factory();
73 
74 private:
75  INLINE static void create_factory();
76  RecorderFrame *read_frame();
77 
78 private:
79  RecorderHeader _header;
80  double _clock_offset;
81  int _frame_offset;
82 
83  Filename _filename;
84  DatagramOutputFile _dout;
85  DatagramInputFile _din;
86  BamWriter *_writer;
87  BamReader *_reader;
88  bool _frame_tie;
89 
90  // _user_table is directly modified by the user.
91  RecorderTable *_user_table;
92  bool _user_table_modified;
93 
94  // In playback mode, _file_table represents the table as read
95  // directly from the session file, with default recorders in each
96  // slot.
97  RecorderTable *_file_table;
98 
99  // In playback mode, _active_table is the result of the merge of
100  // _file_table and _user_table, with a default recorder or a
101  // user-specified recorder in each active slot.
102  RecorderTable *_active_table;
103 
104  RecorderFrame *_next_frame;
105  bool _eof;
106 
107  static RecorderFactory *_factory;
108 
109 public:
110  static TypeHandle get_class_type() {
111  return _type_handle;
112  }
113  static void init_type() {
114  TypedReferenceCount::init_type();
115  register_type(_type_handle, "RecorderController",
116  TypedReferenceCount::get_class_type());
117  }
118  virtual TypeHandle get_type() const {
119  return get_class_type();
120  }
121  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
122 
123 private:
124  static TypeHandle _type_handle;
125 
126  friend class RecorderFrame;
127 };
128 
129 #include "recorderController.I"
130 
131 #endif
132 
A Factory can be used to create an instance of a particular subclass of some general base class...
Definition: factory.h:41
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This class can be used to read a binary file that consists of an arbitrary header followed by a numbe...
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This object is used by the RecorderController to write (and read) a record of the set of recorders in...
Definition: recorderTable.h:35
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This is the base class to a number of objects that record particular kinds of user input (like a Mous...
Definition: recorderBase.h:55
This class can be used to write a binary file that consists of an arbitrary header followed by a numb...
This object represents one frame of data in the recorded session file.
Definition: recorderFrame.h:35
This object contains the header information written out at the beginning of a recorded session file...
This object manages the process of recording the user's runtime inputs to a bam file so that the sess...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85