Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/InputDevice.cpp
3185 views
1
// Copyright (c) 2014- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "stdafx.h"
19
#include <thread>
20
#include <atomic>
21
22
#include "Common/Input/InputState.h"
23
#include "Common/System/System.h"
24
#include "Common/Thread/ThreadUtil.h"
25
#include "Core/Config.h"
26
#include "Windows/InputDevice.h"
27
28
InputManager g_InputManager;
29
30
void InputManager::InputThread() {
31
SetCurrentThreadName("Input");
32
33
for (auto &device : devices_) {
34
device->Init();
35
}
36
37
// NOTE: The keyboard and mouse buttons are handled via raw input, not here.
38
// This is mainly for controllers which need to be polled, instead of generating events.
39
bool noSleep = false;
40
while (runThread_.load(std::memory_order_relaxed)) {
41
if (focused_.load(std::memory_order_relaxed) || !g_Config.bGamepadOnlyFocused) {
42
System_Notify(SystemNotification::POLL_CONTROLLERS);
43
for (const auto &device : devices_) {
44
int state = device->UpdateState();
45
if (state == InputDevice::UPDATESTATE_SKIP_PAD)
46
break;
47
if (state == InputDevice::UPDATESTATE_NO_SLEEP) {
48
// Sleep was handled automatically.
49
noSleep = true;
50
}
51
}
52
}
53
54
// Try to update 250 times per second.
55
if (!noSleep)
56
Sleep(4);
57
}
58
59
for (auto &device : devices_) {
60
device->Shutdown();
61
}
62
}
63
64
void InputManager::BeginPolling() {
65
runThread_.store(true, std::memory_order_relaxed);
66
inputThread_ = std::thread([this]() {
67
InputThread();
68
});
69
}
70
71
void InputManager::StopPolling() {
72
runThread_.store(false, std::memory_order_relaxed);
73
inputThread_.join();
74
}
75
76