Panda3D
|
00001 // Filename: recorderController.h 00002 // Created by: drose (25Jan04) 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 #ifndef RECORDERCONTROLLER_H 00016 #define RECORDERCONTROLLER_H 00017 00018 #include "pandabase.h" 00019 #include "datagramOutputFile.h" 00020 #include "datagramInputFile.h" 00021 #include "recorderTable.h" 00022 #include "recorderHeader.h" 00023 #include "typedReferenceCount.h" 00024 #include "factory.h" 00025 00026 class RecorderBase; 00027 class RecorderFrame; 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Class : RecorderController 00031 // Description : This object manages the process of recording the 00032 // user's runtime inputs to a bam file so that the 00033 // session can be recreated later. 00034 //////////////////////////////////////////////////////////////////// 00035 class EXPCL_PANDA_RECORDER RecorderController : public TypedReferenceCount { 00036 PUBLISHED: 00037 RecorderController(); 00038 ~RecorderController(); 00039 00040 bool begin_record(const Filename &filename); 00041 bool begin_playback(const Filename &filename); 00042 void close(); 00043 00044 INLINE time_t get_start_time() const; 00045 00046 INLINE void set_random_seed(int random_seed); 00047 INLINE int get_random_seed() const; 00048 00049 INLINE bool is_recording() const; 00050 INLINE bool is_playing() const; 00051 INLINE bool is_open() const; 00052 INLINE const Filename &get_filename() const; 00053 00054 INLINE bool is_error(); 00055 INLINE double get_clock_offset() const; 00056 INLINE int get_frame_offset() const; 00057 00058 INLINE void add_recorder(const string &name, RecorderBase *recorder); 00059 INLINE bool has_recorder(const string &name) const; 00060 INLINE RecorderBase *get_recorder(const string &name) const; 00061 INLINE bool remove_recorder(const string &name); 00062 00063 INLINE void set_frame_tie(bool frame_tie); 00064 INLINE bool get_frame_tie() const; 00065 00066 void record_frame(); 00067 void play_frame(); 00068 00069 public: 00070 typedef Factory<RecorderBase> RecorderFactory; 00071 00072 INLINE static RecorderFactory *get_factory(); 00073 00074 private: 00075 INLINE static void create_factory(); 00076 RecorderFrame *read_frame(); 00077 00078 private: 00079 RecorderHeader _header; 00080 double _clock_offset; 00081 int _frame_offset; 00082 00083 Filename _filename; 00084 DatagramOutputFile _dout; 00085 DatagramInputFile _din; 00086 BamWriter *_writer; 00087 BamReader *_reader; 00088 bool _frame_tie; 00089 00090 // _user_table is directly modified by the user. 00091 RecorderTable *_user_table; 00092 bool _user_table_modified; 00093 00094 // In playback mode, _file_table represents the table as read 00095 // directly from the session file, with default recorders in each 00096 // slot. 00097 RecorderTable *_file_table; 00098 00099 // In playback mode, _active_table is the result of the merge of 00100 // _file_table and _user_table, with a default recorder or a 00101 // user-specified recorder in each active slot. 00102 RecorderTable *_active_table; 00103 00104 RecorderFrame *_next_frame; 00105 bool _eof; 00106 00107 static RecorderFactory *_factory; 00108 00109 public: 00110 static TypeHandle get_class_type() { 00111 return _type_handle; 00112 } 00113 static void init_type() { 00114 TypedReferenceCount::init_type(); 00115 register_type(_type_handle, "RecorderController", 00116 TypedReferenceCount::get_class_type()); 00117 } 00118 virtual TypeHandle get_type() const { 00119 return get_class_type(); 00120 } 00121 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00122 00123 private: 00124 static TypeHandle _type_handle; 00125 00126 friend class RecorderFrame; 00127 }; 00128 00129 #include "recorderController.I" 00130 00131 #endif 00132