Merge pull request #19 from Hasufel/master

This commit is contained in:
Joshua Granick
2014-02-10 11:40:31 -08:00
parent 344cda94d2
commit 14ab05b950
5 changed files with 90 additions and 19 deletions

View File

@@ -47,6 +47,8 @@ class SystemEvents {
static public var joyhatmove = 26;
static public var joybuttondown = 27;
static public var joybuttonup = 28;
static public var syswm = 29;
static public var joydeviceadded = 29;
static public var joydeviceremoved = 30;
static public var syswm = 31;
}

View File

@@ -581,6 +581,18 @@ class InputHandler {
lib.host.ongamepadhat(_event);
}
} //lime_gamepadhat
public function lime_gamepaddeviceadded(_event:Dynamic) {
if(lib.host.ongamepaddeviceadded != null) {
lib.host.ongamepaddeviceadded(_event);
}
} //lime_gamepaddeviceadded
public function lime_gamepaddeviceremoved(_event:Dynamic) {
if(lib.host.ongamepaddeviceremoved != null) {
lib.host.ongamepaddeviceremoved(_event);
}
} //lime_gamepaddeviceremoved
private static var efLeftDown = 0x0001;
private static var efShiftDown = 0x0002;

View File

@@ -282,6 +282,12 @@ class Lime {
case SystemEvents.joybuttonup:
input.lime_gamepadbuttonup(_event);
case SystemEvents.joydeviceadded:
input.lime_gamepaddeviceadded(_event);
case SystemEvents.joydeviceremoved:
input.lime_gamepaddeviceremoved(_event);
//Window
case SystemEvents.activate:

View File

@@ -58,11 +58,13 @@ enum EventType
etJoyHatMove, // 26
etJoyButtonDown, // 27
etJoyButtonUp, // 28
etJoyDeviceAdded, //29
etJoyDeviceRemoved, //30
etSysWM, // 29
etSysWM, // 31
etRenderContextLost, // 30
etRenderContextRestored, // 31
etRenderContextLost, // 32
etRenderContextRestored, // 33
};
enum EventFlags

View File

@@ -738,7 +738,10 @@ extern "C" void MacBoot( /*void (*)()*/ );
SDLFrame *sgSDLFrame = 0;
#ifndef EMSCRIPTEN
SDL_Joystick *sgJoystick = 0;
SDL_Joystick *sgJoystick;
QuickVec<SDL_Joystick *> sgJoysticks;
QuickVec<int> sgJoysticksId;
QuickVec<int> sgJoysticksIndex;
#endif
@@ -1193,7 +1196,12 @@ void ProcessEvent(SDL_Event &inEvent)
Event joystick(etJoyButtonUp);
joystick.id = inEvent.jbutton.which;
joystick.code = inEvent.jbutton.button;
sgSDLFrame->ProcessEvent(joystick);
for (int i = 0; i < sgJoysticksId.size(); i++) { //if SDL_JOYDEVICEREMOVED is triggered, up is fired on all buttons, so we need to counter the effect
if (sgJoysticksId[i] == joystick.id) {
sgSDLFrame->ProcessEvent(joystick);
break;
}
}
break;
}
case SDL_JOYHATMOTION:
@@ -1205,6 +1213,44 @@ void ProcessEvent(SDL_Event &inEvent)
sgSDLFrame->ProcessEvent(joystick);
break;
}
case SDL_JOYDEVICEADDED:
{
int joyId = -1;
for (int i = 0; i < sgJoysticksId.size(); i++) {
if (sgJoysticksIndex[i] == i) {
joyId = i;
break;
}
}
if (joyId == -1) {
Event joystick(etJoyDeviceAdded);
sgJoystick = SDL_JoystickOpen(inEvent.jdevice.which); //which: joystick device index
joystick.id = SDL_JoystickInstanceID(sgJoystick);
sgJoysticks.push_back(sgJoystick);
sgJoysticksId.push_back(joystick.id);
sgJoysticksIndex.push_back(inEvent.jdevice.which);
sgSDLFrame->ProcessEvent(joystick);
}
break;
}
case SDL_JOYDEVICEREMOVED:
{
Event joystick(etJoyDeviceRemoved);
joystick.id = inEvent.jdevice.which; //which: instance id
int j = 0;
for (int i = 0; i < sgJoysticksId.size(); i++) {
if (sgJoysticksId[i] == joystick.id) {
SDL_JoystickClose(sgJoysticks[i]);
break;
}
j++;
}
sgJoysticksId.erase(j,1);
sgJoysticks.erase(j,1);
sgJoysticksIndex.erase(j,1);
sgSDLFrame->ProcessEvent(joystick);
break;
}
}
};
@@ -1524,19 +1570,7 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight,
#endif
HintColourOrder( is_opengl || screen->format->Rmask==0xff );
*/
int numJoysticks = SDL_NumJoysticks();
if (sgJoystickEnabled && numJoysticks > 0)
{
for (int i = 0; i < numJoysticks; i++)
{
sgJoystick = SDL_JoystickOpen(i);
}
SDL_JoystickEventState(SDL_TRUE);
}
*/
int width, height;
if (windowFlags & SDL_WINDOW_FULLSCREEN || windowFlags & SDL_WINDOW_FULLSCREEN_DESKTOP)
{
@@ -1554,6 +1588,21 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight,
sgSDLFrame = new SDLFrame(window, renderer, windowFlags, opengl, width, height);
inOnFrame(sgSDLFrame);
int numJoysticks = SDL_NumJoysticks();
if (sgJoystickEnabled && numJoysticks > 0) {
SDL_JoystickEventState(SDL_TRUE);
for (int i = 0; i < numJoysticks; i++) {
sgJoystick = SDL_JoystickOpen(i);
Event joystick(etJoyDeviceAdded);
joystick.id = SDL_JoystickInstanceID(sgJoystick);
sgJoysticks.push_back(sgJoystick);
sgJoysticksId.push_back(joystick.id);
sgJoysticksIndex.push_back(i);
sgSDLFrame->ProcessEvent(joystick);
}
}
StartAnimation();
}