mirror of https://github.com/PCSX2/pcsx2.git
lilypad: Keep original KeyboardQueue (more ifdef)
It would be nice if windows support basic std::mutex The reverse fifo queue is kept in Linux/KeyboardQueue.cpp
This commit is contained in:
parent
349bb810f0
commit
13bb1ae028
|
@ -28,6 +28,7 @@ endif()
|
|||
set(lilypadSources
|
||||
DeviceEnumerator.cpp
|
||||
InputManager.cpp
|
||||
KeyboardQueue.cpp
|
||||
LilyPad.cpp
|
||||
Linux/Config.cpp
|
||||
Linux/ConfigHelper.cpp
|
||||
|
|
|
@ -21,8 +21,12 @@
|
|||
|
||||
// What MS calls a single process Mutex. Faster, supposedly.
|
||||
// More importantly, can be abbreviated, amusingly, as cSection.
|
||||
#ifdef _MSC_VER
|
||||
static CRITICAL_SECTION cSection;
|
||||
static u8 csInitialized = 0;
|
||||
#else
|
||||
static std::mutex cSection;
|
||||
#endif
|
||||
|
||||
#define EVENT_QUEUE_LEN 16
|
||||
// Actually points one beyond the last queued event.
|
||||
|
@ -31,11 +35,15 @@ static u8 nextQueuedEvent = 0;
|
|||
static keyEvent queuedEvents[EVENT_QUEUE_LEN];
|
||||
|
||||
void QueueKeyEvent(int key, int event) {
|
||||
#ifdef _MSC_VER
|
||||
if (!csInitialized) {
|
||||
csInitialized = 1;
|
||||
InitializeCriticalSection(&cSection);
|
||||
}
|
||||
EnterCriticalSection(&cSection);
|
||||
#else
|
||||
std::lock_guard<std::mutex> lock(cSection);
|
||||
#endif
|
||||
|
||||
// Don't queue events if escape is on top of queue. This is just for safety
|
||||
// purposes when a game is killing the emulator for whatever reason.
|
||||
|
@ -57,23 +65,33 @@ void QueueKeyEvent(int key, int event) {
|
|||
nextQueuedEvent = (nextQueuedEvent + 1) % EVENT_QUEUE_LEN;
|
||||
}
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
LeaveCriticalSection(&cSection);
|
||||
#endif
|
||||
}
|
||||
|
||||
int GetQueuedKeyEvent(keyEvent *event) {
|
||||
if (lastQueuedEvent == nextQueuedEvent) return 0;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
EnterCriticalSection(&cSection);
|
||||
#else
|
||||
std::lock_guard<std::mutex> lock(cSection);
|
||||
#endif
|
||||
*event = queuedEvents[nextQueuedEvent];
|
||||
nextQueuedEvent = (nextQueuedEvent + 1) % EVENT_QUEUE_LEN;
|
||||
#ifdef _MSC_VER
|
||||
LeaveCriticalSection(&cSection);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ClearKeyQueue() {
|
||||
lastQueuedEvent = nextQueuedEvent;
|
||||
#ifdef _MSC_VER
|
||||
if (csInitialized) {
|
||||
DeleteCriticalSection(&cSection);
|
||||
csInitialized = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -19,55 +19,6 @@
|
|||
// This is undoubtedly completely unnecessary.
|
||||
#include "KeyboardQueue.h"
|
||||
|
||||
// What MS calls a single process Mutex. Faster, supposedly.
|
||||
// More importantly, can be abbreviated, amusingly, as cSection.
|
||||
static std::mutex cSection;
|
||||
|
||||
#define EVENT_QUEUE_LEN 16
|
||||
// Actually points one beyond the last queued event.
|
||||
static u8 lastQueuedEvent = 0;
|
||||
static u8 nextQueuedEvent = 0;
|
||||
static keyEvent queuedEvents[EVENT_QUEUE_LEN];
|
||||
|
||||
void QueueKeyEvent(int key, int event) {
|
||||
std::lock_guard<std::mutex> lock(cSection);
|
||||
|
||||
// Don't queue events if escape is on top of queue. This is just for safety
|
||||
// purposes when a game is killing the emulator for whatever reason.
|
||||
if (nextQueuedEvent == lastQueuedEvent ||
|
||||
queuedEvents[nextQueuedEvent].key != VK_ESCAPE ||
|
||||
queuedEvents[nextQueuedEvent].evt != KEYPRESS) {
|
||||
// Clear queue on escape down, bringing escape to front. May do something
|
||||
// with shift/ctrl/alt and F-keys, later.
|
||||
if (event == KEYPRESS && key == VK_ESCAPE) {
|
||||
nextQueuedEvent = lastQueuedEvent;
|
||||
}
|
||||
|
||||
queuedEvents[lastQueuedEvent].key = key;
|
||||
queuedEvents[lastQueuedEvent].evt = event;
|
||||
|
||||
lastQueuedEvent = (lastQueuedEvent + 1) % EVENT_QUEUE_LEN;
|
||||
// If queue wrapped around, remove last element.
|
||||
if (nextQueuedEvent == lastQueuedEvent) {
|
||||
nextQueuedEvent = (nextQueuedEvent + 1) % EVENT_QUEUE_LEN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GetQueuedKeyEvent(keyEvent *event) {
|
||||
if (lastQueuedEvent == nextQueuedEvent) return 0;
|
||||
|
||||
std::lock_guard<std::mutex> lock(cSection);
|
||||
*event = queuedEvents[nextQueuedEvent];
|
||||
nextQueuedEvent = (nextQueuedEvent + 1) % EVENT_QUEUE_LEN;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ClearKeyQueue() {
|
||||
lastQueuedEvent = nextQueuedEvent;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
// Above code is for events that go from the plugin to core
|
||||
// Here we need the contrary, event that come from core to the plugin
|
||||
|
@ -82,7 +33,7 @@ static u8 R_nextQueuedEvent = 0;
|
|||
static keyEvent R_queuedEvents[R_EVENT_QUEUE_LEN];
|
||||
|
||||
void R_QueueKeyEvent(const keyEvent &evt) {
|
||||
std::lock_guard<std::mutex> lock(cSection);
|
||||
std::lock_guard<std::mutex> lock(core_event);
|
||||
|
||||
R_queuedEvents[R_lastQueuedEvent] = evt;
|
||||
R_lastQueuedEvent = (R_lastQueuedEvent + 1) % R_EVENT_QUEUE_LEN;
|
||||
|
|
Loading…
Reference in New Issue