Commit 07909b06 authored by hybrid's avatar hybrid

Open and close joystick only at beginning and end of SDL driver. Added resize event handling.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1697 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5a6e3f8c
...@@ -92,6 +92,22 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) ...@@ -92,6 +92,22 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
createWindow(); createWindow();
} }
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
// we can name up to 256 different joysticks
const int numJoysticks = core::min_(SDL_NumJoysticks(), 256);
Joysticks.reallocate(numJoysticks);
for (int i=0; i<numJoysticks; ++i)
{
Joysticks.push_back(SDL_JoystickOpen(i));
char logString[256];
(void)sprintf(logString, "Found joystick %d, %d axes, %d buttons '%s'",
i, SDL_JoystickNumAxes(Joysticks[i]),
SDL_JoystickNumButtons(Joysticks[i]),
SDL_JoystickName(i));
os::Printer::log(logString, ELL_INFORMATION);
}
#endif
// create cursor control // create cursor control
CursorControl = new CCursorControl(this); CursorControl = new CCursorControl(this);
...@@ -106,6 +122,12 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) ...@@ -106,6 +122,12 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
//! destructor //! destructor
CIrrDeviceSDL::~CIrrDeviceSDL() CIrrDeviceSDL::~CIrrDeviceSDL()
{ {
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
const u32 numJoysticks = Joysticks.size();
for (u32 i=0; i<numJoysticks; ++i)
SDL_JoystickClose(Joysticks[i]);
#endif
// only free surfaces created by us // only free surfaces created by us
if (Screen && !CreationParams.WindowId) if (Screen && !CreationParams.WindowId)
SDL_FreeSurface(Screen); SDL_FreeSurface(Screen);
...@@ -282,6 +304,19 @@ bool CIrrDeviceSDL::run() ...@@ -282,6 +304,19 @@ bool CIrrDeviceSDL::run()
WindowMinimized = (SDL_event.active.gain!=1); WindowMinimized = (SDL_event.active.gain!=1);
break; break;
case SDL_VIDEORESIZE:
if ((SDL_event.resize.w != (int)Width) || (SDL_event.resize.h != (int)Height))
{
Width = SDL_event.resize.w;
Height = SDL_event.resize.h;
if (Screen)
SDL_FreeSurface(Screen);
Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );
if (VideoDriver)
VideoDriver->OnResize(core::dimension2d<s32>(Width, Height));
}
break;
case SDL_USEREVENT: case SDL_USEREVENT:
irrevent.EventType = irr::EET_USER_EVENT; irrevent.EventType = irr::EET_USER_EVENT;
irrevent.UserEvent.UserData1 = reinterpret_cast<s32>(SDL_event.user.data1); irrevent.UserEvent.UserData1 = reinterpret_cast<s32>(SDL_event.user.data1);
...@@ -302,14 +337,12 @@ bool CIrrDeviceSDL::run() ...@@ -302,14 +337,12 @@ bool CIrrDeviceSDL::run()
// update joystick states manually // update joystick states manually
SDL_JoystickUpdate(); SDL_JoystickUpdate();
// we can name up to 256 different joysticks
const int numJoysticks = core::min_(SDL_NumJoysticks(), 256);
// we'll always send joystick input events... // we'll always send joystick input events...
SEvent joyevent; SEvent joyevent;
joyevent.EventType = EET_JOYSTICK_INPUT_EVENT; joyevent.EventType = EET_JOYSTICK_INPUT_EVENT;
for (int i=0; i<numJoysticks; ++i) for (u32 i=0; i<Joysticks.size(); ++i)
{ {
SDL_Joystick* joystick = SDL_JoystickOpen(i); SDL_Joystick* joystick = Joysticks[i];
if (joystick) if (joystick)
{ {
int j; int j;
...@@ -370,7 +403,6 @@ bool CIrrDeviceSDL::run() ...@@ -370,7 +403,6 @@ bool CIrrDeviceSDL::run()
// now post the event // now post the event
postEventFromUser(joyevent); postEventFromUser(joyevent);
// and close the joystick // and close the joystick
SDL_JoystickClose(joystick);
} }
} }
#endif #endif
...@@ -528,6 +560,7 @@ void CIrrDeviceSDL::setResizeAble(bool resize) ...@@ -528,6 +560,7 @@ void CIrrDeviceSDL::setResizeAble(bool resize)
SDL_Flags |= SDL_RESIZABLE; SDL_Flags |= SDL_RESIZABLE;
else else
SDL_Flags &= ~SDL_RESIZABLE; SDL_Flags &= ~SDL_RESIZABLE;
if (Screen)
SDL_FreeSurface(Screen); SDL_FreeSurface(Screen);
Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags ); Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );
Resizeable = resize; Resizeable = resize;
......
...@@ -169,6 +169,9 @@ namespace irr ...@@ -169,6 +169,9 @@ namespace irr
SDL_Surface* Screen; SDL_Surface* Screen;
int SDL_Flags; int SDL_Flags;
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
core::array<SDL_Joystick*> Joysticks;
#endif
s32 MouseX, MouseY; s32 MouseX, MouseY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment