/*****************************************************************************
 * $LastChangedDate: 2011-02-04 19:23:35 -0500 (Fri, 04 Feb 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Replay animation of an Aircraft (record-mode implementation of Replay class).
 *//*
 * LEGAL:   COPYRIGHT (C) 2008 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef CONTROL_REPLAY_RECORDER_HH
#define CONTROL_REPLAY_RECORDER_HH 1

#include "control/command.hh"
#include "control/events.hh"
#include "control/replay_path.hh"

namespace control {

////////////////////////////////////////////////////////////////////////////////
/// @brief Replay animation of an Aircraft (record-mode implementation of Replay class).
///
/// Recording:
/// ----------
/// Recording is mostly done by listening to Commands being broadcast,
/// but supplemented by polling by a timer-tick for Commands which aren't.
///
class ReplayRecorder : public Shared
{
PREVENT_COPYING(ReplayRecorder)
private:
    CLASS_CONST int INVALID_TIME = -1;

// Public interface:
public:
                        ReplayRecorder( shptr<Aircraft> aircraft,
                                        const Milliseconds freq );
                        ~ReplayRecorder();
    bool                Start( void );
    void                Stop( void );
    void                Clear( void );
    bool                Save( const string& filename );

// Internal to Replay classes:
public:
    shptr<ReplayPath>   GetPath( void ) { return mPath; }
    bool                IfHaveRecording( void ) const { return not mPath->empty(); }

private:
    void                Register( void );
    void                Unregister( void );

private:
    /// @brief Timer-tick to animate replay.
    CLASS_TICK_FUNCTOR( ReplayRecorder, mRecorder )

private:
    /// @brief Listens for control commands from Aircraft.
    CLASS_EVENT_LISTENER( CommandListener, CommandEvent, ReplayRecorder, mRecorder )

private:
    shptr<Aircraft>             mAircraft;              ///< aircraft to replay
    const Milliseconds          mFreq;                  ///< freq of timer-tick
    bool                        mRegistered;            ///< if listeners/functors are currently registered
    shptr<TickFunctor>          mTickFunctor;           ///< pulse for play mode
    shptr<CommandListener>      mCommandListener;       ///< listens for a Command from current Craft
    shptr<ReplayPath>           mPath;                  ///< replay data consists of steps in animation path
    Milliseconds                mStartTime;             ///< time when recording began
};

} // namespace control

#endif // CONTROL_REPLAY_RECORDER_HH
