Back to index

supertuxkart  0.5+dfsg1
replay_player.hpp
Go to the documentation of this file.
00001 //  $Id$
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2007 Maik Semder <ikework@gmx.de>
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #ifndef HEADER_REPLAYPLAYER_H
00021 #define HEADER_REPLAYPLAYER_H
00022 
00023 #ifdef HAVE_GHOST_REPLAY
00024 
00025 #include <vector>
00026 #include <plib/ssg.h>
00027 
00028 #include "replay_base.hpp"
00029 
00030 
00031 class KartProperties;
00032 class ReplayKart
00033 {
00034 public:
00035     ReplayKart();
00036     ~ReplayKart();
00037 
00038     ReplayKart( ReplayKart const &kart ) { *this = kart; }
00039     ReplayKart& operator=( ReplayKart const &kart ) 
00040     {
00041         assert( this != &kart );
00042         m_kart_properties = kart.m_kart_properties;
00043         m_model = kart.m_model;
00044         sgCopyCoord ( &m_position, &kart.m_position );
00045         return *this;
00046     }
00047     bool                init( const std::string &strKartIdent );
00048     void                destroy();
00049 
00050     ssgTransform*       getModel() { return m_model; }
00051 
00052     void                setPosition( const sgCoord &pos ) { sgCopyCoord ( &m_position, &pos ); m_model->setTransform(&m_position); }
00053 
00054 private:
00055     const KartProperties    *m_kart_properties;
00056     sgCoord                 m_position;
00057     ssgTransform            *m_model;
00058 };
00059 
00060 // class managing:
00061 //      - the loading of replay-file
00062 //      - the rendering of the replay (interpolation if needed)
00063 class ReplayPlayer : public ReplayBase
00064 {
00065 public:
00066     ReplayPlayer();
00067     virtual ~ReplayPlayer();
00068 
00069     void            destroy();
00070 
00071     bool            loadReplayHumanReadable( FILE *fd );
00072 
00073     // calc state of replay-objects at given time
00074     void            showReplayAt( float abs_time );
00075 
00076     void            reset()                         { m_current_frame_index = 0; }
00077 
00078 private:
00079     typedef std::vector<ReplayKart>    ReplayKarts;
00080 
00081     int                    m_current_frame_index;
00082     ReplayKarts            m_Karts;
00083 };
00084 
00085 
00086 #endif // HAVE_GHOST_REPLAY
00087 
00088 #endif // HEADER_REPLAYPLAYER_H
00089