Back to index

supertuxkart  0.5+dfsg1
replay_buffers.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_REPLAYBUFFERS_H
00021 #define HEADER_REPLAYBUFFERS_H
00022 
00023 #ifdef HAVE_GHOST_REPLAY
00024 
00025 
00026 #include <cstdio>
00027 
00028 #include "replay_buffer_tpl.hpp"
00029 
00030 struct ReplayKartState;
00031 struct ReplayFrame;
00032 
00033 
00034 // the worker-class .. administrates the memory-usage with no copy of 
00035 // previous replay-items when reallocation needed if buffers are full
00036 class ReplayBuffers
00037 {
00038 public:
00039 
00040     ReplayBuffers();
00041     ~ReplayBuffers();
00042 
00043     bool                init( unsigned int number_karts, 
00044                               size_t number_preallocated_frames );
00045     void                destroy();
00046 
00047     // returns a new *free* frame to be used to store the current frame-data into it
00048     // used to *record* the replay
00049     ReplayFrame*        getNewFrame();
00050 
00051     // returs frame at given position from replay data
00052     // used to *show* the replay
00053     // if frame_index >= num_frames -> returns NULL
00054     ReplayFrame const*  getFrameAt( size_t frame_index ) const  { return m_BufferFrame.getObjectAt( frame_index ); }
00055 
00056     size_t              getNumberFrames() const                 { return m_BufferFrame.getNumberObjectsUsed(); }
00057     unsigned int        getNumberKarts() const                  { return m_number_karts; }
00058 
00059     bool                saveReplayHumanReadable( FILE *fd ) const;
00060     bool                loadReplayHumanReadable( FILE *fd, unsigned int number_karts );
00061 
00062 private:
00063     bool                isHealthy() const                       { return m_BufferFrame.isHealthy() && m_BufferKartState.isHealthy(); }
00064 
00065 private:
00066     typedef ReplayBuffer<ReplayFrame>           BufferFrame;
00067     typedef ReplayBufferArray<ReplayKartState>  BufferKartState;
00068 
00069     unsigned int        m_number_karts;
00070     BufferFrame         m_BufferFrame;
00071     BufferKartState     m_BufferKartState;
00072 };
00073 
00074 
00075 #endif // HAVE_GHOST_REPLAY
00076 
00077 #endif // HEADER_REPLAYBUFFERS_H
00078