CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Windows/InputDevice.cpp
Views: 1401
// Copyright (c) 2014- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "stdafx.h"18#include <thread>19#include <atomic>2021#include "Common/Input/InputState.h"22#include "Common/System/System.h"23#include "Common/Thread/ThreadUtil.h"24#include "Core/Config.h"25#include "Windows/InputDevice.h"2627static std::atomic_flag threadRunningFlag;28static std::thread inputThread;29static std::atomic_bool focused = ATOMIC_VAR_INIT(true);3031inline static void ExecuteInputPoll() {32if (focused.load(std::memory_order_relaxed) || !g_Config.bGamepadOnlyFocused) {33System_Notify(SystemNotification::POLL_CONTROLLERS);34}35}3637static void RunInputThread() {38SetCurrentThreadName("Input");3940// NOTE: The keyboard and mouse buttons are handled via raw input, not here.41// This is mainly for controllers which need to be polled, instead of generating events.4243while (threadRunningFlag.test_and_set(std::memory_order_relaxed)) {44ExecuteInputPoll();4546// Try to update 250 times per second.47Sleep(4);48}49}5051void InputDevice::BeginPolling() {52threadRunningFlag.test_and_set(std::memory_order_relaxed);53inputThread = std::thread(&RunInputThread);54}5556void InputDevice::StopPolling() {57threadRunningFlag.clear(std::memory_order_relaxed);5859inputThread.join();60}6162void InputDevice::GainFocus() {63focused.store(true, std::memory_order_relaxed);64}6566void InputDevice::LoseFocus() {67focused.store(false, std::memory_order_relaxed);68}697071