src/tools/tRecorderInternal.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 // declaration
00029 #ifndef     TRECORDERINTERNAL_H_INCLUDED
00030 #include    "tRecorderInternal.h"
00031 #endif
00032 
00033 #include    <ctype.h>
00034 
00035 #ifdef      HAVE_STDLIB
00036 #include    <stdlib.h>
00037 #endif
00038 
00039 #include    <fstream>
00040 
00041 #include    "tCommandLine.h"
00042 #include    "tConsole.h"
00043 #include    "tError.h"
00044 
00045 #undef  INLINE_DEF
00046 #define INLINE_DEF
00047 
00048 // static pointer to currently running recording
00049 // !todo: make this a context item
00050 tRecording * tRecording::currentRecording_ = 0;
00051 tPlayback * tPlayback::currentPlayback_ = 0;
00052 
00053 // ******************************************************************************************
00054 // *
00055 // * ~tRecording
00056 // *
00057 // ******************************************************************************************
00060 // ******************************************************************************************
00061 
00062 tRecording::~tRecording()
00063 {
00064     // clear current recording
00065     currentRecording_ = 0;
00066 }
00067 
00068 // ******************************************************************************************
00069 // *
00070 // *    tRecording
00071 // *
00072 // ******************************************************************************************
00075 // ******************************************************************************************
00076 
00077 tRecording::tRecording()
00078 {
00079     tASSERT( !currentRecording_ );
00080 
00081     std::cout << "Recording!\n";
00082 
00083     // set current recording
00084     currentRecording_ = this;
00085 }
00086 
00087 // ******************************************************************************************
00088 // *
00089 // * tRecording
00090 // *
00091 // ******************************************************************************************
00095 // ******************************************************************************************
00096 
00097 tRecording::tRecording( tRecording const & other )
00098 {
00099     tASSERT(false);
00100 }
00101 
00102 // ******************************************************************************************
00103 // *
00104 // *  operator =
00105 // *
00106 // ******************************************************************************************
00111 // ******************************************************************************************
00112 
00113 tRecording & tRecording::operator= ( tRecording const & other )
00114 {
00115     tASSERT(false);
00116 
00117     return *this;
00118 }
00119 
00120 // ******************************************************************************************
00121 // *
00122 // *    BeginSection
00123 // *
00124 // ******************************************************************************************
00128 // ******************************************************************************************
00129 
00130 void tRecording::BeginSection( char const * name )
00131 {
00132     DoGetStream() << "\n" << name;
00133 }
00134 
00135 // ******************************************************************************************
00136 // *
00137 // *    DoGetStream
00138 // *
00139 // ******************************************************************************************
00143 // ******************************************************************************************
00144 
00145 /*
00146 std::ostream & tRecording::DoGetStream( void ) const
00147 {
00148     tASSERT(0); // pure virtual
00149 
00150     return std::ostream();
00151 }
00152 */
00153 
00154 // ******************************************************************************************
00155 // *
00156 // * ~tPlayback
00157 // *
00158 // ******************************************************************************************
00161 // ******************************************************************************************
00162 
00163 tPlayback::~tPlayback()
00164 {
00165     // clear current Playback
00166     currentPlayback_ = 0;
00167 }
00168 
00169 // ******************************************************************************************
00170 // *
00171 // *    tPlayback
00172 // *
00173 // ******************************************************************************************
00176 // ******************************************************************************************
00177 
00178 tPlayback::tPlayback()
00179 {
00180     tASSERT( !currentPlayback_ );
00181 
00182     // set current Playback
00183     currentPlayback_ = this;
00184 }
00185 
00186 // ******************************************************************************************
00187 // *
00188 // * tPlayback
00189 // *
00190 // ******************************************************************************************
00194 // ******************************************************************************************
00195 
00196 tPlayback::tPlayback( tPlayback const & other )
00197 {
00198     tASSERT(false);
00199 }
00200 
00201 // ******************************************************************************************
00202 // *
00203 // *  operator =
00204 // *
00205 // ******************************************************************************************
00210 // ******************************************************************************************
00211 
00212 tPlayback & tPlayback::operator= ( tPlayback const & other )
00213 {
00214     tASSERT(false);
00215 
00216     return *this;
00217 }
00218 // ******************************************************************************************
00219 // *
00220 // *    GetNextSection
00221 // *
00222 // ******************************************************************************************
00226 // ******************************************************************************************
00227 
00228 const std::string & tPlayback::GetNextSection( void ) const
00229 {
00230     return nextSection_;
00231 }
00232 
00233 /*
00234 void EatWhite( std::istream & stream )
00235 {
00236     std::ws( stream );
00237     return;
00238 
00239     // eat whitespace (read to end of line)
00240     //int c= ' ';
00241     //while ( isblank(c) )
00242     //    c = stream.get();
00243     //if ( c != '\n' )
00244     //    stream.unget();
00245 }
00246 */
00247 
00248 // ******************************************************************************************
00249 // *
00250 // *    AdvanceSection
00251 // *
00252 // ******************************************************************************************
00255 // ******************************************************************************************
00256 
00257 void tPlayback::AdvanceSection( void )
00258 {
00259     std::istream& stream = DoGetStream();
00260 
00261     std::ws( stream );
00262     stream >> nextSection_;
00263     std::ws( stream );
00264 
00265     // memorize if end marking was seen
00266     static bool end = false;
00267     if ( nextSection_ == "END" )
00268         end = true;
00269 
00270     if ( !stream.good() )
00271     {
00272         if ( !end )
00273             con << "Recording ends abruptly here, prepare for a crash!\n";
00274 
00275         // stop playing back
00276         nextSection_ = "EOF";
00277         currentPlayback_ = NULL;
00278     }
00279 }
00280 
00281 class tRecordingCommandLineAnalyzer: public tCommandLineAnalyzer
00282 {
00283 private:
00284     virtual bool DoAnalyze( tCommandLineParser & parser )
00285     {
00286         tString filename;
00287         if ( parser.GetOption( filename, "--record" ) )
00288         {
00289             // start a recorder
00290             static tRecorderImp< tRecording, std::ofstream > recorder( static_cast< char const * >( filename ) );
00291             return true;
00292         }
00293 
00294         if ( parser.GetOption( filename, "--playback" ) )
00295         {
00296             // start a playback
00297             static tRecorderImp< tPlayback, std::ifstream > recorder( static_cast< char const * >( filename ) );
00298             recorder.InitPlayback();
00299             return true;
00300         }
00301 
00302         return false;
00303     }
00304 
00305     virtual void DoHelp( std::ostream & s )
00306     {                                      //
00307         s << "--record <filename>          : creates a DEBUG recording while running\n";
00308         s << "--playback <filename>        : plays back a DEBUG recording\n";
00309     }
00310 };
00311 
00312 static tRecordingCommandLineAnalyzer analyzer;

Generated on Sat Mar 15 22:56:01 2008 for Armagetron Advanced by  doxygen 1.5.4