Back to index

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

#include <projectile_manager.hpp>

Collaboration diagram for ProjectileManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ProjectileManager ()
 ~ProjectileManager ()
void explode ()
void FinishedExplosion ()
ssgSelector * getExplosionModel ()
int getProjectileId (const std::string ident)
void loadData ()
void cleanup ()
void update (float dt)
 General projectile update call.
FlyablenewProjectile (Kart *kart, CollectableType type)
ExplosionnewExplosion (sgCoord *coord)
 See if there is an old, unused explosion object available.
void Deactivate (Flyable *p)
void removeTextures ()

Private Types

typedef std::vector< Flyable * > Projectiles
typedef std::vector< Explosion * > Explosions

Private Attributes

Projectiles m_active_projectiles
Explosions m_active_explosions
ssgSelector * m_explosion_model
bool m_something_was_hit
bool m_explosion_ended

Detailed Description

Definition at line 31 of file projectile_manager.hpp.


Member Typedef Documentation

typedef std::vector<Explosion* > ProjectileManager::Explosions [private]

Definition at line 35 of file projectile_manager.hpp.

typedef std::vector<Flyable*> ProjectileManager::Projectiles [private]

Definition at line 34 of file projectile_manager.hpp.


Constructor & Destructor Documentation

Definition at line 50 of file projectile_manager.hpp.

Definition at line 51 of file projectile_manager.hpp.

{};

Member Function Documentation

Definition at line 61 of file projectile_manager.cpp.

{
    for(Projectiles::iterator i = m_active_projectiles.begin();
        i != m_active_projectiles.end(); ++i)
    {
        ssgTransform *m = (*i)->getModelTransform();
        m->removeAllKids();
        delete *i;
    }
    m_active_projectiles.clear();
    for(Explosions::iterator i  = m_active_explosions.begin();
        i != m_active_explosions.end(); ++i)
    {
        scene->remove((ssgTransform*)*i);
        ssgDeRefDelete(*i);
    }
    m_active_explosions.clear();
}   // cleanup

Here is the call graph for this function:

Here is the caller graph for this function:

void ProjectileManager::Deactivate ( Flyable p) [inline]

Definition at line 64 of file projectile_manager.hpp.

{}
void ProjectileManager::explode ( ) [inline]

Definition at line 52 of file projectile_manager.hpp.

Here is the caller graph for this function:

Definition at line 53 of file projectile_manager.hpp.

Here is the caller graph for this function:

ssgSelector* ProjectileManager::getExplosionModel ( ) [inline]

Definition at line 54 of file projectile_manager.hpp.

    {
        return (ssgSelector*)m_explosion_model->clone();
    }

Here is the caller graph for this function:

int ProjectileManager::getProjectileId ( const std::string  ident)

Definition at line 34 of file projectile_manager.cpp.

{

    // Load the explosion model and find the actual selector branch in it.
    // Only the explosion model is loaded here, see collectable_manager.
    m_explosion_model = find_selector((ssgBranch*)loader->load("explode.ac",
                                   CB_EXPLOSION) );
    m_explosion_model->ref();
    if ( m_explosion_model == NULL )
    {
        fprintf ( stderr, "explode.ac doesn't have an 'explosion' object.\n" ) ;
        exit ( 1 ) ;
    }

}   // loadData

Here is the call graph for this function:

See if there is an old, unused explosion object available.

If so, reuse this object, otherwise create a new one.

Definition at line 144 of file projectile_manager.cpp.

{
    Explosion *e = new Explosion(coord);
    m_active_explosions.push_back(e);
    return e;
}   // newExplosion

Here is the caller graph for this function:

Definition at line 128 of file projectile_manager.cpp.

{
    Flyable *f;
    switch(type) {
    case COLLECT_SPARK:   f = new Spark(kart);   break;
    case COLLECT_HOMING:  f = new Homing(kart);  break;
    case COLLECT_MISSILE: f = new Missile(kart); break;
    default:              return NULL;
    }
    m_active_projectiles.push_back(f);
    return f;
}   // newProjectile

Here is the caller graph for this function:

Definition at line 51 of file projectile_manager.cpp.

{
    cleanup();
    ssgDeRefDelete(m_explosion_model);
    // Only the explosion is here, all other models are actually managed
    // by collectable_manager.
    callback_manager->clear(CB_EXPLOSION);
}   // removeTextures

Here is the call graph for this function:

void ProjectileManager::update ( float  dt)

General projectile update call.

Definition at line 82 of file projectile_manager.cpp.

{
    // First update all projectiles on the track
    for(Projectiles::iterator i  = m_active_projectiles.begin();
        i != m_active_projectiles.end(); ++i)
    {
        (*i)->update(dt);
    }
    // Then check if any projectile hit something
    if(m_something_was_hit)
    {
        Projectiles::iterator p = m_active_projectiles.begin();
        while(p!=m_active_projectiles.end())
        {
            if(! (*p)->hasHit()) { p++; continue; }
            newExplosion((*p)->getCoord());
            Flyable *f=*p;
            Projectiles::iterator pNext=m_active_projectiles.erase(p);  // returns the next element
            delete f;
            p=pNext;
        }   // while p!=m_active_projectiles.end()
    }

    m_explosion_ended=false;
    for(Explosions::iterator i  = m_active_explosions.begin();
        i != m_active_explosions.end(); ++i)
    {
        (*i)->update(dt);
    }
    if(m_explosion_ended)
    {
        Explosions::iterator e;
        e = m_active_explosions.begin();
        while(e!=m_active_explosions.end())
        {
            if(!(*e)->hasEnded()) { e++; continue;}
            Explosion *exp=*e;
            Explosions::iterator eNext=m_active_explosions.erase(e);
            ssgDeRefDelete(exp);  // reduce refcount and free object
            e=eNext;
        }   // while e!=m_active_explosions.end()
    }   // if m_explosion_ended
    m_something_was_hit=false;
}   // update

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 43 of file projectile_manager.hpp.

Definition at line 39 of file projectile_manager.hpp.

Definition at line 47 of file projectile_manager.hpp.

ssgSelector* ProjectileManager::m_explosion_model [private]

Definition at line 45 of file projectile_manager.hpp.

Definition at line 46 of file projectile_manager.hpp.


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