- make sdl driver a class

- fix all uses of the new class
 - fixed a few spelling mistakes
 - config is now saved upon leaving options menu (not when the game is ended)



git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1676 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
thebohemian 2008-03-30 15:18:19 +00:00
parent b1faf872b3
commit 122b22a77e
11 changed files with 83 additions and 59 deletions

View File

@ -66,7 +66,7 @@ void GameManager::run()
m_curr_time = SDL_GetTicks();
while(!m_abort)
{
sdl_input();
inputDriver->input();
m_prev_time = m_curr_time;
m_curr_time = SDL_GetTicks();

View File

@ -66,7 +66,7 @@ ConfigDisplay::ConfigDisplay()
}
else if( user_config->m_prev_windowed && user_config->m_fullscreen )
{
drv_toggleFullscreen();
inputDriver->toggleFullscreen();
user_config->m_prev_windowed = false;
user_config->m_crashed = false;
user_config->saveConfig();
@ -194,7 +194,7 @@ void ConfigDisplay::select()
switch ( widget_manager->getSelectedWgt() )
{
case WTOK_FULLSCREEN:
drv_toggleFullscreen();
inputDriver->toggleFullscreen();
if( user_config->m_fullscreen )
{
menu_manager->pushMenu( MENUID_RESOLUTION_CONFIRM_WIN );
@ -346,8 +346,7 @@ void ConfigDisplay::changeResolution(int width, int height/*, bool reverse*/)
user_config->saveConfig();
}
//FIXME: setVideoMode() should be put inside a namespace or something
setVideoMode();
inputDriver->setVideoMode();
glViewport(0,0,user_config->m_width, user_config->m_height);
}

View File

@ -110,7 +110,7 @@ void DisplayResConfirm::select()
SDL_RemoveTimer(m_timer);
if (FROM_WINDOW)
{
drv_toggleFullscreen();
inputDriver->toggleFullscreen();
user_config->m_crashed = false;
user_config->saveConfig();
}
@ -140,7 +140,7 @@ void DisplayResConfirm::countdown()
if( FROM_WINDOW )
{
drv_toggleFullscreen();
inputDriver->toggleFullscreen();
user_config->m_prev_windowed = false;
user_config->m_crashed = false;
user_config->saveConfig();
@ -161,7 +161,7 @@ void DisplayResConfirm::handle(GameAction ga, int value)
SDL_RemoveTimer(m_timer);
if (FROM_WINDOW)
{
drv_toggleFullscreen();
inputDriver->toggleFullscreen();
user_config->m_crashed = false;
user_config->saveConfig();
}

View File

@ -129,7 +129,7 @@ void MenuManager::update()
&& m_current_menu == m_RaceGUI)
{
m_RaceGUI = 0;
drv_setMode(MENU);
inputDriver->setMode(MENU);
}
delete m_current_menu;
@ -180,7 +180,7 @@ void MenuManager::update()
m_current_menu= new NumPlayers();
break;
case MENUID_RACE:
drv_setMode(INGAME);
inputDriver->setMode(INGAME);
m_current_menu = new RaceGUI();
m_RaceGUI = m_current_menu;
break;

View File

@ -21,6 +21,7 @@
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
#include "user_config.hpp"
enum WidgetTokens
{
@ -106,6 +107,9 @@ void Options::select()
menu_manager->pushMenu(MENUID_CONFIG_SOUND);
break;
case WTOK_BACK:
// Make config changes permanent.
user_config->saveConfig();
menu_manager->popMenu();
break;
default:

View File

@ -129,7 +129,7 @@ PlayerControls::select()
// Switch to typing in the player's name.
widget_manager->setWgtText(WTOK_PLYR_NAME1, (m_name + "<").c_str());
drv_setMode(LOWLEVEL);
inputDriver->setMode(LOWLEVEL);
break;
case WTOK_QUIT:
@ -151,7 +151,7 @@ PlayerControls::select()
m_edit_action = static_cast<KartAction>(selected - WTOK_LEFT);
widget_manager->setWgtText(selected, _("Press key"));
drv_setMode(INPUT_SENSE);
inputDriver->setMode(INPUT_SENSE);
break;
}
@ -228,10 +228,10 @@ void PlayerControls::handle(GameAction ga, int value)
// Updates the configuration with the newly sensed input.
user_config->setInput(m_player_index,
m_edit_action,
drv_getSensedInput());
inputDriver->getSensedInput());
// Fall through to recover the widget labels.
case GA_SENSE_CANCEL:
drv_setMode(MENU);
inputDriver->setMode(MENU);
// Refresh all key labels since they mave changed because of
// conflicting bindings.
@ -240,7 +240,7 @@ void PlayerControls::handle(GameAction ga, int value)
case GA_ENTER:
// If the user is typing her name this will be finished at this
// point.
if (drv_isInMode(LOWLEVEL))
if (inputDriver->isInMode(LOWLEVEL))
{
// Prevents zero-length names.
if (m_name.length() == 0)
@ -248,7 +248,7 @@ void PlayerControls::handle(GameAction ga, int value)
user_config->m_player[m_player_index].setName(m_name);
widget_manager->setWgtText(WTOK_PLYR_NAME1, m_name.c_str());
drv_setMode(MENU);
inputDriver->setMode(MENU);
}
else
select();
@ -256,12 +256,12 @@ void PlayerControls::handle(GameAction ga, int value)
case GA_LEAVE:
// If the user is typing her name this will be cancelled at this
// point.
if (drv_isInMode(LOWLEVEL))
if (inputDriver->isInMode(LOWLEVEL))
{
m_name = user_config->m_player[m_player_index].getName();
widget_manager->setWgtText(WTOK_PLYR_NAME1, m_name.c_str());
drv_setMode(MENU);
inputDriver->setMode(MENU);
break;
}
// Fall through to reach the usual GA_LEAVE code (leave menu).

