Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/InputDevice.h
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
#pragma once
19
20
#include <list>
21
#include <memory>
22
#include <atomic>
23
#include <thread>
24
25
#include "Common/CommonTypes.h"
26
27
class InputDevice {
28
public:
29
virtual ~InputDevice() {}
30
31
virtual void Init() {}
32
virtual void Shutdown() {}
33
34
enum { UPDATESTATE_SKIP_PAD = 0x1234, UPDATESTATE_NO_SLEEP = 0x2345};
35
virtual int UpdateState() = 0;
36
};
37
38
class InputManager {
39
public:
40
void BeginPolling();
41
void StopPolling();
42
43
void Shutdown() {
44
devices_.clear();
45
}
46
47
void GainFocus() {
48
focused_.store(true, std::memory_order_relaxed);
49
}
50
void LoseFocus() {
51
focused_.store(false, std::memory_order_relaxed);
52
}
53
54
void AddDevice(InputDevice *device) {
55
devices_.emplace_back(std::unique_ptr<InputDevice>(device));
56
}
57
58
private:
59
void InputThread();
60
61
std::vector<std::unique_ptr<InputDevice>> devices_;
62
63
std::atomic<bool> runThread_;
64
std::thread inputThread_;
65
std::atomic<bool> focused_;
66
};
67
68
extern InputManager g_InputManager;
69
70