Back to index

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

#include <herring_manager.hpp>

Collaboration diagram for HerringManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 HerringManager ()
 ~HerringManager ()
void loadDefaultHerrings ()
void loadHerringStyle (const std::string filename)
HerringnewHerring (herringType type, sgVec3 *xyz)
void update (float delta)
void hitHerring (Kart *kart)
void cleanup ()
 Remove all herring instances, and the track specific models.
void reset ()
 Remove all herring instances, and the track specific models.
void removeTextures ()
void setUserFilename (char *s)
ssgEntity * getHerringModel (herringType type)

Private Types

typedef std::vector< Herring * > AllHerringType

Private Member Functions

void CreateDefaultHerring (sgVec3 colour, std::string name)
void setDefaultHerringStyle ()
void setHerring (const lisp::Lisp *herring_node, const char *colour, herringType type)

Private Attributes

AllHerringType m_all_herrings
ssgEntity * m_herring_model [HE_SILVER+1]
std::map< std::string,
ssgEntity * > 
m_all_models
std::string m_user_filename

Detailed Description

Definition at line 32 of file herring_manager.hpp.


Member Typedef Documentation

typedef std::vector<Herring*> HerringManager::AllHerringType [private]

Definition at line 37 of file herring_manager.hpp.


Constructor & Destructor Documentation

Definition at line 84 of file herring_manager.cpp.

{
    m_all_models.clear();
    // The actual loading is done in loadDefaultHerrings
}   // HerringManager

Definition at line 109 of file herring_manager.cpp.

{
    for(CI_type i=m_all_models.begin(); i!=m_all_models.end(); ++i)
    {
        ssgDeRefDelete(i->second);
    }
}   // ~HerringManager

Member Function Documentation

Remove all herring instances, and the track specific models.

This is used just before a new track is loaded and a race is started.

Definition at line 224 of file herring_manager.cpp.

{
    for(AllHerringType::iterator i =m_all_herrings.begin();
        i!=m_all_herrings.end();  i++)
    {
        delete *i;
    }
    m_all_herrings.clear();

    setDefaultHerringStyle();

    // Then load the default style from the user_config file
    // -----------------------------------------------------
    // This way if a herring is not defined in the herringstyle-file, the
    // default (i.e. old herring) is used.
    try
    {
        // FIXME: This should go in a system-wide configuration file,
        //        and only one of this and the hard-coded settings in
        //        setDefaultHerringStyle are necessary!!!
        loadHerringStyle(user_config->m_herring_style);
    }
    catch(std::runtime_error)
    {
        fprintf(stderr,"The herring style '%s' in your configuration file does not exist.\nIt is ignored.\n",
                user_config->m_herring_style.c_str());
        user_config->m_herring_style="";
    }

    try
    {
        loadHerringStyle(m_user_filename);
    }
    catch(std::runtime_error)
    {
        fprintf(stderr,"The herring style '%s' specified on the command line does not exist.\nIt is ignored.\n",
                m_user_filename.c_str());
        m_user_filename="";  // reset to avoid further warnings.
    }

}   // cleanup

Here is the call graph for this function:

Here is the caller graph for this function:

void HerringManager::CreateDefaultHerring ( sgVec3  colour,
std::string  name 
) [private]

Definition at line 290 of file herring_manager.cpp.