View File

@ -212,7 +212,7 @@ RaceGUI::handle(GameAction ga, int value)
// to reload all textures, display lists etc. Fullscreen can
// be toggled from the main menu (options->display).
case GA_TOGGLE_FULLSCREEN:
drv_toggleFullscreen(false); // 0: do not reset textures
inputDriver->toggleFullscreen(false); // 0: do not reset textures
// Fall through to put the game into pause mode.
#endif
case GA_LEAVE_RACE:

View File

@ -434,7 +434,7 @@ int main(int argc, char *argv[] )
}
//FIXME: this needs a better organization
drv_init();
inputDriver = new SDLDriver ();
ssgInit () ;
game_manager = new GameManager ();
@ -515,10 +515,8 @@ int main(int argc, char *argv[] )
}
/* Program closing...*/
user_config->saveConfig();
drv_deinit();
delete inputDriver;
if (user_config->m_log_errors) //close logfiles
{

View File

@ -43,30 +43,18 @@
#include "gui/font.hpp"
#include "user_config.hpp"
Input *sensedInput = 0;
ActionMap *actionMap = 0;
SDL_Surface *mainSurface;
long flags;
StickInfo **stickInfos = 0;
InputDriverMode mode = BOOTSTRAP;
#define DEADZONE_MOUSE 150
#define DEADZONE_MOUSE_SENSE 200
#define DEADZONE_JOYSTICK 1000
#define MULTIPLIER_MOUSE 750
/** Helper values to store and track the relative mouse movements. If these
* values exceed the deadzone value the input is reported to the game. This
* Makes the mouse behave like an analog axis on a gamepad/joystick.
*/
int mouseValX = 0;
int mouseValY = 0;
SDLDriver *inputDriver;
//-----------------------------------------------------------------------------
void drv_init()
SDLDriver::SDLDriver()
: sensedInput(0), actionMap(0), mainSurface(0), flags(0), stickInfos(0),
mode(BOOTSTRAP), mouseValX(0), mouseValY(0)
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER);
@ -125,23 +113,24 @@ void drv_init()
SDL_WM_SetCaption("SuperTuxKart", NULL);
// Get into menu mode initially.
drv_setMode(MENU);
setMode(MENU);
}
//-----------------------------------------------------------------------------
void
showPointer()
SDLDriver::showPointer()
{
SDL_ShowCursor(SDL_ENABLE);
}
//-----------------------------------------------------------------------------
void
hidePointer()
SDLDriver::hidePointer()
{
SDL_ShowCursor(SDL_DISABLE);
}
//-----------------------------------------------------------------------------
void drv_toggleFullscreen(bool resetTextures)
void
SDLDriver::toggleFullscreen(bool resetTextures)
{
user_config->m_fullscreen = !user_config->m_fullscreen;
@ -167,7 +156,8 @@ void drv_toggleFullscreen(bool resetTextures)
}
//-----------------------------------------------------------------------------
void setVideoMode(bool resetTextures)
void
SDLDriver::setVideoMode(bool resetTextures)
{
//Is SDL_FreeSurface necessary? SDL wiki says not??
SDL_FreeSurface(mainSurface);
@ -215,7 +205,7 @@ void setVideoMode(bool resetTextures)
}
//-----------------------------------------------------------------------------
void drv_deinit()
SDLDriver::~SDLDriver()
{
const int NUM_STICKS = SDL_NumJoysticks();
for (int i=0;i<NUM_STICKS;i++)
@ -241,7 +231,8 @@ void drv_deinit()
* Note: It is the obligation of the called menu to switch of the sense mode.
*
*/
void input(InputType type, int id0, int id1, int id2, int value)
void
SDLDriver::input(InputType type, int id0, int id1, int id2, int value)
{
BaseGUI* menu = menu_manager->getCurrentMenu();
@ -296,7 +287,8 @@ void input(InputType type, int id0, int id1, int id2, int value)
* flexibility (= treat 4 directions as four buttons).
*
*/
void sdl_input()
void
SDLDriver::input()
{
SDL_Event ev;
@ -459,7 +451,7 @@ void sdl_input()
* It is wrong to call it when not in input sensing mode anymore.
*/
Input &
drv_getSensedInput()
SDLDriver::getSensedInput()
{
assert (mode == INPUT_SENSE);
@ -473,7 +465,7 @@ drv_getSensedInput()
/** Queries the input driver whether it is in the given expected mode.
*/
bool
drv_isInMode(InputDriverMode expMode)
SDLDriver::isInMode(InputDriverMode expMode)
{
return mode == expMode;
}
@ -518,7 +510,7 @@ drv_isInMode(InputDriverMode expMode)
*
*/
void
drv_setMode(InputDriverMode newMode)
SDLDriver::setMode(InputDriverMode newMode)
{
switch (newMode)
{

View File

@ -44,18 +44,49 @@ struct StickInfo {
~StickInfo();
};
void drv_init();
void drv_deinit();
class SDLDriver
{
Input *sensedInput;
ActionMap *actionMap;
SDL_Surface *mainSurface;
long flags;
void drv_toggleFullscreen(bool resetTextures=1);
void setVideoMode(bool resetTextures=1);
StickInfo **stickInfos;
void sdl_input();
InputDriverMode mode;
/* Helper values to store and track the relative mouse movements. If these
* values exceed the deadzone value the input is reported to the game. This
* makes the mouse behave like an analog axis on a gamepad/joystick.
*/
int mouseValX;
int mouseValY;
void showPointer();
void hidePointer();
void input(InputType, int, int, int, int);
public:
SDLDriver();
~SDLDriver();
void drv_setMode(InputDriverMode);
bool drv_isInMode(InputDriverMode);
void toggleFullscreen(bool resetTextures=1);
void setVideoMode(bool resetTextures=1);
Input &drv_getSensedInput();
void input();
void setMode(InputDriverMode);
bool isInMode(InputDriverMode);
Input &getSensedInput();
};
extern SDLDriver *inputDriver;
#endif

View File

@ -24,7 +24,7 @@
#define PLAYERS 4
/* The following config versions are currently used:
0: the 0.2 release config file, without config-verison number
0: the 0.2 release config file, without config-version number
(so that defaults to 0)
1: Removed singleWindowMenu, newKeyboardStyle, oldStatusDisplay,
added config-version number