3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
29
#ifndef TRECORDERINTERNAL_H_INCLUDED
30
#include "tRecorderInternal.h"
41
#include "tCommandLine.h"
47
// static pointer to currently running recording
48
// !todo: make this a context item
49
tRecording * tRecording::currentRecording_ = 0;
50
tPlayback * tPlayback::currentPlayback_ = 0;
52
// ******************************************************************************************
56
// ******************************************************************************************
59
// ******************************************************************************************
61
tRecording::~tRecording()
63
// clear current recording
64
currentRecording_ = 0;
67
// ******************************************************************************************
71
// ******************************************************************************************
74
// ******************************************************************************************
76
tRecording::tRecording()
78
tASSERT( !currentRecording_ );
80
std::cout << "Recording!\n";
82
// set current recording
83
currentRecording_ = this;
86
// ******************************************************************************************
90
// ******************************************************************************************
92
//! @param other the source to copy from
94
// ******************************************************************************************
96
tRecording::tRecording( tRecording const & other )
101
// ******************************************************************************************
105
// ******************************************************************************************
107
//! @param other the source to copy from
108
//! @return a reference to this
110
// ******************************************************************************************
112
tRecording & tRecording::operator= ( tRecording const & other )
119
// ******************************************************************************************
123
// ******************************************************************************************
125
//! @param name the name of the new section
127
// ******************************************************************************************
129
void tRecording::BeginSection( char const * name )
131
DoGetStream() << "\n" << name;
134
// ******************************************************************************************
138
// ******************************************************************************************
140
//! @return the stream to write to
142
// ******************************************************************************************
145
std::ostream & tRecording::DoGetStream( void ) const
147
tASSERT(0); // pure virtual
149
return std::ostream();
153
// ******************************************************************************************
157
// ******************************************************************************************
160
// ******************************************************************************************
162
tPlayback::~tPlayback()
164
// clear current Playback
165
currentPlayback_ = 0;
168
// ******************************************************************************************
172
// ******************************************************************************************
175
// ******************************************************************************************
177
tPlayback::tPlayback()
179
tASSERT( !currentPlayback_ );
181
// set current Playback
182
currentPlayback_ = this;
185
// ******************************************************************************************
189
// ******************************************************************************************
191
//! @param other the source to copy from
193
// ******************************************************************************************
195
tPlayback::tPlayback( tPlayback const & other )
200
// ******************************************************************************************
204
// ******************************************************************************************
206
//! @param other the source to copy from
207
//! @return a reference to this
209
// ******************************************************************************************
211
tPlayback & tPlayback::operator= ( tPlayback const & other )
217
// ******************************************************************************************
221
// ******************************************************************************************
223
//! @return the name of the next section
225
// ******************************************************************************************
227
const std::string & tPlayback::GetNextSection( void ) const
233
void EatWhite( std::istream & stream )
238
// eat whitespace (read to end of line)
240
//while ( isblank(c) )
247
// ******************************************************************************************
251
// ******************************************************************************************
254
// ******************************************************************************************
256
void tPlayback::AdvanceSection( void )
258
std::istream& stream = DoGetStream();
261
stream >> nextSection_;
264
// memorize if end marking was seen
265
static bool end = false;
266
if ( nextSection_ == "END" )
269
if ( !stream.good() )
272
con << "Recording ends abruptly here, prepare for a crash!\n";
275
nextSection_ = "EOF";
276
currentPlayback_ = NULL;
280
class tRecordingCommandLineAnalyzer: public tCommandLineAnalyzer
283
virtual bool DoAnalyze( tCommandLineParser & parser )
286
if ( parser.GetOption( filename, "--record" ) )
289
static tRecorderImp< tRecording, std::ofstream > recorder( static_cast< char const * >( filename ) );
293
if ( parser.GetOption( filename, "--playback" ) )
296
static tRecorderImp< tPlayback, std::ifstream > recorder( static_cast< char const * >( filename ) );
297
recorder.InitPlayback();
304
virtual void DoHelp( std::ostream & s )
306
s << "--record <filename> : creates a DEBUG recording while running\n";
307
s << "--playback <filename> : plays back a DEBUG recording\n";
311
static tRecordingCommandLineAnalyzer analyzer;