Back to index

supertuxkart  0.5+dfsg1
Public Types | Public Member Functions | Private Types | Private Attributes
Highscores Class Reference

#include <highscores.hpp>

Collaboration diagram for Highscores:
Collaboration graph

List of all members.

Public Types

enum  HighscoreType {

Public Member Functions

 Highscores ()
void Read (const lisp::Lisp *const node)
void Write (lisp::Writer *writer)
int matches (HighscoreType highscore_type, int num_karts, const RaceManager::Difficulty difficulty, const std::string &track, const int number_of_laps)
int addData (const HighscoreType highscore_type, const std::string kart_name, const std::string name, const float time)
 Inserts the data into the highscore list.
int getNumberEntries () const
void getEntry (int number, std::string &kart_name, std::string &name, float *const time) const

Private Types

enum  { HIGHSCORE_LEN = 3 }

Private Attributes

std::string m_track
HighscoreType m_highscore_type
int m_number_of_karts
int m_difficulty
int m_number_of_laps
std::string m_kart_name [HIGHSCORE_LEN]
std::string m_name [HIGHSCORE_LEN]
float m_time [HIGHSCORE_LEN]

Detailed Description

Definition at line 30 of file highscores.hpp.

Member Enumeration Documentation

anonymous enum [private]

Definition at line 39 of file highscores.hpp.

{HIGHSCORE_LEN = 3};       // It's a top 3 list

Definition at line 33 of file highscores.hpp.

Constructor & Destructor Documentation

Definition at line 27 of file highscores.cpp.

    m_track           = ""; 
    m_highscore_type  = HST_UNDEFINED;
    m_number_of_karts =-1;
    m_difficulty      = -1;
    m_number_of_laps  = -1;
    for(int i=0; i<HIGHSCORE_LEN; i++) 
        m_name[i]      = "";
        m_kart_name[i] = "";
        m_time[i]      = -9.9f;
}   // Highscores

Member Function Documentation

int Highscores::addData ( const HighscoreType  highscore_type,
const std::string  kart_name,
const std::string  name,
const float  time 

Inserts the data into the highscore list.

If the new entry is fast enough to be in the highscore list, the new position (1-HIGHSCORE_LEN) is returned, otherwise a 0.

Definition at line 101 of file highscores.cpp.

    int position=-1;
    for(int i=0; i<HIGHSCORE_LEN; i++)
        // Check for unused entry. If so, just insert the new record
        // Check if new entry is faster than previous entry, if so
        // move times etc and insert new entry
        if(time < m_time[i])
            for(int j=HIGHSCORE_LEN-2;j>=i;j--)
                m_name[j+1]      = m_name[j];
                m_kart_name[j+1] = m_kart_name[j];
                m_time[j+1]      = m_time[j];
            position = i;

        m_track               = race_manager->getTrackName();
        m_highscore_type      = highscore_type;
        m_number_of_karts     = race_manager->getNumKarts();
        m_difficulty          = race_manager->getDifficulty();
        m_number_of_laps      = race_manager->getNumLaps();
        m_name[position]      = name;
        m_time[position]      = time;
        m_kart_name[position] = kart_name;

    return position+1;

}   // addData

Here is the call graph for this function:

Here is the caller graph for this function:

void Highscores::getEntry ( int  number,
std::string &  kart_name,
std::string &  name,
float *const  time 
) const

Definition at line 154 of file highscores.cpp.

    if(number<0 || number>getNumberEntries())
        fprintf(stderr, "Error, accessing undefined highscore entry:\n");
        fprintf(stderr,"number %d, but %d entries are defined\n",number,
        fprintf(stderr, "This error can be ignored, but no highscores are available\n");
    kart_name = m_kart_name[number];
    name      = m_name[number];
    *time     = m_time[number];
}   // getEntry

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 144 of file highscores.cpp.

    for(int i=HIGHSCORE_LEN-1; i>=0; i--)
        if(m_time[i]>0) return i+1;
    return 0;
}   // getNumberEntries

Here is the caller graph for this function:

int Highscores::matches ( HighscoreType  highscore_type,
int  num_karts,
const RaceManager::Difficulty  difficulty,
const std::string &  track,
const int  number_of_laps 

Definition at line 85 of file highscores.cpp.

    return (m_highscore_type  == highscore_type   &&
            m_track           == track            &&
            m_difficulty      == difficulty       &&
            m_number_of_laps  == number_of_laps   &&
            m_number_of_karts == num_karts          );
}   // matches
void Highscores::Read ( const lisp::Lisp *const  node)

Definition at line 43 of file highscores.cpp.

    node->get("track-name",     m_track               );
    node->get("number-karts",   m_number_of_karts     );
    node->get("race-mode",      (int&)m_highscore_type);
    node->get("difficulty",     m_difficulty          );
    node->get("number-of-laps", m_number_of_laps      );

    for(int i=0; i<HIGHSCORE_LEN; i++) 
        char s[128];
        snprintf(s, sizeof(s), "time-%d",     i);
        node->get(s,m_time[i]                  );
        snprintf(s, sizeof(s), "name-%d",     i);
        node->get(s,m_name[i]                  );
        snprintf(s, sizeof(s), "kartname-%d", i);
        node->get(s, m_kart_name[i]            );
}   // Read

Here is the call graph for this function:

Here is the caller graph for this function:

void Highscores::Write ( lisp::Writer writer)

Definition at line 64 of file highscores.cpp.

    writer->write("track-name\t",     m_track            );
    writer->write("number-karts\t",   m_number_of_karts  );
    writer->write("difficulty\t\t",   m_difficulty       );
    writer->write("race-mode\t\t",    m_highscore_type   );
    writer->write("number-of-laps\t", m_number_of_laps   );
    for(int j=0; j<HIGHSCORE_LEN; j++) 
        char s[128];
        snprintf(s, sizeof(s), "time-%d\t\t",     j);
        writer->write(s, m_time[j]                 );
        snprintf(s, sizeof(s), "name-%d\t\t",     j);
        writer->write(s, m_name[j]                 );
        snprintf(s, sizeof(s), "kartname-%d\t\t", j);
        writer->write(s, m_kart_name[j]            );
    }   // for j
}   // Write

Here is the call graph for this function:

Member Data Documentation

int Highscores::m_difficulty [private]

Definition at line 43 of file highscores.hpp.

Definition at line 41 of file highscores.hpp.

std::string Highscores::m_kart_name[HIGHSCORE_LEN] [private]

Definition at line 45 of file highscores.hpp.

std::string Highscores::m_name[HIGHSCORE_LEN] [private]

Definition at line 46 of file highscores.hpp.

Definition at line 42 of file highscores.hpp.

Definition at line 44 of file highscores.hpp.

Definition at line 47 of file highscores.hpp.

std::string Highscores::m_track [private]

Definition at line 40 of file highscores.hpp.

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