Back to index

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

#include <loader.hpp>

Collaboration diagram for Loader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Loader ()
 ~Loader ()
virtual void makeModelPath (char *path, const char *fname) const
ssgEntity * load (const std::string &filename, CallbackType t, bool optimise=true, bool is_full_path=false)
 Loads a .ac model.
void setCallbackType (CallbackType t)

Private Member Functions

bool findFile (std::string &full_path, const std::string &fname, const std::vector< std::string > &search_path) const
void makePath (std::string &path, const std::string &dir, const std::string &fname) const
ssgBranch * createBranch (char *data) const
 Handle userdata that is stored in the model files.
void preProcessObj (ssgEntity *n, bool mirror)
ssgBranch * animInit (char *data) const

Private Attributes

bool m_is_full_path
std::string m_root_dir
std::vector< std::string > m_texture_search_path
std::vector< std::string > m_model_search_path
std::vector< std::string > m_music_search_path
CallbackType m_current_callback_type

Detailed Description

Definition at line 29 of file loader.hpp.


Constructor & Destructor Documentation

Definition at line 44 of file loader.cpp.

Definition at line 50 of file loader.cpp.

{
}   // ~Loader

Member Function Documentation

ssgBranch * Loader::animInit ( char *  data) const [private]

Definition at line 132 of file loader.cpp.

{
    while ( ! isdigit ( *data ) && *data != '\0' )
        data++ ;

    const int   START_LIM =        strtol(data, &data, 0 );
    const int   END_LIM   =        strtol(data, &data, 0 );
    const float TIME_LIM  = (float)strtod(data, &data    );

    while ( *data <= ' ' && *data != '\0' )
        data++ ;

    char mode = toupper ( *data ) ;

    ssgTimedSelector *br = new ssgTimedSelector;

    br->setLimits  (START_LIM+1, END_LIM+1 ) ;
    br->setDuration(TIME_LIM ) ;
    br->setMode    ((mode=='O') ?  SSG_ANIM_ONESHOT
                    :  (mode=='S') ?  SSG_ANIM_SWING
                    : SSG_ANIM_SHUTTLE ) ;
    br->control    (SSG_ANIM_START ) ;

    return br;
}   // animInit

Here is the caller graph for this function:

ssgBranch * Loader::createBranch ( char *  data) const [private]

Handle userdata that is stored in the model files.

Mostly the userdata indicates that a special branch is to be created (e.g. a ssgCutout instead of the standard branch). But some userdata indicate that callbacks need to be created, which are then handled by the callback manager.

Definition at line 166 of file loader.cpp.

{

    if ( data == NULL || data[0] != '@' ) return NULL;

    data++ ;   /* Skip the '@' */

    if ( strncmp("billboard", data, strlen("billboard") ) == 0 )
        return  new ssgCutout();

    if ( strncmp("DONT_DELETE", data, strlen("DONT_DELETE") ) == 0 )
    {
        printf("DONT\n");
        ssgBranch *br = new ssgTransform();
        br->setUserData(new ssgBase());
        return br;
    }

    if ( strncmp("invisible", data, strlen("invisible") ) == 0 )
        return new ssgInvisible();

    if ( strncmp ( "switch", data, strlen ( "switch" ) ) == 0 )
    {
        ssgSelector *sel = new ssgSelector();
        sel->select(0);
        return sel;
    }

    if ( strncmp ( "animate", data, strlen ( "animate" ) ) == 0 )
        return animInit(data);


    if ( strncmp ( "autodcs", data, strlen ( "autodcs" ) ) == 0 )
    {
        ssgTransform *br = new ssgTransform();
        Callback     *c  = new MovingTexture(data, br);
        br->setUserData(new ssgBase());
        callback_manager->addCallback(c, m_current_callback_type);
        return br;
    }

    if ( strncmp ( "autotex", data, strlen ( "autotex" ) ) == 0 )
    {
        ssgTexTrans *br = new ssgTexTrans();
        Callback    *c  = new MovingTexture(data, br);
        callback_manager->addCallback(c, m_current_callback_type);
        return br;
    }
    if(strncmp("physics", data, strlen("physics")) == 0)
    {
        MovingPhysics *mp = new MovingPhysics(std::string(data));
        callback_manager->addCallback(mp, m_current_callback_type);
        return mp;
    }
    fprintf(stderr, "Warning: Ignoring userdata '%s'\n", data);
    return NULL ;
}   // createBranch

