Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Protected Attributes
History Class Reference

#include <history.hpp>

List of all members.

Public Member Functions

 History ()
int GetCount ()
int GetCurrentIndex ()
int GetSize ()
void SetSize (int n)
void StoreDelta (float delta)
void Save ()
void Load ()
void LoadKartData (Kart *k, int kartNumber)
float GetNextDelta ()

Protected Attributes

int m_size
int m_current
bool m_wrapped
FILE * m_fd
float * m_all_deltas

Detailed Description

Definition at line 28 of file history.hpp.


Constructor & Destructor Documentation

History::History ( ) [inline]

Definition at line 39 of file history.hpp.

Here is the call graph for this function:


Member Function Documentation

int History::GetCount ( ) [inline]

Definition at line 40 of file history.hpp.

{ return m_wrapped ? m_size : m_current+1; }

Here is the caller graph for this function:

int History::GetCurrentIndex ( ) [inline]

Definition at line 41 of file history.hpp.

{ return m_current;}

Here is the caller graph for this function:

Definition at line 49 of file history.cpp.

{
    m_current++;
    if(m_current>=m_size)
    {
        fprintf(stderr,"History: finished.\n");
        exit(-3);
    }
    return m_all_deltas[m_current];
}   // GetNextDT

Here is the caller graph for this function:

int History::GetSize ( ) [inline]

Definition at line 42 of file history.hpp.

{ return m_size;  }

Here is the caller graph for this function:

void History::Load ( )

Definition at line 104 of file history.cpp.

{
    char s[1024], s1[1024];
    int  n, numKarts;
    m_fd = fopen("history.dat","r");

    fgets(s, 1023, m_fd);
    if(sscanf(s,"Version: %s",s1)!=1)
    {
        fprintf(stderr, "WARNING: no Version information found in history file.\n");
        exit(-2);
    }
#ifdef VERSION
    if(strcmp(s1,VERSION))
    {
        fprintf(stderr, "WARNING: history is version '%s'\n",s1);
        fprintf(stderr, "         tuxracer version is '%s'\n",VERSION);
    }
#endif
    fgets(s, 1023, m_fd);
    if(sscanf(s, "numkarts: %d",&numKarts)!=1)
    {
        fprintf(stderr,"WARNING: No number of karts found in history file.\n");
        exit(-2);
    }
    race_manager->setNumKarts(numKarts);

    fgets(s, 1023, m_fd);
    if(sscanf(s, "numplayers: %d",&n)!=1)
    {
        fprintf(stderr,"WARNING: No number of players found in history file.\n");
        exit(-2);
    }
    race_manager->setNumPlayers(n);

    fgets(s, 1023, m_fd);
    if(sscanf(s, "difficulty: %d",&n)!=1)
    {
        fprintf(stderr,"WARNING: No difficulty found in history file.\n");
        exit(-2);
    }
    race_manager->setDifficulty((RaceManager::Difficulty)n);

    fgets(s, 1023, m_fd);
    if(sscanf(s, "track: %s",s1)!=1)
    {
        fprintf(stderr,"WARNING: Track not found in history file.\n");
    }
    race_manager->setTrack(s1);
    // This value doesn't really matter, but should be defined, otherwise
    // the racing phase can switch to 'ending'
    race_manager->setNumLaps(10);

    for(int i=0; i<numKarts; i++)
    {
        fgets(s, 1023, m_fd);
        if(sscanf(s, "model %d: %s",&n, s1)!=2)
        {
            fprintf(stderr,"WARNING: No model information for kart %d found.\n",
                    i);
            exit(-2);
        }
    }   // for i<nKarts
    // JH: The model information is currently ignored
    fgets(s, 1023, m_fd);
    if(sscanf(s,"size: %d",&n)!=1)
    {
        fprintf(stderr,"WARNING: Number of records not found in history file.\n");
        exit(-2);
    }
    SetSize(n);
    for(int i=0; i<m_size; i++)
    {
        fgets(s, 1023, m_fd);
        sscanf(s, "delta: %f\n",m_all_deltas+i);
    }
    m_current = -1;
}   // Load

Here is the call graph for this function:

Here is the caller graph for this function:

void History::LoadKartData ( Kart k,
int  kartNumber 
)

Definition at line 184 of file history.cpp.

{
    char s[1024];
    for(int i=0; i<m_size; i++)
    {
        fgets(s, 1023, m_fd);
        k->ReadHistory(s, kartNumber, i);
    }   // for i<m_current
}   // LoadKartData

Here is the call graph for this function:

Here is the caller graph for this function:

void History::Save ( )

Definition at line 61 of file history.cpp.

{
    FILE *fd = fopen("history.dat","w");
    int  nKarts = race_manager->getNumKarts();
#ifdef VERSION
    fprintf(fd, "Version:  %s\n",   VERSION);
#endif
    fprintf(fd, "numkarts: %d\n",   nKarts);
    fprintf(fd, "numplayers: %d\n", race_manager->getNumPlayers());
    fprintf(fd, "difficulty: %d\n", race_manager->getDifficulty());
    fprintf(fd, "track: %s\n",      world->getTrack()->getIdent().c_str());

    int k;
    for(k=0; k<nKarts; k++)
    {
        fprintf(fd, "model %d: %s\n",k, world->getKart(k)->getName().c_str());
    }
    fprintf(fd, "size:     %d\n", GetCount());

    int j = m_wrapped ? m_current : 0;
    for(int i=0; i<GetCount(); i++)
    {
        fprintf(fd, "delta: %f\n",m_all_deltas[i]);
        j=(j+1)%m_size;
    }

    for(int k=0; k<nKarts; k++)
    {
        Kart* kart= world->getKart(k);
        char s[1024];
        j = m_wrapped ? m_current : 0;
        for(int i=0; i<GetCount(); i++)
        {
            kart->WriteHistory(s, k, j);
            fprintf(fd, "%s\n",s);
            j=(j+1)%m_size;
        }   // for i
    }   // for k
    fprintf(fd, "History file end.\n");
    fclose(fd);
}   // Save

Here is the call graph for this function:

Here is the caller graph for this function:

void History::SetSize ( int  n)

Definition at line 28 of file history.cpp.

{
    m_size      = n;
    m_all_deltas  = new float[m_size];
    m_current    = -1;
    m_wrapped    = false;
}   // History

Here is the caller graph for this function:

void History::StoreDelta ( float  delta)

Definition at line 37 of file history.cpp.

{
    this->m_current++;
    if(m_current>=m_size)
    {
        m_wrapped = true;
        m_current = 0;
    }
    m_all_deltas[m_current] = delta;
}   // StoreDT

Here is the caller graph for this function:


Member Data Documentation

float* History::m_all_deltas [protected]

Definition at line 37 of file history.hpp.

int History::m_current [protected]

Definition at line 33 of file history.hpp.

FILE* History::m_fd [protected]

Definition at line 35 of file history.hpp.

int History::m_size [protected]

Definition at line 32 of file history.hpp.

bool History::m_wrapped [protected]

Definition at line 34 of file history.hpp.


The documentation for this class was generated from the following files: