Back to index

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

Management class for the whole gameflow, this is where the main-loop is. More...

#include <game_manager.hpp>

List of all members.

Public Member Functions

 GameManager ()
 ~GameManager ()
void run ()
void abort ()

Private Attributes

bool m_abort
int m_frame_count
Uint32 m_curr_time
Uint32 m_prev_time

Detailed Description

Management class for the whole gameflow, this is where the main-loop is.

Definition at line 26 of file game_manager.hpp.


Constructor & Destructor Documentation

Definition at line 46 of file game_manager.cpp.

                         :
m_abort(false),
m_frame_count(0),
m_curr_time(m_prev_time),
m_prev_time(SDL_GetTicks())
{
}  // GameManager

Definition at line 55 of file game_manager.cpp.

{
}   // ~GameManager

Member Function Documentation

Definition at line 181 of file game_manager.cpp.

{
    m_abort = true;
}

Here is the caller graph for this function:

void GameManager::run ( )

Definition at line 60 of file game_manager.cpp.

{
    const GLuint TITLE_SCREEN_TEXTURE = 
        material_manager->getMaterial("st_title_screen.rgb")->getState()->getTextureHandle();
       
    bool music_on = false;
    m_curr_time = SDL_GetTicks();
    float dt;
    while(!m_abort)
    {
        inputDriver->input();

        m_prev_time = m_curr_time;

        while( 1 )
        {
            m_curr_time = SDL_GetTicks();
            dt =(float)(m_curr_time - m_prev_time);
            
            // don't allow the game to run slower than a certain amount.
            // when the computer can't keep it up, slow down the shown time instead
            static const float max_elapsed_time = 3.0f*1.0f/60.0f*1000.0f; /* time 3 internal substeps take */
            if(dt > max_elapsed_time) dt=max_elapsed_time;
                                               
            // Throttle fps if more than maximum, which can reduce 
            // the noise the fan on a graphics card makes
            if( dt*user_config->m_max_fps < 1000.0f)
            {
                //SDL_Delay has a granularity of 10ms on most platforms, so
                //most likely when frames go faster than 125 frames, at times
                //it might limit the frames to even 55 frames. On some cases,
                //SDL_Delay(1) will just cause the program to give up the
                //rest of it's timeslice.
                SDL_Delay(1);
            }
            else break;
        }
        dt *= 0.001f;

        if (!music_on && !race_manager->raceIsActive())
        {
            sound_manager->stopMusic();   // stop potential 'left over' music from race
              sound_manager->startMusic(stk_config->m_title_music);
                  music_on = true;
        }

        if (race_manager->raceIsActive())
        {
            music_on = false; 
               if(user_config->m_profile) dt=1.0f/60.0f;
            // In the first call dt might be large (includes loading time),
            // which can cause the camera to significantly tilt
            scene->draw(world->getPhase()==World::SETUP_PHASE ? 0.0f : dt);
            if ( world->getPhase() != World::LIMBO_PHASE)
            {
                world->update(dt);

                if(user_config->m_profile>0)
                {
                    m_frame_count++;
                    if (world->getTime()>user_config->m_profile)
                    {
                        //FIXME: SDL_GetTicks() includes the loading time,
                        //so the FPS will be skewed for now.
                        printf("Number of frames: %d time %f, Average FPS: %f\n",
                               m_frame_count, SDL_GetTicks() * 0.001,
                               (float)m_frame_count/(SDL_GetTicks() * 0.001));
                        if(!user_config->m_replay_history) history->Save();
                        std::exit(-2);
                    }
                }   // if m_profile
            }
        }
        else
        {
            glMatrixMode   ( GL_PROJECTION ) ;
            glLoadIdentity () ;
            glMatrixMode   ( GL_MODELVIEW ) ;
            glLoadIdentity () ;
            glDisable      ( GL_DEPTH_TEST ) ;
            glDisable      ( GL_LIGHTING   ) ;
            glDisable      ( GL_FOG        ) ;
            glDisable      ( GL_CULL_FACE  ) ;
            glDisable      ( GL_ALPHA_TEST ) ;
            glEnable       ( GL_TEXTURE_2D ) ;

            // On at least one platform the X server apparently gets overloaded
            // by the large texture, resulting in buffering of key events. This
            // results in the menu being very unresponsive/slow - it can sometimes
            // take (say) half a second before the menu reacts to a pressed key.
            // This is caused by X buffering the key events, delivering them
            // later (and sometimes even several at the same frame). This issue
            // could either be solved by a lazy drawing of the background picture
            // (i.e. draw the background only if something has changed) - which is
            // a lot of implementation work ... or by sleeping for a little while,
            // which apparently reduces the load for the X server, so that no
            // buffering is done --> all key events are handled in time.
        #if !defined(WIN32) && !defined(__CYGWIN__)
//                usleep(2000);
        #endif
            //Draw the splash screen
            glBindTexture(GL_TEXTURE_2D,TITLE_SCREEN_TEXTURE);

            glBegin ( GL_QUADS ) ;
            glColor3f   (1, 1, 1 ) ;
            glTexCoord2f(0, 0); glVertex2i(-1, -1);
            glTexCoord2f(1, 0); glVertex2i( 1, -1);
            glTexCoord2f(1, 1); glVertex2i( 1,  1);
            glTexCoord2f(0, 1); glVertex2i(-1,  1);
            glEnd () ;
        }

        menu_manager->update();
        sound_manager->update(dt);

        glFlush();
        SDL_GL_SwapBuffers();
    }  // while !m_exit
}   // run

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

bool GameManager::m_abort [private]

Definition at line 29 of file game_manager.hpp.

Uint32 GameManager::m_curr_time [private]

Definition at line 32 of file game_manager.hpp.

Definition at line 31 of file game_manager.hpp.

Uint32 GameManager::m_prev_time [private]

Definition at line 33 of file game_manager.hpp.


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