Back to index

extremetuxracer  0.5beta
Classes | Enumerations | Functions
loop.h File Reference
#include "SDL.h"
#include "translation.h"
#include "pp_types.h"
#include "gl_util.h"
#include "ppgltk/ui_mgr.h"
#include "ppgltk/ui_theme.h"
#include "render_util.h"
#include "game_config.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  GameMode

Enumerations

enum  game_mode_t {
  ALL_MODES = -2, NO_MODE = -1, SPLASH = 0, GAME_TYPE_SELECT,
  EVENT_SELECT, EVENT_RACE_SELECT, RACE_SELECT, LOADING,
  INTRO, RACING, GAME_OVER, PAUSED,
  RESET, CREDITS, CREDITS_TRANS, CONFIGURATION,
  CONFIG_GRAPHICS, CONFIG_VIDEO, CONFIG_AUDIO, CONFIG_KEYBOARD,
  CONFIG_JOYSTICK, QUIT, BENCHMARK, NUM_GAME_MODES,
  HIGHSCORE
}
 Game state. More...

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)

Enumeration Type Documentation

Game state.

Enumerator:
ALL_MODES 
NO_MODE 
SPLASH 
GAME_TYPE_SELECT 
EVENT_SELECT 
EVENT_RACE_SELECT 
RACE_SELECT 
LOADING 
INTRO 
RACING 
GAME_OVER 
PAUSED 
RESET 
CREDITS 
CREDITS_TRANS 
CONFIGURATION 
CONFIG_GRAPHICS 
CONFIG_VIDEO 
CONFIG_AUDIO 
CONFIG_KEYBOARD 
CONFIG_JOYSTICK 
QUIT 
BENCHMARK 
NUM_GAME_MODES 
HIGHSCORE 

Definition at line 39 of file loop.h.


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;
}