started input module by splitting sdldrv in more logical parts

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3290 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-03-23 14:55:23 +00:00
parent a357cea512
commit e7905e0811
10 changed files with 245 additions and 202 deletions

View File

@ -21,7 +21,7 @@
#include "gui/race_gui.hpp"
#include "input.hpp"
#include "sdldrv.hpp"
#include "input_manager.hpp"
#include "user_config.hpp"
#include "race_manager.hpp"
#include "material_manager.hpp"

View File

@ -3,7 +3,7 @@
#include "gui/engine.hpp"
#include "gui/widget.hpp"
#include "gui/screen.hpp"
#include "sdldrv.hpp"
#include "input_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "race_manager.hpp"
#include "network/network_manager.hpp"
@ -166,7 +166,7 @@ namespace StateManager
317 // Might still be set from a previous challenge
318 race_manager->setCoinTarget(0);
inputDriver->setMode(SDLDriver::INGAME);
input_manager->setMode(InputManager::INGAME);
race_manager->setLocalKartInfo(0, argv[i+1]);
@ -198,7 +198,7 @@ namespace StateManager
void pushMenu(std::string name)
{
inputDriver->setMode(SDLDriver::MENU);
input_manager->setMode(InputManager::MENU);
g_menu_stack.push_back(name);
g_game_mode = false;
GUIEngine::switchToScreen(name.c_str());
@ -220,7 +220,7 @@ namespace StateManager
void resetAndGoToMenu(std::string name)
{
inputDriver->setMode(SDLDriver::MENU);
input_manager->setMode(InputManager::MENU);
g_menu_stack.clear();
g_menu_stack.push_back(name);
g_game_mode = false;
@ -233,7 +233,7 @@ namespace StateManager
g_menu_stack.push_back("race");
g_game_mode = true;
GUIEngine::clear();
inputDriver->setMode(SDLDriver::INGAME);
input_manager->setMode(InputManager::INGAME);
}
bool isGameState()

View File

@ -22,6 +22,8 @@
953EAAB20F30A4410000D57D /* triangle_mesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 953EAAB10F30A4410000D57D /* triangle_mesh.cpp */; };
953EAAB60F30A4650000D57D /* translation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 953EAAB50F30A4650000D57D /* translation.cpp */; };
953F038C0F6C880D00C77FE2 /* state_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 953F038B0F6C880D00C77FE2 /* state_manager.cpp */; };
95A116BF0F77D3BB00B18B3D /* input_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95A116BD0F77D3BB00B18B3D /* input_manager.cpp */; };
95A117350F77D7BE00B18B3D /* sdl_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95A117330F77D7BE00B18B3D /* sdl_manager.cpp */; };
95C1E3F20F699079005D33E6 /* race_gui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C1E3F10F699079005D33E6 /* race_gui.cpp */; };
95C1E4000F699427005D33E6 /* font.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C1E3FF0F699427005D33E6 /* font.cpp */; };
95C2B1F70F296546000D3E5D /* actionmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C2AC210F296540000D3E5D /* actionmap.cpp */; };
@ -203,7 +205,6 @@
95C2B5710F296547000D3E5D /* replay_recorder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C2B1A40F296545000D3E5D /* replay_recorder.cpp */; };
95C2B5760F296547000D3E5D /* default_robot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C2B1AB0F296545000D3E5D /* default_robot.cpp */; };
95C2B5780F296547000D3E5D /* track_info.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C2B1AF0F296545000D3E5D /* track_info.cpp */; };
95C2B57B0F296547000D3E5D /* sdldrv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C2B1B30F296545000D3E5D /* sdldrv.cpp */; };
95C2B5860F296547000D3E5D /* static_ssg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C2B1BF0F296545000D3E5D /* static_ssg.cpp */; };
95C2B5870F296547000D3E5D /* stk_config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C2B1C10F296545000D3E5D /* stk_config.cpp */; };
95C2B5910F296547000D3E5D /* track.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C2B1CF0F296545000D3E5D /* track.cpp */; };
@ -270,6 +271,10 @@
953EAAB50F30A4650000D57D /* translation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = translation.cpp; path = ../../utils/translation.cpp; sourceTree = SOURCE_ROOT; };
953F038B0F6C880D00C77FE2 /* state_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = state_manager.cpp; path = ../../gui/state_manager.cpp; sourceTree = SOURCE_ROOT; };
953F038E0F6C8AD800C77FE2 /* state_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = state_manager.hpp; path = ../../gui/state_manager.hpp; sourceTree = SOURCE_ROOT; };
95A116BD0F77D3BB00B18B3D /* input_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = input_manager.cpp; path = games/supertuxkart/src/input_manager.cpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
95A116BE0F77D3BB00B18B3D /* input_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = input_manager.hpp; path = games/supertuxkart/src/input_manager.hpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
95A117330F77D7BE00B18B3D /* sdl_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sdl_manager.cpp; path = games/supertuxkart/src/sdl_manager.cpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
95A117340F77D7BE00B18B3D /* sdl_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sdl_manager.hpp; path = games/supertuxkart/src/sdl_manager.hpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
95C1E3EB0F698F23005D33E6 /* race_gui.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = race_gui.hpp; path = ../../gui/race_gui.hpp; sourceTree = SOURCE_ROOT; };
95C1E3F10F699079005D33E6 /* race_gui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = race_gui.cpp; path = ../../gui/race_gui.cpp; sourceTree = SOURCE_ROOT; };
95C1E3FF0F699427005D33E6 /* font.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = font.cpp; path = ../../gui/font.cpp; sourceTree = SOURCE_ROOT; };
@ -696,8 +701,6 @@
95C2B1AC0F296545000D3E5D /* default_robot.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = default_robot.hpp; path = ../../robots/default_robot.hpp; sourceTree = SOURCE_ROOT; };
95C2B1AF0F296545000D3E5D /* track_info.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = track_info.cpp; path = ../../robots/track_info.cpp; sourceTree = SOURCE_ROOT; };
95C2B1B00F296545000D3E5D /* track_info.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = track_info.hpp; path = ../../robots/track_info.hpp; sourceTree = SOURCE_ROOT; };
95C2B1B30F296545000D3E5D /* sdldrv.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sdldrv.cpp; path = ../../sdldrv.cpp; sourceTree = SOURCE_ROOT; };
95C2B1B40F296545000D3E5D /* sdldrv.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sdldrv.hpp; path = ../../sdldrv.hpp; sourceTree = SOURCE_ROOT; };
95C2B1BF0F296545000D3E5D /* static_ssg.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = static_ssg.cpp; path = ../../static_ssg.cpp; sourceTree = SOURCE_ROOT; };
95C2B1C00F296545000D3E5D /* static_ssg.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = static_ssg.hpp; path = ../../static_ssg.hpp; sourceTree = SOURCE_ROOT; };
95C2B1C10F296545000D3E5D /* stk_config.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = stk_config.cpp; path = ../../stk_config.cpp; sourceTree = SOURCE_ROOT; };
@ -1252,6 +1255,8 @@
95C2AEDA0F296542000D3E5D /* highscores.hpp */,
95C2AEDC0F296542000D3E5D /* history.cpp */,
95C2AEDD0F296542000D3E5D /* history.hpp */,
95A116BD0F77D3BB00B18B3D /* input_manager.cpp */,
95A116BE0F77D3BB00B18B3D /* input_manager.hpp */,
95C2B0EF0F296545000D3E5D /* input.hpp */,
95C2B0F00F296545000D3E5D /* isect.cpp */,
95C2B0F10F296545000D3E5D /* isect.hpp */,
@ -1268,8 +1273,6 @@
95C2B18A0F296545000D3E5D /* player.hpp */,
95C2B1930F296545000D3E5D /* race_manager.cpp */,
95C2B1940F296545000D3E5D /* race_manager.hpp */,
95C2B1B30F296545000D3E5D /* sdldrv.cpp */,
95C2B1B40F296545000D3E5D /* sdldrv.hpp */,
95C2B1BF0F296545000D3E5D /* static_ssg.cpp */,
95C2B1C00F296545000D3E5D /* static_ssg.hpp */,
95C2B1C10F296545000D3E5D /* stk_config.cpp */,
@ -1277,6 +1280,8 @@
95C2B1DB0F296546000D3E5D /* user_config.cpp */,
95C2B1DC0F296546000D3E5D /* user_config.hpp */,
95C2B1DE0F296546000D3E5D /* user_pointer.hpp */,
95A117330F77D7BE00B18B3D /* sdl_manager.cpp */,
95A117340F77D7BE00B18B3D /* sdl_manager.hpp */,
);
name = src;
path = ../..;
@ -2721,7 +2726,6 @@
95C2B5710F296547000D3E5D /* replay_recorder.cpp in Sources */,
95C2B5760F296547000D3E5D /* default_robot.cpp in Sources */,
95C2B5780F296547000D3E5D /* track_info.cpp in Sources */,
95C2B57B0F296547000D3E5D /* sdldrv.cpp in Sources */,
95C2B5860F296547000D3E5D /* static_ssg.cpp in Sources */,
95C2B5870F296547000D3E5D /* stk_config.cpp in Sources */,
95C2B5910F296547000D3E5D /* track.cpp in Sources */,
@ -2756,6 +2760,8 @@
95C1E3F20F699079005D33E6 /* race_gui.cpp in Sources */,
95C1E4000F699427005D33E6 /* font.cpp in Sources */,
953F038C0F6C880D00C77FE2 /* state_manager.cpp in Sources */,
95A116BF0F77D3BB00B18B3D /* input_manager.cpp in Sources */,
95A117350F77D7BE00B18B3D /* sdl_manager.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -17,7 +17,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sdldrv.hpp"
#include "input_manager.hpp"
#include <map>
#include <vector>
@ -31,91 +31,41 @@
#include "input.hpp"
#include "actionmap.hpp"
#include "user_config.hpp"
#include "material_manager.hpp"
#include "main_loop.hpp"
#include "player.hpp"
#include "user_config.hpp"
#include "items/item_manager.hpp"
#include "items/powerup_manager.hpp"
#include "items/attachment_manager.hpp"
#include "items/projectile_manager.hpp"
#include "karts/kart_properties_manager.hpp"
#include "gui/font.hpp"
#include "gui/race_gui.hpp"
#include "gui/engine.hpp"
#include "gui/state_manager.hpp"
#include "gui/engine.hpp"
#include "race_manager.hpp"
#include "modes/world.hpp"
#include "karts/kart.hpp"
#include "history.hpp"
#include "gui/race_gui.hpp"
#include "sdl_manager.hpp"
#define DEADZONE_MOUSE 150
#define DEADZONE_MOUSE_SENSE 200
#define DEADZONE_JOYSTICK 2000
#define MULTIPLIER_MOUSE 750
SDLDriver *inputDriver;
InputManager *input_manager;
//-----------------------------------------------------------------------------
/** Initialise SDL.
*/
SDLDriver::SDLDriver()
: m_sensed_input(0), m_action_map(0), m_main_surface(0), m_flags(0), m_stick_infos(0),
InputManager::InputManager()
: m_sensed_input(0), m_action_map(0), m_stick_infos(0),
m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0)
{
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_TIMER) < 0)
{
fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
exit(1);
}
m_flags = SDL_OPENGL | SDL_HWSURFACE;
//detect if previous resolution crashed STK
if (user_config->m_crashed)
{
//STK crashed last time
user_config->m_crashed = false; //reset flag
// set window mode as a precaution
user_config->m_fullscreen = false;
// blacklist the res if not already done
std::ostringstream o;
o << user_config->m_width << "x" << user_config->m_height;
std::string res = o.str();
if (std::find(user_config->m_blacklist_res.begin(),
user_config->m_blacklist_res.end(),res) == user_config->m_blacklist_res.end())
{
user_config->m_blacklist_res.push_back (o.str());
}
//use prev screen res settings if available
if (user_config->m_width != user_config->m_prev_width
|| user_config->m_height != user_config->m_prev_height)
{
user_config->m_width = user_config->m_prev_width;
user_config->m_height = user_config->m_prev_height;
}
else //set 'safe' resolution to return to
{
user_config->m_width = user_config->m_prev_width = 800;
user_config->m_height = user_config->m_prev_height = 600;
}
}
if(user_config->m_fullscreen)
m_flags |= SDL_FULLSCREEN;
setVideoMode(false);
SDL_JoystickEventState(SDL_ENABLE);
initStickInfos();
// Get into menu mode initially.
setMode(MENU);
}
// -----------------------------------------------------------------------------
/** Initialises joystick/gamepad info.
*/
void SDLDriver::initStickInfos()
void InputManager::initStickInfos()
{
int nextIndex = 0;
@ -201,102 +151,10 @@ void SDLDriver::initStickInfos()
delete si;
} // initStickInfos
//-----------------------------------------------------------------------------
/** Show cursor.
*/
void SDLDriver::showPointer()
{
SDL_ShowCursor(SDL_ENABLE);
} // showPointer
//-----------------------------------------------------------------------------
/** Hide cursor.
*/
void SDLDriver::hidePointer()
{
SDL_ShowCursor(SDL_DISABLE);
} // hidePointer
//-----------------------------------------------------------------------------
/** Toggles to fullscreen mode.
*/
void SDLDriver::toggleFullscreen(bool resetTextures)
{
user_config->m_fullscreen = !user_config->m_fullscreen;
m_flags = SDL_OPENGL | SDL_HWSURFACE;
if(user_config->m_fullscreen)
{
m_flags |= SDL_FULLSCREEN;
if(StateManager::isGameState())
showPointer();
// Store settings in user config file in case new video mode
// causes a crash
user_config->m_crashed = true; //set flag.
user_config->saveConfig();
}
else if(StateManager::isGameState())
hidePointer();
setVideoMode(resetTextures);
} // toggleFullscreen
// -----------------------------------------------------------------------------
/** Sets the video mode. If 8 bit colours are not supported, 5 bits are used;
* and if this doesn't work, alpha is disabled, too - before giving up. So
* STK should now work with 16 bit windows.
* \param resetTextures Forces all textures to be reloaded after a change of
* resolution. Necessary with windows and Macs OpenGL
* versions.
*/
void SDLDriver::setVideoMode(bool resetTextures)
{
#if defined(WIN32) || defined(__APPLE__)
if(resetTextures)
{
// FIXME: clear texture cache here
// Windows needs to reload all textures, display lists, ... which means
// that all models have to be reloaded. So first, free all textures,
// models, then reload the textures from materials.dat, then reload
// all models, textures etc.
// startScreen -> removeTextures();
attachment_manager -> removeTextures();
projectile_manager -> removeTextures();
item_manager -> removeTextures();
kart_properties_manager -> removeTextures();
powerup_manager -> removeTextures();
material_manager->reInit();
powerup_manager -> loadPowerups();
kart_properties_manager -> loadKartData();
item_manager -> loadDefaultItems();
projectile_manager -> loadData();
attachment_manager -> loadModels();
// startScreen -> installMaterial();
//FIXME: the font reinit funcs should be inside the font class
//Reinit fonts
delete_fonts();
init_fonts();
//TODO: this function probably will get deleted in the future; if
//so, the widget_manager.hpp include has no other reason to be here.
//widget_manager->reloadFonts();
}
#endif
} // setVideoMode
//-----------------------------------------------------------------------------
/** Destructor. Frees all data structures.
*/
SDLDriver::~SDLDriver()
InputManager::~InputManager()
{
const int NUM_STICKS = SDL_NumJoysticks();
for (int i = 0; i < NUM_STICKS; i++)
@ -305,9 +163,8 @@ SDLDriver::~SDLDriver()
delete [] m_stick_infos;
// FIXME LEAK: delete m_action_map if defined
SDL_FreeSurface(m_main_surface);
} // ~SDLDriver
} // ~InputManager
#define MAX_VALUE 32768
@ -397,7 +254,7 @@ void handleGameAction(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:
inputDriver->toggleFullscreen(false); // 0: do not reset textures
SDLManager::toggleFullscreen(false); // 0: do not reset textures
// Fall through to put the game into pause mode.
#endif
case GA_LEAVE_RACE:
@ -430,7 +287,7 @@ void handleGameAction(GameAction ga, int value)
* Note: It is the obligation of the called menu to switch of the sense mode.
*
*/
void SDLDriver::input(Input::InputType type, int id0, int id1, int id2,
void InputManager::input(Input::InputType type, int id0, int id1, int id2,
int value)
{
@ -548,7 +405,7 @@ void SDLDriver::input(Input::InputType type, int id0, int id1, int id2,
* flexibility (= treat 4 directions as four buttons).
*
*/
void SDLDriver::input()
void InputManager::input()
{
SDL_Event ev;
/* Logical joystick index that is reported to the higher game APIs which
@ -749,7 +606,7 @@ void SDLDriver::input()
*
* It is wrong to call it when not in input sensing mode anymore.
*/
Input &SDLDriver::getSensedInput()
Input &InputManager::getSensedInput()
{
assert (m_mode >= INPUT_SENSE_PREFER_AXIS &&
m_mode <= INPUT_SENSE_PREFER_BUTTON );
@ -763,7 +620,7 @@ Input &SDLDriver::getSensedInput()
//-----------------------------------------------------------------------------
/** Queries the input driver whether it is in the given expected mode.
*/
bool SDLDriver::isInMode(InputDriverMode expMode)
bool InputManager::isInMode(InputDriverMode expMode)
{
return m_mode == expMode;
} // isInMode
@ -789,7 +646,7 @@ bool SDLDriver::isInMode(InputDriverMode expMode)
* once per application instance. It is the state the input driver is first.
*
*/
void SDLDriver::setMode(InputDriverMode new_mode)
void InputManager::setMode(InputDriverMode new_mode)
{
switch (new_mode)
{
@ -806,7 +663,7 @@ void SDLDriver::setMode(InputDriverMode new_mode)
// supresses to the notification of them as an input.
m_mouse_val_x = m_mouse_val_y = 0;
showPointer();
SDLManager::showPointer();
// Fall through expected.
case BOOTSTRAP:
@ -822,7 +679,7 @@ void SDLDriver::setMode(InputDriverMode new_mode)
case INPUT_SENSE_PREFER_BUTTON:
// Leaving input sense mode.
showPointer();
SDLManager::showPointer();
// The order is deliberate just in case someone starts to make
// STK multithreaded: m_sensed_input must not be 0 when
@ -838,7 +695,7 @@ void SDLDriver::setMode(InputDriverMode new_mode)
SDL_EnableUNICODE(SDL_DISABLE);
showPointer();
SDLManager::showPointer();
m_mode = MENU;
@ -860,7 +717,7 @@ void SDLDriver::setMode(InputDriverMode new_mode)
// Installs the action map for the ingame mode.
m_action_map = user_config->newIngameActionMap();
hidePointer();
SDLManager::hidePointer();
m_mode = INGAME;
@ -877,7 +734,7 @@ void SDLDriver::setMode(InputDriverMode new_mode)
m_max_sensed_type = Input::IT_NONE;
m_sensed_input = new Input();
hidePointer();
SDLManager::hidePointer();
m_mode = new_mode;
@ -888,7 +745,7 @@ void SDLDriver::setMode(InputDriverMode new_mode)
SDL_EnableUNICODE(SDL_ENABLE);
hidePointer();
SDLManager::hidePointer();
m_mode = LOWLEVEL;
@ -903,7 +760,7 @@ void SDLDriver::setMode(InputDriverMode new_mode)
/** Constructor for StickInfo.
* \param sdlIndex Index of stick.
*/
SDLDriver::StickInfo::StickInfo(int sdlIndex)
InputManager::StickInfo::StickInfo(int sdlIndex)
{
m_sdlJoystick = SDL_JoystickOpen(sdlIndex);
@ -923,7 +780,7 @@ SDLDriver::StickInfo::StickInfo(int sdlIndex)
// -----------------------------------------------------------------------------
/** Destructor for StickInfo.
*/
SDLDriver::StickInfo::~StickInfo()
InputManager::StickInfo::~StickInfo()
{
delete m_prevAxisDirections;

View File

@ -1,4 +1,4 @@
// $Id: sdldrv.hpp 694 2006-08-29 07:42:36Z hiker $
// $Id: input_manager.hpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004-2006 Steve Baker <sjbaker1@airmail.net>
@ -17,8 +17,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_SDLDRV_H
#define HEADER_SDLDRV_H
#ifndef HEADER_INPUT_MANAGER_H
#define HEADER_INPUT_MANAGER_H
#include <string>
#include <vector>
@ -31,7 +31,7 @@ class ActionMap;
/** Class to handle SDL.
*/
class SDLDriver
class InputManager
{
public:
enum InputDriverMode {
@ -61,8 +61,6 @@ private:
int m_max_sensed_input;
Input::InputType m_max_sensed_type;
ActionMap *m_action_map;
SDL_Surface *m_main_surface;
long m_flags;
StickInfo **m_stick_infos;
InputDriverMode m_mode;
@ -72,21 +70,17 @@ private:
*/
int m_mouse_val_x, m_mouse_val_y;
void showPointer();
void hidePointer();
void input(Input::InputType, int, int, int, int);
public:
SDLDriver();
~SDLDriver();
InputManager();
~InputManager();
void initStickInfos();
void toggleFullscreen(bool resetTextures=1);
void setVideoMode(bool resetTextures=1);
void input();
void setMode(InputDriverMode);
bool isInMode(InputDriverMode);
Input &getSensedInput();
};
extern SDLDriver *inputDriver;
extern InputManager *input_manager;
#endif

View File

@ -22,7 +22,7 @@
#include "history.hpp"
#include "player.hpp"
#include "sdldrv.hpp"
#include "input_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
#include "graphics/camera.hpp"

View File

@ -44,11 +44,12 @@
#include <sstream>
#include <algorithm>
#include "sdl_manager.hpp"
#include "user_config.hpp"
#include "race_manager.hpp"
#include "main_loop.hpp"
#include "material_manager.hpp"
#include "sdldrv.hpp"
#include "input_manager.hpp"
#include "callback_manager.hpp"
#include "history.hpp"
#include "stk_config.hpp"
@ -543,7 +544,11 @@ int main(int argc, char *argv[] )
}
}
inputDriver = new SDLDriver ();
SDLManager::init();
input_manager = new InputManager ();
// Get into menu mode initially.
input_manager->setMode(InputManager::MENU);
main_loop = new MainLoop();
// loadMaterials needs ssgLoadTextures (internally), which can
@ -639,7 +644,7 @@ int main(int argc, char *argv[] )
if (user_config->m_crashed) user_config->m_crashed = false;
user_config->saveConfig();
}
if(inputDriver) delete inputDriver; // if early crash avoid delete NULL
if(input_manager) delete input_manager; // if early crash avoid delete NULL
if (user_config && user_config->m_log_errors) //close logfiles
{

View File

@ -22,7 +22,7 @@
#include <SDL/SDL.h>
#include <assert.h>
#include "history.hpp"
#include "sdldrv.hpp"
#include "input_manager.hpp"
#include "material_manager.hpp"
#include "race_manager.hpp"
#include "audio/sound_manager.hpp"
@ -76,7 +76,7 @@ void MainLoop::run()
float dt;
while(!m_abort)
{
inputDriver->input();
input_manager->input();
m_prev_time = m_curr_time;

168
src/sdl_manager.cpp Normal file
View File

@ -0,0 +1,168 @@
#include "sdl_manager.hpp"
#include <SDL/SDL.h>
#include "user_config.hpp"
#include "input_manager.hpp"
#include "gui/state_manager.hpp"
#include "history.hpp"
#include "items/item_manager.hpp"
#include "items/powerup_manager.hpp"
#include "items/attachment_manager.hpp"
#include "items/projectile_manager.hpp"
#include "karts/kart_properties_manager.hpp"
#include "material_manager.hpp"
#include "gui/font.hpp"
#include "gui/race_gui.hpp"
#include "gui/engine.hpp"
#include <iostream>
#include <sstream>
namespace SDLManager
{
long m_flags;
void init()
{
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_TIMER) < 0)
{
fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
exit(1);
}
m_flags = SDL_OPENGL | SDL_HWSURFACE;
//detect if previous resolution crashed STK
if (user_config->m_crashed)
{
//STK crashed last time
user_config->m_crashed = false; //reset flag
// set window mode as a precaution
user_config->m_fullscreen = false;
// blacklist the res if not already done
std::ostringstream o;
o << user_config->m_width << "x" << user_config->m_height;
std::string res = o.str();
if (std::find(user_config->m_blacklist_res.begin(),
user_config->m_blacklist_res.end(),res) == user_config->m_blacklist_res.end())
{
user_config->m_blacklist_res.push_back (o.str());
}
//use prev screen res settings if available
if (user_config->m_width != user_config->m_prev_width
|| user_config->m_height != user_config->m_prev_height)
{
user_config->m_width = user_config->m_prev_width;
user_config->m_height = user_config->m_prev_height;
}
else //set 'safe' resolution to return to
{
user_config->m_width = user_config->m_prev_width = 800;
user_config->m_height = user_config->m_prev_height = 600;
}
}
if(user_config->m_fullscreen)
m_flags |= SDL_FULLSCREEN;
setVideoMode(false);
SDL_JoystickEventState(SDL_ENABLE);
}
//-----------------------------------------------------------------------------
/** Show cursor.
*/
void showPointer()
{
SDL_ShowCursor(SDL_ENABLE);
} // showPointer
//-----------------------------------------------------------------------------
/** Hide cursor.
*/
void hidePointer()
{
SDL_ShowCursor(SDL_DISABLE);
} // hidePointer
//-----------------------------------------------------------------------------
/** Toggles to fullscreen mode.
*/
void toggleFullscreen(bool resetTextures)
{
user_config->m_fullscreen = !user_config->m_fullscreen;
m_flags = SDL_OPENGL | SDL_HWSURFACE;
if(user_config->m_fullscreen)
{
m_flags |= SDL_FULLSCREEN;
if(StateManager::isGameState())
showPointer();
// Store settings in user config file in case new video mode
// causes a crash
user_config->m_crashed = true; //set flag.
user_config->saveConfig();
}
else if(StateManager::isGameState())
hidePointer();
setVideoMode(resetTextures);
} // toggleFullscreen
// -----------------------------------------------------------------------------
/** Sets the video mode. If 8 bit colours are not supported, 5 bits are used;
* and if this doesn't work, alpha is disabled, too - before giving up. So
* STK should now work with 16 bit windows.
* \param resetTextures Forces all textures to be reloaded after a change of
* resolution. Necessary with windows and Macs OpenGL
* versions.
*/
void setVideoMode(bool resetTextures)
{
#if defined(WIN32) || defined(__APPLE__)
if(resetTextures)
{
// FIXME: clear texture cache here
// Windows needs to reload all textures, display lists, ... which means
// that all models have to be reloaded. So first, free all textures,
// models, then reload the textures from materials.dat, then reload
// all models, textures etc.
// startScreen -> removeTextures();
attachment_manager -> removeTextures();
projectile_manager -> removeTextures();
item_manager -> removeTextures();
kart_properties_manager -> removeTextures();
powerup_manager -> removeTextures();
material_manager->reInit();
powerup_manager -> loadPowerups();
kart_properties_manager -> loadKartData();
item_manager -> loadDefaultItems();
projectile_manager -> loadData();
attachment_manager -> loadModels();
// startScreen -> installMaterial();
//FIXME: the font reinit funcs should be inside the font class
//Reinit fonts
delete_fonts();
init_fonts();
//TODO: this function probably will get deleted in the future; if
//so, the widget_manager.hpp include has no other reason to be here.
//widget_manager->reloadFonts();
}
#endif
} // setVideoMode
// SDL_FreeSurface(m_main_surface); ?
// the previous sdl driver declared m_main_surface but it was always set to NULL afaik
}

13
src/sdl_manager.hpp Normal file
View File

@ -0,0 +1,13 @@
#ifndef SDL_MANAGER_HPP
#define SDL_MANAGER_HPP
namespace SDLManager
{
void init();
void setVideoMode(bool resetTextures);
void toggleFullscreen(bool resetTextures);
void showPointer();
void hidePointer();
}
#endif