Panda3D
|
00001 // Filename: recorderController.I 00002 // Created by: drose (24Jan04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: RecorderController::get_start_time 00018 // Access: Published 00019 // Description: Returns the time (and date) at which the current 00020 // session was originally recorded (or, in recording 00021 // mode, the time at which the current session began). 00022 //////////////////////////////////////////////////////////////////// 00023 INLINE time_t RecorderController:: 00024 get_start_time() const { 00025 return _header._start_time; 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: RecorderController::set_random_seed 00030 // Access: Published 00031 // Description: Indicates an arbitrary number to be recorded in the 00032 // session file as a random seed, should the application 00033 // wish to take advantage of it. This must be set 00034 // before begin_record() is called. 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE void RecorderController:: 00037 set_random_seed(int random_seed) { 00038 _header._random_seed = random_seed; 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: RecorderController::get_random_seed 00043 // Access: Published 00044 // Description: Returns the random seed that was set by a previous 00045 // call to set_random_seed(), or the number read from 00046 // the session file after begin_playback() has been 00047 // called. 00048 //////////////////////////////////////////////////////////////////// 00049 INLINE int RecorderController:: 00050 get_random_seed() const { 00051 return _header._random_seed; 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: RecorderController::is_recording 00056 // Access: Published 00057 // Description: Returns true if the controller has been opened for 00058 // output, false otherwise. 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE bool RecorderController:: 00061 is_recording() const { 00062 return (_writer != (BamWriter *)NULL); 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: RecorderController::is_playing 00067 // Access: Published 00068 // Description: Returns true if the controller has been opened for 00069 // input, false otherwise. 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE bool RecorderController:: 00072 is_playing() const { 00073 return (_reader != (BamReader *)NULL); 00074 } 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: RecorderController::is_open 00078 // Access: Published 00079 // Description: Returns true if the controller has been opened for 00080 // either input or output, false otherwise. 00081 //////////////////////////////////////////////////////////////////// 00082 INLINE bool RecorderController:: 00083 is_open() const { 00084 return is_recording() || is_playing(); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: RecorderController::get_filename 00089 // Access: Published 00090 // Description: Returns the filename that was passed to the most 00091 // recent call to begin_record() or begin_playback(). 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE const Filename &RecorderController:: 00094 get_filename() const { 00095 return _filename; 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: RecorderController::is_error 00100 // Access: Published 00101 // Description: Returns true if the controller has been opened for 00102 // input or output output and there is an error on the 00103 // stream, or false if the controller is closed or if 00104 // there is no problem. 00105 //////////////////////////////////////////////////////////////////// 00106 INLINE bool RecorderController:: 00107 is_error() { 00108 return _dout.is_error() || _din.is_error(); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: RecorderController::get_clock_offset 00113 // Access: Published 00114 // Description: Returns the delta offset between the actual frame 00115 // time and the frame time written to the log. This is 00116 // essentially the time at which the recording (or 00117 // playback) started. 00118 //////////////////////////////////////////////////////////////////// 00119 INLINE double RecorderController:: 00120 get_clock_offset() const { 00121 return _clock_offset; 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: RecorderController::get_frame_offset 00126 // Access: Published 00127 // Description: Returns the delta offset between the actual frame 00128 // count and the frame count written to the log. This is 00129 // essentially the frame number at which the recording 00130 // (or playback) started. 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE int RecorderController:: 00133 get_frame_offset() const { 00134 return _frame_offset; 00135 } 00136 00137 00138 //////////////////////////////////////////////////////////////////// 00139 // Function: RecorderController::add_recorder 00140 // Access: Published 00141 // Description: Adds the named recorder to the set of recorders that 00142 // are in use. 00143 // 00144 // If the controller is in recording mode, the named 00145 // recorder will begin recording its status to the 00146 // session file. If the controller is in playback mode 00147 // and the name and type matches a recorder in the 00148 // session file, the recorder will begin receiving data. 00149 //////////////////////////////////////////////////////////////////// 00150 INLINE void RecorderController:: 00151 add_recorder(const string &name, RecorderBase *recorder) { 00152 _user_table->add_recorder(name, recorder); 00153 _user_table_modified = true; 00154 00155 // We can only add the state flag immediately if we are in recording 00156 // mode. In playback mode, we're not sure yet whether the new 00157 // recorder state will actually be playing (we won't know until we 00158 // merge the tables in play_frame()). 00159 if (is_recording()) { 00160 recorder->_flags |= RecorderBase::F_recording; 00161 } 00162 } 00163 00164 //////////////////////////////////////////////////////////////////// 00165 // Function: RecorderController::has_recorder 00166 // Access: Published 00167 // Description: Returns true if the named recorder has been added to 00168 // the table by a previous call to add_recorder(), false 00169 // otherwise. 00170 // 00171 // If the controller is in playback mode, this will also 00172 // return false for a recorder that was found in the 00173 // session file but was never explicitly added via 00174 // add_recorder(); see get_recorder(). 00175 //////////////////////////////////////////////////////////////////// 00176 INLINE bool RecorderController:: 00177 has_recorder(const string &name) const { 00178 return (_user_table->get_recorder(name) != (RecorderBase *)NULL); 00179 } 00180 00181 //////////////////////////////////////////////////////////////////// 00182 // Function: RecorderController::get_recorder 00183 // Access: Published 00184 // Description: Returns the recorder with the indicated name, or NULL 00185 // if there is no such recorder. 00186 // 00187 // If the controller is in playback mode, this may 00188 // return the recorder matching the indicated name as 00189 // read from the session file, even if it was never 00190 // added to the table by the user. In this case, 00191 // has_recorder() may return false, but get_recorder() 00192 // will return a non-NULL value. 00193 //////////////////////////////////////////////////////////////////// 00194 INLINE RecorderBase *RecorderController:: 00195 get_recorder(const string &name) const { 00196 RecorderBase *recorder = _user_table->get_recorder(name); 00197 if (is_playing() && recorder == (RecorderBase *)NULL) { 00198 recorder = _active_table->get_recorder(name); 00199 } 00200 return recorder; 00201 } 00202 00203 //////////////////////////////////////////////////////////////////// 00204 // Function: RecorderController::remove_recorder 00205 // Access: Published 00206 // Description: Removes the named recorder from the table. Returns 00207 // true if successful, false if there was no such 00208 // recorder. 00209 // 00210 // If the controller is in recording mode, the named 00211 // recorder will stop recording. If the controller is 00212 // in playback mode, the named recorder will 00213 // disassociate itself from the session file (but if the 00214 // session file still has data for this name, a default 00215 // recorder will take its place to decode the data from 00216 // the session file). 00217 //////////////////////////////////////////////////////////////////// 00218 INLINE bool RecorderController:: 00219 remove_recorder(const string &name) { 00220 // If we are playing or recording, immediately remove the state flag 00221 // from the recorder. (When we are playing, the state flag will get 00222 // removed automatically at the next call to play_frame(), but we 00223 // might as well be aggressive and remove it now. When we are 00224 // recording, we have to remove it now.) 00225 if (is_recording() || is_playing()) { 00226 RecorderBase *recorder = _user_table->get_recorder(name); 00227 if (recorder != (RecorderBase *)NULL) { 00228 recorder->_flags &= ~(RecorderBase::F_recording | RecorderBase::F_playing); 00229 } 00230 } 00231 _user_table_modified = true; 00232 return _user_table->remove_recorder(name); 00233 } 00234 00235 //////////////////////////////////////////////////////////////////// 00236 // Function: RecorderController::set_frame_tie 00237 // Access: Published 00238 // Description: Sets the frame_tie flag. 00239 // 00240 // When this is true, sessions are played back 00241 // frame-for-frame, based on the frame count of the 00242 // recorded session. This gives the most accurate 00243 // playback, but the playback rate will vary according 00244 // to the frame rate of the playback machine. 00245 // 00246 // When this is false, sessions are played back at real 00247 // time, based on the clock of the recorded session. 00248 // This may introduce playback discrepencies if the 00249 // frames do not fall at exactly the same times as they 00250 // did in the original. 00251 //////////////////////////////////////////////////////////////////// 00252 INLINE void RecorderController:: 00253 set_frame_tie(bool frame_tie) { 00254 _frame_tie = frame_tie; 00255 } 00256 00257 //////////////////////////////////////////////////////////////////// 00258 // Function: RecorderController::get_frame_tie 00259 // Access: Published 00260 // Description: See set_frame_tie(). 00261 //////////////////////////////////////////////////////////////////// 00262 INLINE bool RecorderController:: 00263 get_frame_tie() const { 00264 return _frame_tie; 00265 } 00266 00267 //////////////////////////////////////////////////////////////////// 00268 // Function: RecorderController::get_factory 00269 // Access: Public, Static 00270 // Description: Returns the global RecorderFactory for generating 00271 // TypedWritable objects 00272 //////////////////////////////////////////////////////////////////// 00273 INLINE RecorderController::RecorderFactory *RecorderController:: 00274 get_factory() { 00275 if (_factory == (RecorderFactory *)NULL) { 00276 create_factory(); 00277 } 00278 return _factory; 00279 } 00280 00281 //////////////////////////////////////////////////////////////////// 00282 // Function: RecorderController::create_factory 00283 // Access: Private, Static 00284 // Description: Creates a new RecorderFactory for generating 00285 // TypedWritable objects 00286 //////////////////////////////////////////////////////////////////// 00287 INLINE void RecorderController:: 00288 create_factory() { 00289 _factory = new RecorderFactory; 00290 }