/*****************************************************************************
 * $LastChangedDate: 2011-02-04 21:32:44 -0500 (Fri, 04 Feb 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Replay animation of an Aircraft (play 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_PLAYER_HH
#define CONTROL_REPLAY_PLAYER_HH 1

#include "control/replay_path.hh"

namespace control {

////////////////////////////////////////////////////////////////////////////////
/// @brief Replay animation of an Aircraft (play mode implementation of Replay class).
///
class ReplayPlayer : public Shared
{
PREVENT_COPYING(ReplayPlayer)
private:
    CLASS_CONST Milliseconds::Int INVALID_TIME = -1;

public:
                    ReplayPlayer( shptr<Aircraft> aircraft,
                                  const Milliseconds freq,
                                  const Command::ExecuteMode commandExecuteMode );
                    ~ReplayPlayer();
    bool            Start( void );
    void            Stop( void );
    bool            IfPlaying( void );
    bool            Load( const string& filename );
    void            UseRecording( shptr<ReplayRecorder> recorder );

private:
    void            Register( void );
    void            Unregister( void );
    void            Tick( const Milliseconds elapsedTime );
    void            TryInterpolatingPositions( void );
    void            TryInterpolatingQuaternions( void );
    fp              ComputeInterpolationFraction( const ReplayPath::Step& prevStep,
                                                  const ReplayPath::Step& nextStep );
    void            DisableJoystickIfPlayer( void );
    void            RestoreJoystickIfPlayer( void );

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

private:
    shptr<Aircraft>             mAircraft;              ///< Aircraft to replay
    const Milliseconds          mFreq;                  ///< freq of timer-tick
    const Command::ExecuteMode  mCommandExecuteMode;    ///< graphical or physical replay
    bool                        mRegistered;            ///< if listeners/functors are currently registered
    shptr<TickFunctor>          mTickFunctor;           ///< pulse for play mode
    shptr<ReplayPath>           mPath;                  ///< replay data consists of steps in animation path
    Milliseconds                mStartTime;             ///< time when playing began
    bool                        mPlaying;
    bool                        mJoystickEnabled;       ///< joystick might be disabled during replay
};

} // namespace control

#endif // CONTROL_REPLAY_PLAYER_HH
