Back to index

extremetuxracer  0.5beta
Functions | Variables
loop.cpp File Reference
#include "loop.h"
#include "game_config.h"
#include "ppgltk/ui_snow.h"
#include "ppgltk/alg/defs.h"
#include "SDL.h"
#include "render_util.h"
#include "splash_screen.h"
#include "game_type_select.h"
#include "credits.h"
#include "race_select.h"
#include "loading.h"
#include "intro.h"
#include "racing.h"
#include "paused.h"
#include "game_over.h"
#include "reset.h"
#include "event_select.h"
#include "event_race_select.h"
#include "bench.h"
#include "highscore.h"
#include "configuration.h"
#include "graphicsconfig.h"
#include "videoconfig.h"
#include "audioconfig.h"
#include "keyboardconfig.h"
#include "joystickconfig.h"
#include "game_mgr.h"

Go to the source code of this file.

Functions

void set_game_mode (game_mode_t mode)
void main_loop ()
bool is_mode_change_pending ()
 Returns true if a mode change will occur the next time main_loop() runs.
void loop_mouse_func (int button, int state, int x, int y)
void loop_mouse_motion_func (int x, int y)
void loop_keyboard_func (SDLKey key, SDLMod mod, bool release, int x, int y)

Variables

static game_mode_t new_mode = NO_MODE

Function Documentation

Returns true if a mode change will occur the next time main_loop() runs.

Author:
jfpatry

Definition at line 192 of file loop.cpp.

{
    return bool(GameMode::mode != new_mode);
}

Here is the caller graph for this function:

void loop_keyboard_func ( SDLKey  key,
SDLMod  mod,
bool  release,
int  x,
int  y 
)

Definition at line 232 of file loop.cpp.

{
       if(GameMode::currentMode!=NULL){          
              if (key < SDLK_UP) {
            if ( isalpha( key ) ) {
                key = SDLKey(tolower( key ));
            }
        }
              
              if(GameMode::currentMode->keyboardEvent(key,release)) return;
              else if(release){
                     if(GameMode::currentMode->keyReleaseEvent(key)) return;
              }else{
                     if(GameMode::currentMode->keyPressEvent(key)) return;
              }
              UIMgr.keyboardEvent(key,mod,release);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void loop_mouse_func ( int  button,
int  state,
int  x,
int  y 
)

Definition at line 213 of file loop.cpp.

{
       if(GameMode::currentMode!=NULL){
              bool pressed = state && SDL_PRESSED;
              if(GameMode::currentMode->mouseButtonEvent(button,x,y,pressed)) return;
              else if(pressed){
                     if(GameMode::currentMode->mouseButtonPressEvent(button,x,y)) return;
              }else{
                     if(GameMode::currentMode->mouseButtonReleaseEvent(button,x,y)) return;
              }      
              UIMgr.mouseEvent(button,state,x,y);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void loop_mouse_motion_func ( int  x,
int  y 
)

Definition at line 227 of file loop.cpp.

{
       UIMgr.motionEvent(x,y);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void main_loop ( )

Definition at line 69 of file loop.cpp.

{
       if ( getparam_capture_mouse() ) {
              const int w = getparam_x_resolution();
              const int h = getparam_y_resolution();
              pp::Vec2d pos = UIMgr.getMousePosition();

              // Flip y coordinates
              pos.y = h - pos.y;

              if ( pos.x < 0 ) {
                  pos.x = 0;
              }
              if ( pos.x > w-1 ) {
                  pos.x = w-1;
              }
              if ( pos.y < 0 ) {
                  pos.y = 0;
              }
              if ( pos.y > h-1 ) {
                  pos.y = h-1;
              }

              winsys_warp_pointer( int(pos.x), int(pos.y) );
    }
       
       if ( GameMode::mode != new_mode ) {
              
              if (GameMode::currentMode!=NULL){
                     delete GameMode::currentMode;
              }
              GameMode::prevmode = GameMode::mode;

              switch(new_mode){
                     case SPLASH:
                            GameMode::currentMode = new SplashScreen();
                            break;               
                     case GAME_TYPE_SELECT:
                            GameMode::currentMode = new GameTypeSelect();
                            break;
                     case CREDITS:
                            GameMode::currentMode = new Credits();
                            break;
                     case CREDITS_TRANS:
                            GameMode::currentMode = new CreditsTrans();
                            break;
                     case CONFIGURATION:
                            GameMode::currentMode = new Configuration();
                            break;
                     case RACE_SELECT:
                            GameMode::currentMode = new RaceSelect();
                            break;
                     case LOADING:
                            GameMode::currentMode = new Loading();
                            break;
                     case INTRO:
                            GameMode::currentMode = new Intro();
                            break;
                     case RACING:
                            GameMode::currentMode = new Racing();
                            break;
                     case PAUSED:
                            GameMode::currentMode = new Paused();
                            break;
                     case GAME_OVER:
                            GameMode::currentMode = new GameOver();
                            break;               
                     case RESET:
                            GameMode::currentMode = new Reset();
                            break;
                     case EVENT_SELECT:
                            GameMode::currentMode = new EventSelect();
                            break;
                     case CONFIG_GRAPHICS:
                            GameMode::currentMode = new GraphicsConfig();
                            break;
                     case CONFIG_VIDEO:
                            GameMode::currentMode = new VideoConfig();
                            break;
                     case CONFIG_AUDIO:
                            GameMode::currentMode = new AudioConfig();
                            break;
                     case CONFIG_KEYBOARD:
                            GameMode::currentMode = new KeyboardConfig();
                            break;
                     case CONFIG_JOYSTICK:
                            GameMode::currentMode = new JoystickConfig();
                            break;
                     case EVENT_RACE_SELECT:
                            GameMode::currentMode = new EventRaceSelect();
                            break;
                     case BENCHMARK:
                            GameMode::currentMode = new Benchmark();
                            break;
                     case HIGHSCORE:
                            GameMode::currentMode = new HighscoreShow();
                            break;
                     default:{}
                            //todo: add fallback               
              }
              
              GameMode::mode = new_mode;
       
              // Reset time step clock so that there isn't a sudden
              //  jump when we start the new mode 
              gameMgr->resetTimeStep();
       }
       
       gameMgr->updateTimeStep();
       
       if ( Benchmark::getTimeStep() >0.0 ){
              GameMode::currentMode->loop(Benchmark::getTimeStep());
       }else{ 
              GameMode::currentMode->loop( gameMgr->getTimeStep() );
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_game_mode ( game_mode_t  mode)

Definition at line 64 of file loop.cpp.

{
    new_mode = mode;
}

Variable Documentation

Definition at line 62 of file loop.cpp.