EXPERIMENTAL

Removed X event loops from GCPad and Wiimote plugins, and implemented an asynchronous check for keyboard and mouse buttons.
Also added an X event loop in core that handles events while the emulator is paused.  Prevents unexpected behavior from events that occur while the emulator is paused.
Now there is only one event loop running at a time (besides those hidden in SDL).
I will revert this commit if other devs are unhappy with it.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5048 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2010-02-13 20:47:23 +00:00
commit c2e0c75c93
12 changed files with 113 additions and 181 deletions

View file

@ -61,9 +61,6 @@ int NumPads = 0, NumGoodPads = 0; // Number of goods pads
std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
CONTROLLER_MAPPING_WII WiiMapping[MAX_WIIMOTES];
// Keyboard input
bool KeyStatus[LAST_CONSTANT];
} // namespace
#endif //_EMU_DECLARATIONS_

View file

@ -307,7 +307,6 @@ struct CONTROLLER_MAPPING_WII // WII PAD MAPPING
extern int NumPads, NumGoodPads; // Number of goods pads
extern std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
extern CONTROLLER_MAPPING_WII WiiMapping[4];
extern bool KeyStatus[64];
} // namespace

View file

@ -196,10 +196,6 @@ void LoadRecordedMovements()
}
}
#if defined(HAVE_X11) && HAVE_X11
Window GLWin;
#endif
/* Calibrate the mouse position to the emulation window. g_WiimoteInitialize.hWnd is the rendering window handle. */
void GetMousePos(float& x, float& y)
{
@ -223,6 +219,7 @@ void GetMousePos(float& x, float& y)
float WinWidth = 0, WinHeight = 0;
float XOffset = 0, YOffset = 0;
int root_x, root_y, win_x, win_y;
Window GLWin = *(Window *)g_WiimoteInitialize.pXWindow;
if (GLWin != 0)
{
XWindowAttributes WinAttribs;
@ -643,8 +640,6 @@ void Update(int _number)
// Read input or not
if (WiiMapping[g_ID].Source == 1)
{
ReadLinuxKeyboard();
// Check if the pad state should be updated
if (NumGoodPads > 0 && joyinfo.size() > (u32)WiiMapping[g_ID].ID)
UpdatePadState(WiiMapping[g_ID]);
@ -672,89 +667,4 @@ void Update(int _number)
}
}
void ReadLinuxKeyboard()
{
#if defined(HAVE_X11) && HAVE_X11
XEvent E;
KeySym key;
// keyboard input
int num_events;
for (num_events = XPending(WMdisplay); num_events > 0; num_events--)
{
XNextEvent(WMdisplay, &E);
GLWin = E.xany.window;
switch (E.type)
{
case KeyPress:
{
key = XLookupKeysym((XKeyEvent*)&E, 0);
if ((key >= XK_F1 && key <= XK_F9) ||
key == XK_Shift_L || key == XK_Shift_R ||
key == XK_Control_L || key == XK_Control_R || key == XK_Escape)
{
XPutBackEvent(WMdisplay, &E);
break;
}
for (int i = 0; i < LAST_CONSTANT; i++)
{
if (((int) key) == WiiMapping[g_ID].Button[i])
KeyStatus[i] = true;
}
break;
}
case KeyRelease:
{
key = XLookupKeysym((XKeyEvent*)&E, 0);
if ((key >= XK_F1 && key <= XK_F9) ||
key == XK_Shift_L || key == XK_Shift_R ||
key == XK_Control_L || key == XK_Control_R || key == XK_Escape) {
XPutBackEvent(WMdisplay, &E);
break;
}
for (int i = 0; i < LAST_CONSTANT; i++)
{
if (((int) key) == WiiMapping[g_ID].Button[i])
KeyStatus[i] = false;
}
break;
}
case ButtonPress:
{
int button = ((XButtonEvent*)&E)->button;
if (button == 1)
KeyStatus[EWM_A] = true;
else if (button == 3)
KeyStatus[EWM_B] = true;
else
XPutBackEvent(WMdisplay, &E);
break;
}
case ButtonRelease:
{
int button = ((XButtonEvent*)&E)->button;
if (button == 1)
KeyStatus[EWM_A] = false;
else if (button == 3)
KeyStatus[EWM_B] = false;
else
XPutBackEvent(WMdisplay, &E);
break;
}
case ConfigureNotify:
case ClientMessage:
XPutBackEvent(WMdisplay, &E);
break;
default:
break;
}
}
#endif
}
} // end of namespace

View file

@ -42,7 +42,7 @@ void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size
void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) ;
void Update(int _number);
void DoState(PointerWrap &p);
void ReadLinuxKeyboard();
//void ReadLinuxKeyboard();
bool IsKey(int Key);
// Recordings

View file

@ -297,7 +297,7 @@ int RecordingCheckKeys(int WmNuIr)
// Multi System Input Status Check
bool IsKey(int Key)
{
int Ret = NULL;
int Ret = false;
if (WiiMapping[g_ID].Source == 1)
{
@ -310,7 +310,11 @@ bool IsKey(int Key)
#else
if (MapKey < 256 || MapKey >= 0xf000)
{
Ret = KeyStatus[Key]; // Keyboard (Linux)
char keys[32];
KeyCode keyCode;
XQueryKeymap(WMdisplay, keys);
keyCode = XKeysymToKeycode(WMdisplay, MapKey);
Ret = (keys[keyCode/8] & (1 << (keyCode%8))); // Keyboard (Linux)
#endif
}
else if (MapKey < 0x1100)
@ -337,8 +341,28 @@ bool IsKey(int Key)
Ret = !(x < 0 || x > 1 || y < 0 || y > 1);
}
#endif
}
#if defined(HAVE_X11) && HAVE_X11
if ((Key == EWM_SHAKE) || (Key == EWM_A) || (Key == EWM_B))
{
Window GLWin = *(Window *)g_WiimoteInitialize.pXWindow;
if (GLWin != 0)
{
int root_x, root_y, win_x, win_y;
Window rootDummy, childWin;
unsigned int mask;
XQueryPointer(WMdisplay, GLWin, &rootDummy, &childWin, &root_x, &root_y, &win_x, &win_y, &mask);
if (((Key == EWM_A) && (mask & Button1Mask))
|| ((Key == EWM_B) && (mask & Button3Mask))
|| ((Key == EWM_SHAKE) && (mask & Button3Mask)))
{
float x, y;
GetMousePos(x, y);
Ret = !(x < 0 || x > 1 || y < 0 || y > 1);
}
}
}
#endif
}
return (Ret) ? true : false;
}