Panda3D
recorderController.I
1 // Filename: recorderController.I
2 // Created by: drose (24Jan04)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: RecorderController::get_start_time
18 // Access: Published
19 // Description: Returns the time (and date) at which the current
20 // session was originally recorded (or, in recording
21 // mode, the time at which the current session began).
22 ////////////////////////////////////////////////////////////////////
23 INLINE time_t RecorderController::
24 get_start_time() const {
25  return _header._start_time;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: RecorderController::set_random_seed
30 // Access: Published
31 // Description: Indicates an arbitrary number to be recorded in the
32 // session file as a random seed, should the application
33 // wish to take advantage of it. This must be set
34 // before begin_record() is called.
35 ////////////////////////////////////////////////////////////////////
36 INLINE void RecorderController::
37 set_random_seed(int random_seed) {
38  _header._random_seed = random_seed;
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: RecorderController::get_random_seed
43 // Access: Published
44 // Description: Returns the random seed that was set by a previous
45 // call to set_random_seed(), or the number read from
46 // the session file after begin_playback() has been
47 // called.
48 ////////////////////////////////////////////////////////////////////
49 INLINE int RecorderController::
50 get_random_seed() const {
51  return _header._random_seed;
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: RecorderController::is_recording
56 // Access: Published
57 // Description: Returns true if the controller has been opened for
58 // output, false otherwise.
59 ////////////////////////////////////////////////////////////////////
60 INLINE bool RecorderController::
61 is_recording() const {
62  return (_writer != (BamWriter *)NULL);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: RecorderController::is_playing
67 // Access: Published
68 // Description: Returns true if the controller has been opened for
69 // input, false otherwise.
70 ////////////////////////////////////////////////////////////////////
71 INLINE bool RecorderController::
72 is_playing() const {
73  return (_reader != (BamReader *)NULL);
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: RecorderController::is_open
78 // Access: Published
79 // Description: Returns true if the controller has been opened for
80 // either input or output, false otherwise.
81 ////////////////////////////////////////////////////////////////////
82 INLINE bool RecorderController::
83 is_open() const {
84  return is_recording() || is_playing();
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: RecorderController::get_filename
89 // Access: Published
90 // Description: Returns the filename that was passed to the most
91 // recent call to begin_record() or begin_playback().
92 ////////////////////////////////////////////////////////////////////
93 INLINE const Filename &RecorderController::
94 get_filename() const {
95  return _filename;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: RecorderController::is_error
100 // Access: Published
101 // Description: Returns true if the controller has been opened for
102 // input or output output and there is an error on the
103 // stream, or false if the controller is closed or if
104 // there is no problem.
105 ////////////////////////////////////////////////////////////////////
106 INLINE bool RecorderController::
108  return _dout.is_error() || _din.is_error();
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: RecorderController::get_clock_offset
113 // Access: Published
114 // Description: Returns the delta offset between the actual frame
115 // time and the frame time written to the log. This is
116 // essentially the time at which the recording (or
117 // playback) started.
118 ////////////////////////////////////////////////////////////////////
119 INLINE double RecorderController::
121  return _clock_offset;
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: RecorderController::get_frame_offset
126 // Access: Published
127 // Description: Returns the delta offset between the actual frame
128 // count and the frame count written to the log. This is
129 // essentially the frame number at which the recording
130 // (or playback) started.
131 ////////////////////////////////////////////////////////////////////
132 INLINE int RecorderController::
134  return _frame_offset;
135 }
136 
137 
138 ////////////////////////////////////////////////////////////////////
139 // Function: RecorderController::add_recorder
140 // Access: Published
141 // Description: Adds the named recorder to the set of recorders that
142 // are in use.
143 //
144 // If the controller is in recording mode, the named
145 // recorder will begin recording its status to the
146 // session file. If the controller is in playback mode
147 // and the name and type matches a recorder in the
148 // session file, the recorder will begin receiving data.
149 ////////////////////////////////////////////////////////////////////
150 INLINE void RecorderController::
151 add_recorder(const string &name, RecorderBase *recorder) {
152  _user_table->add_recorder(name, recorder);
153  _user_table_modified = true;
154 
155  // We can only add the state flag immediately if we are in recording
156  // mode. In playback mode, we're not sure yet whether the new
157  // recorder state will actually be playing (we won't know until we
158  // merge the tables in play_frame()).
159  if (is_recording()) {
160  recorder->_flags |= RecorderBase::F_recording;
161  }
162 }
163 
164 ////////////////////////////////////////////////////////////////////
165 // Function: RecorderController::has_recorder
166 // Access: Published
167 // Description: Returns true if the named recorder has been added to
168 // the table by a previous call to add_recorder(), false
169 // otherwise.
170 //
171 // If the controller is in playback mode, this will also
172 // return false for a recorder that was found in the
173 // session file but was never explicitly added via
174 // add_recorder(); see get_recorder().
175 ////////////////////////////////////////////////////////////////////
176 INLINE bool RecorderController::
177 has_recorder(const string &name) const {
178  return (_user_table->get_recorder(name) != (RecorderBase *)NULL);
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: RecorderController::get_recorder
183 // Access: Published
184 // Description: Returns the recorder with the indicated name, or NULL
185 // if there is no such recorder.
186 //
187 // If the controller is in playback mode, this may
188 // return the recorder matching the indicated name as
189 // read from the session file, even if it was never
190 // added to the table by the user. In this case,
191 // has_recorder() may return false, but get_recorder()
192 // will return a non-NULL value.
193 ////////////////////////////////////////////////////////////////////
195 get_recorder(const string &name) const {
196  RecorderBase *recorder = _user_table->get_recorder(name);
197  if (is_playing() && recorder == (RecorderBase *)NULL) {
198  recorder = _active_table->get_recorder(name);
199  }
200  return recorder;
201 }
202 
203 ////////////////////////////////////////////////////////////////////
204 // Function: RecorderController::remove_recorder
205 // Access: Published
206 // Description: Removes the named recorder from the table. Returns
207 // true if successful, false if there was no such
208 // recorder.
209 //
210 // If the controller is in recording mode, the named
211 // recorder will stop recording. If the controller is
212 // in playback mode, the named recorder will
213 // disassociate itself from the session file (but if the
214 // session file still has data for this name, a default
215 // recorder will take its place to decode the data from
216 // the session file).
217 ////////////////////////////////////////////////////////////////////
218 INLINE bool RecorderController::
219 remove_recorder(const string &name) {
220  // If we are playing or recording, immediately remove the state flag
221  // from the recorder. (When we are playing, the state flag will get
222  // removed automatically at the next call to play_frame(), but we
223  // might as well be aggressive and remove it now. When we are
224  // recording, we have to remove it now.)
225  if (is_recording() || is_playing()) {
226  RecorderBase *recorder = _user_table->get_recorder(name);
227  if (recorder != (RecorderBase *)NULL) {
228  recorder->_flags &= ~(RecorderBase::F_recording | RecorderBase::F_playing);
229  }
230  }
231  _user_table_modified = true;
232  return _user_table->remove_recorder(name);
233 }
234 
235 ////////////////////////////////////////////////////////////////////
236 // Function: RecorderController::set_frame_tie
237 // Access: Published
238 // Description: Sets the frame_tie flag.
239 //
240 // When this is true, sessions are played back
241 // frame-for-frame, based on the frame count of the
242 // recorded session. This gives the most accurate
243 // playback, but the playback rate will vary according
244 // to the frame rate of the playback machine.
245 //
246 // When this is false, sessions are played back at real
247 // time, based on the clock of the recorded session.
248 // This may introduce playback discrepencies if the
249 // frames do not fall at exactly the same times as they
250 // did in the original.
251 ////////////////////////////////////////////////////////////////////
252 INLINE void RecorderController::
253 set_frame_tie(bool frame_tie) {
254  _frame_tie = frame_tie;
255 }
256 
257 ////////////////////////////////////////////////////////////////////
258 // Function: RecorderController::get_frame_tie
259 // Access: Published
260 // Description: See set_frame_tie().
261 ////////////////////////////////////////////////////////////////////
262 INLINE bool RecorderController::
263 get_frame_tie() const {
264  return _frame_tie;
265 }
266 
267 ////////////////////////////////////////////////////////////////////
268 // Function: RecorderController::get_factory
269 // Access: Public, Static
270 // Description: Returns the global RecorderFactory for generating
271 // TypedWritable objects
272 ////////////////////////////////////////////////////////////////////
275  if (_factory == (RecorderFactory *)NULL) {
276  create_factory();
277  }
278  return _factory;
279 }
280 
281 ////////////////////////////////////////////////////////////////////
282 // Function: RecorderController::create_factory
283 // Access: Private, Static
284 // Description: Creates a new RecorderFactory for generating
285 // TypedWritable objects
286 ////////////////////////////////////////////////////////////////////
287 INLINE void RecorderController::
288 create_factory() {
289  _factory = new RecorderFactory;
290 }
bool remove_recorder(const string &name)
Removes the named recorder from the table.
bool is_error()
Returns true if the controller has been opened for input or output output and there is an error on th...
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
virtual bool is_error()
Returns true if the file has reached an error condition.
bool remove_recorder(const string &name)
Removes the named recorder from the table.
Definition: recorderTable.I:95
void set_frame_tie(bool frame_tie)
Sets the frame_tie flag.
static RecorderFactory * get_factory()
Returns the global RecorderFactory for generating TypedWritable objects.
void set_random_seed(int random_seed)
Indicates an arbitrary number to be recorded in the session file as a random seed, should the application wish to take advantage of it.
bool is_recording() const
Returns true if the controller has been opened for output, false otherwise.
bool is_open() const
Returns true if the controller has been opened for either input or output, false otherwise.
const Filename & get_filename() const
Returns the filename that was passed to the most recent call to begin_record() or begin_playback()...
virtual bool is_error()
Returns true if the file has reached an error condition.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
void add_recorder(const string &name, RecorderBase *recorder)
Adds the named recorder to the set of recorders that are in use.
int get_random_seed() const
Returns the random seed that was set by a previous call to set_random_seed(), or the number read from...
int get_frame_offset() const
Returns the delta offset between the actual frame count and the frame count written to the log...
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
RecorderBase * get_recorder(const string &name) const
Returns the recorder with the indicated name, or NULL if there is no such recorder.
Definition: recorderTable.I:79
bool has_recorder(const string &name) const
Returns true if the named recorder has been added to the table by a previous call to add_recorder()...
void add_recorder(const string &name, RecorderBase *recorder)
Adds the named recorder to the set of recorders.
Definition: recorderTable.I:58
bool get_frame_tie() const
See set_frame_tie().
time_t get_start_time() const
Returns the time (and date) at which the current session was originally recorded (or, in recording mode, the time at which the current session began).
double get_clock_offset() const
Returns the delta offset between the actual frame time and the frame time written to the log...
RecorderBase * get_recorder(const string &name) const
Returns the recorder with the indicated name, or NULL if there is no such recorder.
bool is_playing() const
Returns true if the controller has been opened for input, false otherwise.