CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/WindowsHost.cpp
Views: 1401
1
// Copyright (c) 2012- 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 "ppsspp_config.h"
19
20
#include <algorithm>
21
22
// native stuff
23
#include "Common/System/Display.h"
24
#include "Common/System/NativeApp.h"
25
#include "Common/Input/InputState.h"
26
#include "Common/Input/KeyCodes.h"
27
#include "Common/StringUtils.h"
28
29
#include "Core/Core.h"
30
#include "Core/Config.h"
31
#include "Core/ConfigValues.h"
32
#include "Core/CoreParameter.h"
33
#include "Core/HLE/Plugins.h"
34
#include "Core/System.h"
35
#include "Core/Debugger/SymbolMap.h"
36
#include "Core/Instance.h"
37
38
#include "UI/OnScreenDisplay.h"
39
40
#include "Windows/EmuThread.h"
41
#include "Windows/WindowsHost.h"
42
#include "Windows/MainWindow.h"
43
44
#ifndef _M_ARM
45
#include "Windows/DinputDevice.h"
46
#endif
47
#include "Windows/XinputDevice.h"
48
49
#include "Windows/main.h"
50
51
void SetConsolePosition() {
52
HWND console = GetConsoleWindow();
53
if (console != NULL && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1) {
54
SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
55
}
56
}
57
58
void UpdateConsolePosition() {
59
RECT rc;
60
HWND console = GetConsoleWindow();
61
if (console != NULL && GetWindowRect(console, &rc) && !IsIconic(console)) {
62
g_Config.iConsoleWindowX = rc.left;
63
g_Config.iConsoleWindowY = rc.top;
64
}
65
}
66
67
void WindowsInputManager::Init() {
68
//add first XInput device to respond
69
input.push_back(std::make_unique<XinputDevice>());
70
#ifndef _M_ARM
71
//find all connected DInput devices of class GamePad
72
numDinputDevices_ = DinputDevice::getNumPads();
73
for (size_t i = 0; i < numDinputDevices_; i++) {
74
input.push_back(std::make_unique<DinputDevice>(static_cast<int>(i)));
75
}
76
#endif
77
}
78
79
void WindowsInputManager::PollControllers() {
80
static const int CHECK_FREQUENCY = 71; // Just an arbitrary prime to try to not collide with other periodic checks.
81
if (checkCounter_++ > CHECK_FREQUENCY) {
82
#ifndef _M_ARM
83
size_t newCount = DinputDevice::getNumPads();
84
if (newCount > numDinputDevices_) {
85
INFO_LOG(Log::System, "New controller device detected");
86
for (size_t i = numDinputDevices_; i < newCount; i++) {
87
input.push_back(std::make_unique<DinputDevice>(static_cast<int>(i)));
88
}
89
numDinputDevices_ = newCount;
90
}
91
#endif
92
checkCounter_ = 0;
93
}
94
95
for (const auto &device : input) {
96
if (device->UpdateState() == InputDevice::UPDATESTATE_SKIP_PAD)
97
break;
98
}
99
100
// Disabled by default, needs a workaround to map to psp keys.
101
if (g_Config.bMouseControl) {
102
NativeMouseDelta(mouseDeltaX_, mouseDeltaY_);
103
}
104
105
mouseDeltaX_ *= g_Config.fMouseSmoothing;
106
mouseDeltaY_ *= g_Config.fMouseSmoothing;
107
108
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_X] = mouseDeltaX_;
109
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_Y] = mouseDeltaY_;
110
}
111
112