15 #include "recorderController.h"
16 #include "recorderFrame.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 #include "config_recorder.h"
21 #include "clockObject.h"
32 RecorderController() {
39 _user_table_modified =
false;
51 ~RecorderController() {
71 time(&_header._start_time);
73 if (!_dout.
open(_filename)) {
74 recorder_cat.error() <<
"Unable to open " << _filename <<
"\n";
79 recorder_cat.error() <<
"Unable to write to " << _filename <<
"\n";
85 if (!_writer->
init()) {
93 _user_table_modified =
true;
96 _user_table->
set_flags(RecorderBase::F_recording);
99 <<
"Recording session to " << _filename <<
"\n";
118 _filename = filename;
123 if (!_din.
open(_filename)) {
124 recorder_cat.error() <<
"Unable to open " << _filename <<
"\n";
129 if (!_din.
read_header(head, _bam_header.size()) || head != _bam_header) {
130 recorder_cat.error() <<
"Unable to read " << _filename <<
"\n";
135 if (!_reader->
init()) {
140 _user_table_modified =
true;
148 !object->
is_of_type(RecorderHeader::get_class_type())) {
150 << _filename <<
" does not contain a recorded session.\n";
156 recorder_cat.warning()
157 <<
"Unable to resolve header data.\n";
161 _header = (*new_header);
165 _next_frame = read_frame();
168 << _filename <<
" does not contain any frames.\n";
174 <<
"Playing back session from " << _filename <<
"\n";
191 _user_table->
clear_flags(RecorderBase::F_recording);
198 _active_table->
clear_flags(RecorderBase::F_playing);
209 delete _active_table;
227 RecorderFrame data(now, frame, _user_table_modified, _user_table);
228 _user_table_modified =
false;
254 if (frame < _next_frame->_frame) {
265 _clock_offset = global_clock->
get_frame_time() - _next_frame->_timestamp;
268 if (now < _next_frame->_timestamp) {
277 if (_next_frame->_table_changed && _file_table != _next_frame->_table) {
279 _file_table = _next_frame->_table;
282 if (_next_frame->_table_changed || _user_table_modified) {
285 _active_table->
clear_flags(RecorderBase::F_playing);
286 delete _active_table;
289 _user_table_modified =
false;
293 _active_table->
set_flags(RecorderBase::F_playing);
296 _next_frame->_table = _active_table;
300 _next_frame = read_frame();
305 <<
"End of recorded session.\n";
308 <<
"Unable to read datagram from recorded session.\n";
327 !object->
is_of_type(RecorderFrame::get_class_type())) {
332 recorder_cat.warning()
333 <<
"Unable to resolve frame data.\n";
bool is_recording() const
Returns true if the controller has been opened for output, false otherwise.
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
bool begin_playback(const Filename &filename)
Begins playing back data from the indicated filename.
bool is_eof() const
Returns true if the reader has reached end-of-file, false otherwise.
A Factory can be used to create an instance of a particular subclass of some general base class...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool resolve()
This may be called at any time during processing of the Bam file to resolve all the known pointers so...
TypedWritable * read_object()
Reads a single object from the Bam file.
Base class for objects that can be written to and read from Bam files.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
bool write_header(const string &header)
Writes a sequence of bytes to the beginning of the datagram file.
void close()
Finishes recording data to the indicated filename.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
bool open(const FileReference *file)
Opens the indicated filename for writing.
bool is_playing() const
Returns true if the controller has been opened for input, false otherwise.
void record_frame()
Gets the next frame of data from all of the active recorders and adds it to the output file...
void play_frame(BamReader *manager)
Once the raw data has been read in from the session file, and the table has been decoded, decode the raw data and call play_frame on each recorder.
bool init()
Initializes the BamReader prior to reading any objects from its source.
This object is used by the RecorderController to write (and read) a record of the set of recorders in...
The name of a file, such as a texture file or an Egg file.
double get_frame_time(Thread *current_thread=Thread::get_current_thread()) const
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
A ClockObject keeps track of elapsed real time and discrete time.
int get_frame_count(Thread *current_thread=Thread::get_current_thread()) const
Returns the number of times tick() has been called since the ClockObject was created, or since it was last reset.
bool write_object(const TypedWritable *obj)
Writes a single object to the Bam file, so that the BamReader::read_object() can later correctly rest...
void clear_flags(short flags)
Clears the given flags on all recorders.
void merge_from(const RecorderTable &other)
Combines the data in the current table (presumably just read from disk, and matching exactly with the...
bool begin_record(const Filename &filename)
Begins recording data to the indicated filename.
This object represents one frame of data in the recorded session file.
void play_frame()
Gets the next frame of data from all of the active recorders and adds it to the output file...
TypeHandle is the identifier used to differentiate C++ class types.
void set_flags(short flags)
Sets the given flags on all recorders.
void close()
Closes the file.
bool init()
Initializes the BamWriter prior to writing any objects to its output stream.