{
    ssgVertexArray   *va = new ssgVertexArray   () ; sgVec3 v ;
    ssgNormalArray   *na = new ssgNormalArray   () ; sgVec3 n ;
    ssgColourArray   *ca = new ssgColourArray   () ; sgVec4 c ;
    ssgTexCoordArray *ta = new ssgTexCoordArray () ; sgVec2 t ;

    sgSetVec3(v, -0.5f, 0.0f, 0.0f ) ; va->add(v) ;
    sgSetVec3(v,  0.5f, 0.0f, 0.0f ) ; va->add(v) ;
    sgSetVec3(v, -0.5f, 0.0f, 0.5f ) ; va->add(v) ;
    sgSetVec3(v,  0.5f, 0.0f, 0.5f ) ; va->add(v) ;
    sgSetVec3(v, -0.5f, 0.0f, 0.0f ) ; va->add(v) ;
    sgSetVec3(v,  0.5f, 0.0f, 0.0f ) ; va->add(v) ;

    sgSetVec3(n,  0.0f,  1.0f,  0.0f ) ; na->add(n) ;

    sgCopyVec3 ( c, colour ) ; c[ 3 ] = 1.0f ; ca->add(c) ;

    sgSetVec2(t, 0.0f, 0.0f ) ; ta->add(t) ;
    sgSetVec2(t, 1.0f, 0.0f ) ; ta->add(t) ;
    sgSetVec2(t, 0.0f, 1.0f ) ; ta->add(t) ;
    sgSetVec2(t, 1.0f, 1.0f ) ; ta->add(t) ;
    sgSetVec2(t, 0.0f, 0.0f ) ; ta->add(t) ;
    sgSetVec2(t, 1.0f, 0.0f ) ; ta->add(t) ;


    ssgLeaf *gset = new ssgVtxTable ( GL_TRIANGLE_STRIP, va, na, ta, ca ) ;

    gset->setState(material_manager->getMaterial("herring.rgb")->getState()) ;

    Shadow* sh = new Shadow ( -0.5f, 0.5f, -0.25f, 0.25f ) ;

    ssgTransform* tr = new ssgTransform () ;

    tr -> addKid ( sh -> getRoot () ) ;
    tr -> addKid ( gset ) ;
    tr -> ref () ; /* Make sure it doesn't get deleted by mistake */
    m_all_models[name] = tr;

}   // CreateDefaultHerring

Here is the call graph for this function:

Here is the caller graph for this function:

ssgEntity* HerringManager::getHerringModel ( herringType  type) [inline]

Definition at line 67 of file herring_manager.hpp.

                                {return m_herring_model[type];}

Here is the caller graph for this function:

void HerringManager::hitHerring ( Kart kart)

Definition at line 206 of file herring_manager.cpp.

{
    for(AllHerringType::iterator i =m_all_herrings.begin();
        i!=m_all_herrings.end();  i++)
    {
        if((*i)->wasEaten()) continue;
        if((*i)->hitKart(kart))
        {
            (*i)->isEaten();
            kart->collectedHerring(*i);
        }   // if hit
    }   // for m_all_herrings
}   // hitHerring

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 118 of file herring_manager.cpp.

{
    // Load all models. This can't be done in the constructor, 
    // since the file_manager isn't ready at that stage.
    // -------------------------------------------------------
    std::set<std::string> files;
    file_manager->listFiles(files, file_manager->getHerringDir(),
                            /*is_full_path*/true, 
                            /*make_full_path*/true);
    for(std::set<std::string>::iterator i  = files.begin();
            i != files.end();  ++i)
        {
            if(!StringUtils::has_suffix(*i, ".ac")) continue;
            ssgEntity*  h         = loader->load(*i, CB_HERRING, 
                                                 /*optimise*/true, 
                                                 /*full_path*/true);
            std::string shortName = StringUtils::basename(StringUtils::without_extension(*i));
            h->ref();
            h->setName(shortName.c_str());
            m_all_models[shortName] = h;
        }   // for i


    // Load the old, internal only models
    // ----------------------------------
    sgVec3 yellow = { 1.0f, 1.0f, 0.4f }; CreateDefaultHerring(yellow, "OLD_GOLD"  );
    sgVec3 cyan   = { 0.4f, 1.0f, 1.0f }; CreateDefaultHerring(cyan  , "OLD_SILVER");
    sgVec3 red    = { 0.8f, 0.0f, 0.0f }; CreateDefaultHerring(red   , "OLD_RED"   );
    sgVec3 green  = { 0.0f, 0.8f, 0.0f }; CreateDefaultHerring(green , "OLD_GREEN" );

    setDefaultHerringStyle();
}   // loadDefaultHerrings

Here is the call graph for this function:

void HerringManager::loadHerringStyle ( const std::string  filename)

Definition at line 332 of file herring_manager.cpp.

{
    if(filename.length()==0) return;
    const lisp::Lisp* root = 0;
    lisp::Parser parser;
    
    root = parser.parse(file_manager->getConfigFile(filename + ".herring"));

    const lisp::Lisp* herring_node = root->getLisp("herring");
    if(!herring_node)
    {
        char msg[MAX_ERROR_MESSAGE_LENGTH];
        snprintf(msg, sizeof(msg), "Couldn't load map '%s': no herring node.",
                 filename.c_str());
       delete root;
        throw std::runtime_error(msg);
        delete root;
    }
    setHerring(herring_node, "red",   HE_RED   );
    setHerring(herring_node, "green", HE_GREEN );
    setHerring(herring_node, "gold"  ,HE_GOLD  );
    setHerring(herring_node, "silver",HE_SILVER);
    delete root;
}   // loadHerringStyle

