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