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