Here is the call graph for this function:

Here is the caller graph for this function:

Herring * HerringManager::newHerring ( herringType  type,
sgVec3 *  xyz 
)

Definition at line 198 of file herring_manager.cpp.

{
    Herring* h = new Herring(type, xyz, m_herring_model[type]);
    m_all_herrings.push_back(h);
    return h;
}   // newHerring

Here is the caller graph for this function:

Definition at line 91 of file herring_manager.cpp.

{
    for(AllHerringType::iterator i =m_all_herrings.begin();
        i!=m_all_herrings.end();  i++)
    {
        delete *i;
    }
    m_all_herrings.clear();

    for(CI_type i=m_all_models.begin(); i!=m_all_models.end(); ++i)
    {
        ssgDeRefDelete(i->second);
    }
    m_all_models.clear();
    callback_manager->clear(CB_HERRING);
}   // removeTextures

Here is the call graph for this function:

Remove all herring instances, and the track specific models.

This is used just before a new track is loaded and a race is started

Definition at line 270 of file herring_manager.cpp.

{
    for(AllHerringType::iterator i =m_all_herrings.begin();
        i!=m_all_herrings.end();  i++)
    {
        (*i)->reset();
    }  // for i
}   // reset

Here is the caller graph for this function:

Definition at line 152 of file herring_manager.cpp.

{
    // This should go in an internal, system wide configuration file
    const std::string DEFAULT_NAMES[4] = {"bonusblock", "banana",
                                   "goldcoin",   "silvercoin"};

    bool bError=0;
    char msg[MAX_ERROR_MESSAGE_LENGTH];
    for(int i=HE_RED; i<=HE_SILVER; i++)
    {
        m_herring_model[i] = m_all_models[DEFAULT_NAMES[i]];
        if(!m_herring_model[i])
        {
            snprintf(msg, sizeof(msg), 
                     "Herring model '%s' is missing (see herring_manager)!\n",
                     DEFAULT_NAMES[i].c_str());
            bError=1;
            break;
        }   // if !m_herring_model
    }   // for i
    if(bError)
    {
        fprintf(stderr, "The following models are available:\n");
        for(CI_type i=m_all_models.begin(); i!=m_all_models.end(); ++i)
        {
            if(i->second)
            {
                if(i->first.substr(0,3)=="OLD")
                {
                    fprintf(stderr,"   %s internally only.\n",i->first.c_str());
                }
                else
                {
                    fprintf(stderr, "   %s in models/herrings/%s.ac.\n",
                            i->first.c_str(),
                            i->first.c_str());
                }
            }  // if i->second
        }
        throw std::runtime_error(msg);
        exit(-1);
    }   // if bError

}   // setDefaultHerringStyle

Here is the caller graph for this function:

void HerringManager::setHerring ( const lisp::Lisp herring_node,
const char *  colour,
herringType  type 
) [private]

Definition at line 358 of file herring_manager.cpp.

{
    std::string name;
    herring_node->get(colour, name);
    if(name.size()>0)
    {
        m_herring_model[type]=m_all_models[name];
    }
}   // setHerring

Here is the call graph for this function:

Here is the caller graph for this function:

void HerringManager::setUserFilename ( char *  s) [inline]

Definition at line 66 of file herring_manager.hpp.

Here is the caller graph for this function:

void HerringManager::update ( float  delta)

Definition at line 280 of file herring_manager.cpp.

{
    for(AllHerringType::iterator i =m_all_herrings.begin();
        i!=m_all_herrings.end();  i++)
    {
        (*i)->update(delta);
    }   // for m_all_herrings
}   // delta

Here is the caller graph for this function:


Member Data Documentation

Definition at line 38 of file herring_manager.hpp.

std::map<std::string,ssgEntity*> HerringManager::m_all_models [private]

Definition at line 47 of file herring_manager.hpp.

ssgEntity* HerringManager::m_herring_model[HE_SILVER+1] [private]

Definition at line 42 of file herring_manager.hpp.

std::string HerringManager::m_user_filename [private]

Definition at line 49 of file herring_manager.hpp.


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