Here is the call graph for this function:

bool Loader::findFile ( std::string &  full_path,
const std::string &  fname,
const std::vector< std::string > &  search_path 
) const [private]
ssgEntity * Loader::load ( const std::string &  filename,
CallbackType  t,
bool  optimise = true,
bool  is_full_path = false 
)

Loads a .ac model.

Loads the .ac model 'filename'. Callbacks contained in this file are stored in the callback class t. If optimise is set to false, the file will not be flattened, which is necessary for the kart models - flattening them will remove the wheel nodes, withouth which the wheels do not rotate.

Parameters:
filenameFile to load
tCallback category for callbacks included in this file (see callback_manager.hpp)
optimiseDefault is true. If set to false, the model will not be flattened.

Definition at line 85 of file loader.cpp.

{
    m_current_callback_type   = t;
    m_is_full_path            = is_full_path;
    ssgEntity *obj            = optimise ? ssgLoad  (filename.c_str(), this) 
                                         : ssgLoadAC(filename.c_str(), this);
    preProcessObj(obj, false);
    return obj;
}   // load

Here is the call graph for this function:

Here is the caller graph for this function:

void Loader::makeModelPath ( char *  path,
const char *  fname 
) const [virtual]

Definition at line 55 of file loader.cpp.

{
    if(m_is_full_path)
    {
        strcpy(path, FNAME);
        return;
    }
    
    std::string p=file_manager->getModelFile(FNAME);
    strcpy(path, p.c_str());
    return;
}   // makeModelPath

Here is the call graph for this function:

void Loader::makePath ( std::string &  path,
const std::string &  dir,
const std::string &  fname 
) const [private]
void Loader::preProcessObj ( ssgEntity *  n,
bool  mirror 
) [private]

Definition at line 97 of file loader.cpp.

{
    if ( n == NULL ) return ;

    n -> dirtyBSphere () ;

    if ( n -> isAKindOf ( ssgTypeLeaf() ) )
    {
        if ( mirror )
            for ( int i = 0 ; i < ((ssgLeaf *)n) -> getNumVertices () ; i++ )
                ((ssgLeaf *)n) -> getVertex ( i ) [ 0 ] *= -1.0f ;

        material_manager->getMaterial((ssgLeaf *) n ) -> applyToLeaf ( (ssgLeaf *) n ) ;
        return ;
    }

    if ( mirror && n -> isAKindOf ( ssgTypeTransform () ) )
    {
        sgMat4 xform ;

        ((ssgTransform *)n) -> getTransform ( xform ) ;
        xform [ 0 ][ 0 ] *= -1.0f ;
        xform [ 1 ][ 0 ] *= -1.0f ;
        xform [ 2 ][ 0 ] *= -1.0f ;
        xform [ 3 ][ 0 ] *= -1.0f ;
        ((ssgTransform *)n) -> setTransform ( xform ) ;
    }

    ssgBranch *b = (ssgBranch *) n ;

    for ( int i = 0 ; i < b -> getNumKids () ; i++ )
        preProcessObj ( b -> getKid ( i ), mirror ) ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Loader::setCallbackType ( CallbackType  t) [inline]

Definition at line 48 of file loader.hpp.


Member Data Documentation

Definition at line 50 of file loader.hpp.

bool Loader::m_is_full_path [private]

Definition at line 32 of file loader.hpp.

std::vector<std::string> Loader::m_model_search_path [private]

Definition at line 34 of file loader.hpp.

std::vector<std::string> Loader::m_music_search_path [private]

Definition at line 34 of file loader.hpp.

std::string Loader::m_root_dir [private]

Definition at line 33 of file loader.hpp.

std::vector<std::string> Loader::m_texture_search_path [private]

Definition at line 34 of file loader.hpp.


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