Back to index

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

#include <kart_properties_manager.hpp>

Collaboration diagram for KartPropertiesManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 KartPropertiesManager ()
 ~KartPropertiesManager ()
const KartPropertiesgetKartById (int i)
const KartPropertiesgetKart (const std::string IDENT)
const int getKartId (const std::string IDENT)
void loadKartData (bool dont_load_models=false)
const float getMaximumSteeringAngle ()
const unsigned int getNumberOfKarts ()
std::vector< std::string > getRandomKarts (int len)
 Return len random karts.
void fillWithRandomKarts (std::vector< std::string > &vec)
 Fill the empty positions in the given vector with random karts.
void removeTextures ()

Public Attributes

std::vector< int > m_selected_karts

Protected Types

typedef std::vector
< KartProperties * > 
KartPropertiesVector

Protected Attributes

float m_max_steer_angle
KartPropertiesVector m_karts_properties
 All available kart configurations.

Detailed Description

Definition at line 27 of file kart_properties_manager.hpp.


Member Typedef Documentation

Definition at line 32 of file kart_properties_manager.hpp.


Constructor & Destructor Documentation

Definition at line 34 of file kart_properties_manager.cpp.

{}

Definition at line 38 of file kart_properties_manager.cpp.

{
    for(KartPropertiesVector::iterator i  = m_karts_properties.begin();
        i != m_karts_properties.end(); ++i)
        delete *i;
}   // ~KartPropertiesManager

Member Function Documentation

void KartPropertiesManager::fillWithRandomKarts ( std::vector< std::string > &  vec)

Fill the empty positions in the given vector with random karts.

Definition at line 153 of file kart_properties_manager.cpp.

{
    std::vector<std::string> all_karts;

    for(KartPropertiesVector::const_iterator i = m_karts_properties.begin();
        i != m_karts_properties.end(); ++i)
        all_karts.push_back((*i)->getIdent());

    std::srand((unsigned int)std::time(0));

    std::random_shuffle(all_karts.begin(), all_karts.end());

    int new_kart = 0;
    for(int i = 0; i < int(vec.size()); ++i)
    {
        while(vec[i].empty())
        {
            if (std::find(vec.begin(), vec.end(), all_karts[new_kart]) == vec.end())
            { // Found a new kart, so use it
                vec[i] = all_karts[new_kart];
            }
            else if (!(all_karts.size() >= vec.size()))
            { // We need to fill more karts than we have available, so don't care about dups
                vec[i] = all_karts[new_kart];
            }

            new_kart += 1;
        }   // while
    }   // for i
}

Here is the caller graph for this function:

const KartProperties * KartPropertiesManager::getKart ( const std::string  IDENT)

Definition at line 111 of file kart_properties_manager.cpp.

{
    for(KartPropertiesVector::const_iterator i  = m_karts_properties.begin();
        i != m_karts_properties.end(); ++i)
    {
        if ((*i)->getIdent() == IDENT)
            return *i;
    }

    return NULL;
}   // getKart

Here is the caller graph for this function:

Definition at line 124 of file kart_properties_manager.cpp.

{
    if (i < 0 || i >= int(m_karts_properties.size()))
        return NULL;

    return m_karts_properties[i];
}

Here is the caller graph for this function:

const int KartPropertiesManager::getKartId ( const std::string  IDENT)

Definition at line 93 of file kart_properties_manager.cpp.

{
    int j = 0;
    for(KartPropertiesVector::const_iterator i  = m_karts_properties.begin();
        i != m_karts_properties.end(); ++i)
    {
        if ((*i)->getIdent() == IDENT)
            return j;
        ++j;
    }

    char msg[MAX_ERROR_MESSAGE_LENGTH];
    snprintf(msg, sizeof(msg), "KartPropertiesManager: Couldn't find kart: '%s'",
             IDENT.c_str());
    throw std::runtime_error(msg);
}   // getKartId

Definition at line 49 of file kart_properties_manager.hpp.

const unsigned int KartPropertiesManager::getNumberOfKarts ( ) [inline]

Definition at line 50 of file kart_properties_manager.hpp.

{return (unsigned int)m_karts_properties.size();}

Here is the caller graph for this function:

std::vector< std::string > KartPropertiesManager::getRandomKarts ( int  len)

Return len random karts.

Definition at line 135 of file kart_properties_manager.cpp.

{
    std::vector<std::string> all_karts;

    for(KartPropertiesVector::const_iterator i  = m_karts_properties.begin();
        i != m_karts_properties.end(); ++i)
    {
        all_karts.push_back((*i)->getIdent());
    }

    std::random_shuffle(all_karts.begin(), all_karts.end());

    all_karts.resize(len);

    return all_karts;
}   // getRandomKart
void KartPropertiesManager::loadKartData ( bool  dont_load_models = false)

Definition at line 58 of file kart_properties_manager.cpp.

{
    m_max_steer_angle = -1.0f;
    std::set<std::string> result;
    file_manager->listFiles(result, file_manager->getKartDir(), 
                            /*is_full_path*/ true);

    // Find out which characters are available and load them
    for(std::set<std::string>::iterator i = result.begin();
            i != result.end(); ++i)
    {
        std::string kart_file;
        try
        {
            kart_file = file_manager->getKartFile((*i)+".kart");
        }
        catch (std::exception& e)
        {
            (void)e;   // remove warning about unused variable
            continue;
        }
        FILE *f=fopen(kart_file.c_str(),"r");
        if(!f) continue;
        fclose(f);
        KartProperties* kp = new KartProperties();
        kp->load(kart_file, "tuxkart-kart", dont_load_models);
        m_karts_properties.push_back(kp);
        if(kp->getMaxSteerAngle() > m_max_steer_angle)
        {
            m_max_steer_angle = kp->getMaxSteerAngle();
        }
    }   // for i
}   // loadKartData

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 46 of file kart_properties_manager.cpp.

{
    for(KartPropertiesVector::iterator i  = m_karts_properties.begin();
        i != m_karts_properties.end(); ++i)
    {
        delete *i;
    }
    m_karts_properties.clear();
    callback_manager->clear(CB_KART);
}   // removeTextures

Here is the call graph for this function:


Member Data Documentation

All available kart configurations.

Definition at line 34 of file kart_properties_manager.hpp.

Definition at line 30 of file kart_properties_manager.hpp.

Definition at line 43 of file kart_properties_manager.hpp.


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