From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- .../InputCommon/ControllerInterface/Device.cpp | 193 +++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 Source/Core/InputCommon/ControllerInterface/Device.cpp (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp new file mode 100644 index 0000000000..965ecfc817 --- /dev/null +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -0,0 +1,193 @@ + +#include "Device.h" + +#include +#include + +namespace ciface +{ +namespace Core +{ + +// +// Device :: ~Device +// +// Destructor, delete all inputs/outputs on device destruction +// +Device::~Device() +{ + { + // delete inputs + std::vector::iterator + i = m_inputs.begin(), + e = m_inputs.end(); + for ( ;i!=e; ++i) + delete *i; + } + + { + // delete outputs + std::vector::iterator + o = m_outputs.begin(), + e = m_outputs.end(); + for ( ;o!=e; ++o) + delete *o; + } +} + +void Device::AddInput(Device::Input* const i) +{ + m_inputs.push_back(i); +} + +void Device::AddOutput(Device::Output* const o) +{ + m_outputs.push_back(o); +} + +Device::Input* Device::FindInput(const std::string &name) const +{ + std::vector::const_iterator + it = m_inputs.begin(), + itend = m_inputs.end(); + for (; it != itend; ++it) + if ((*it)->GetName() == name) + return *it; + + return NULL; +} + +Device::Output* Device::FindOutput(const std::string &name) const +{ + std::vector::const_iterator + it = m_outputs.begin(), + itend = m_outputs.end(); + for (; it != itend; ++it) + if ((*it)->GetName() == name) + return *it; + + return NULL; +} + +// +// Device :: ClearInputState +// +// Device classes should override this function +// ControllerInterface will call this when the device returns failure during UpdateInput +// used to try to set all buttons and axes to their default state when user unplugs a gamepad during play +// buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging +// +void Device::ClearInputState() +{ + // this is going to be called for every UpdateInput call that fails + // kinda slow but, w/e, should only happen when user unplugs a device while playing +} + +// +// DeviceQualifier :: ToString +// +// get string from a device qualifier / serialize +// +std::string DeviceQualifier::ToString() const +{ + if (source.empty() && (cid < 0) && name.empty()) + return ""; + std::ostringstream ss; + ss << source << '/'; + if ( cid > -1 ) + ss << cid; + ss << '/' << name; + return ss.str(); +} + +// +// DeviceQualifier :: FromString +// +// set a device qualifier from a string / unserialize +// +void DeviceQualifier::FromString(const std::string& str) +{ + std::istringstream ss(str); + + std::getline(ss, source = "", '/'); + + // silly + std::getline(ss, name, '/'); + std::istringstream(name) >> (cid = -1); + + std::getline(ss, name = ""); +} + +// +// DeviceQualifier :: FromDevice +// +// set a device qualifier from a device +// +void DeviceQualifier::FromDevice(const Device* const dev) +{ + name = dev->GetName(); + cid = dev->GetId(); + source= dev->GetSource(); +} + +bool DeviceQualifier::operator==(const Device* const dev) const +{ + if (dev->GetId() == cid) + if (dev->GetName() == name) + if (dev->GetSource() == source) + return true; + return false; +} + +bool DeviceQualifier::operator==(const DeviceQualifier& devq) const +{ + if (cid == devq.cid) + if (name == devq.name) + if (source == devq.source) + return true; + + return false; +} + +Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const +{ + std::vector::const_iterator + di = m_devices.begin(), + de = m_devices.end(); + for (; di!=de; ++di) + if (devq == *di) + return *di; + + return NULL; +} + +Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const +{ + if (def_dev) + { + Device::Input* const inp = def_dev->FindInput(name); + if (inp) + return inp; + } + + std::vector::const_iterator + di = m_devices.begin(), + de = m_devices.end(); + for (; di != de; ++di) + { + Device::Input* const i = (*di)->FindInput(name); + + if (i) + return i; + } + + return NULL; +} + +Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const +{ + return def_dev->FindOutput(name); +} + +} +} -- cgit v1.2.3 From d91a5abba1d66948cc43cc7a6c80827ede061bc8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 Jan 2014 19:51:21 -0500 Subject: Light cleanup to a little bit of InputCommon. Replaces much of the iterators that litter this section of the codebase. Also clean up a little bit of the comments that describe the interface classes. --- .../InputCommon/ControllerInterface/Device.cpp | 79 +++++++++------------- 1 file changed, 33 insertions(+), 46 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 965ecfc817..1a7295c2c5 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -10,29 +10,19 @@ namespace Core { // -// Device :: ~Device +// Device :: ~Device // // Destructor, delete all inputs/outputs on device destruction // Device::~Device() { - { // delete inputs - std::vector::iterator - i = m_inputs.begin(), - e = m_inputs.end(); - for ( ;i!=e; ++i) - delete *i; - } + for (Device::Input* input : m_inputs) + delete input; - { // delete outputs - std::vector::iterator - o = m_outputs.begin(), - e = m_outputs.end(); - for ( ;o!=e; ++o) - delete *o; - } + for (Device::Output* output: m_outputs) + delete output; } void Device::AddInput(Device::Input* const i) @@ -47,30 +37,28 @@ void Device::AddOutput(Device::Output* const o) Device::Input* Device::FindInput(const std::string &name) const { - std::vector::const_iterator - it = m_inputs.begin(), - itend = m_inputs.end(); - for (; it != itend; ++it) - if ((*it)->GetName() == name) - return *it; + for (Input* input : m_inputs) + { + if (input->GetName() == name) + return input; + } return NULL; } Device::Output* Device::FindOutput(const std::string &name) const { - std::vector::const_iterator - it = m_outputs.begin(), - itend = m_outputs.end(); - for (; it != itend; ++it) - if ((*it)->GetName() == name) - return *it; + for (Output* output : m_outputs) + { + if (output->GetName() == name) + return output; + } return NULL; } // -// Device :: ClearInputState +// Device :: ClearInputState // // Device classes should override this function // ControllerInterface will call this when the device returns failure during UpdateInput @@ -84,26 +72,28 @@ void Device::ClearInputState() } // -// DeviceQualifier :: ToString +// DeviceQualifier :: ToString // -// get string from a device qualifier / serialize +// Get string from a device qualifier / serialize // std::string DeviceQualifier::ToString() const { if (source.empty() && (cid < 0) && name.empty()) return ""; + std::ostringstream ss; ss << source << '/'; - if ( cid > -1 ) + if (cid > -1) ss << cid; ss << '/' << name; + return ss.str(); } // -// DeviceQualifier :: FromString +// DeviceQualifier :: FromString // -// set a device qualifier from a string / unserialize +// Set a device qualifier from a string / unserialize // void DeviceQualifier::FromString(const std::string& str) { @@ -119,9 +109,9 @@ void DeviceQualifier::FromString(const std::string& str) } // -// DeviceQualifier :: FromDevice +// DeviceQualifier :: FromDevice // -// set a device qualifier from a device +// Set a device qualifier from a device // void DeviceQualifier::FromDevice(const Device* const dev) { @@ -136,6 +126,7 @@ bool DeviceQualifier::operator==(const Device* const dev) const if (dev->GetName() == name) if (dev->GetSource() == source) return true; + return false; } @@ -151,12 +142,11 @@ bool DeviceQualifier::operator==(const DeviceQualifier& devq) const Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const { - std::vector::const_iterator - di = m_devices.begin(), - de = m_devices.end(); - for (; di!=de; ++di) - if (devq == *di) - return *di; + for (Device* d : m_devices) + { + if (devq == d) + return d; + } return NULL; } @@ -170,12 +160,9 @@ Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* return inp; } - std::vector::const_iterator - di = m_devices.begin(), - de = m_devices.end(); - for (; di != de; ++di) + for (Device* d : m_devices) { - Device::Input* const i = (*di)->FindInput(name); + Device::Input* const i = d->FindInput(name); if (i) return i; -- cgit v1.2.3 From d2038049f51192fbb55fbde2fc08128bacfb7707 Mon Sep 17 00:00:00 2001 From: lioncash Date: Mon, 10 Feb 2014 13:54:46 -0500 Subject: Replace all include guard ifdefs with "#pragma once" --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 1a7295c2c5..1b402e9b23 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -1,3 +1,6 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. #include "Device.h" -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 1b402e9b23..295fc10b5a 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -2,10 +2,10 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "Device.h" - -#include #include +#include + +#include "InputCommon/ControllerInterface/Device.h" namespace ciface { -- cgit v1.2.3 From d802d392811be44d34ae9cd23f616db93e54c50f Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 9 Mar 2014 21:14:26 +0100 Subject: clang-modernize -use-nullptr and s/\bNULL\b/nullptr/g for *.cpp/h/mm files not compiled on my machine --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 295fc10b5a..e1383efc9d 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -46,7 +46,7 @@ Device::Input* Device::FindInput(const std::string &name) const return input; } - return NULL; + return nullptr; } Device::Output* Device::FindOutput(const std::string &name) const @@ -57,7 +57,7 @@ Device::Output* Device::FindOutput(const std::string &name) const return output; } - return NULL; + return nullptr; } // @@ -151,7 +151,7 @@ Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const return d; } - return NULL; + return nullptr; } Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const @@ -171,7 +171,7 @@ Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* return i; } - return NULL; + return nullptr; } Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const -- cgit v1.2.3 From 74f308338195ac6c78008def5a6a4342c8b824af Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 11 Jul 2014 10:53:51 -0400 Subject: ControllerInterface: Gate the input based on our new background input setting --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index e1383efc9d..61057c8162 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -5,6 +5,12 @@ #include #include +// For InputGateOn() +// This is a really bad layering violation, but it's the cleanest +// place I could find to put it. +#include "Core/ConfigManager.h" +#include "Core/Host.h" + #include "InputCommon/ControllerInterface/Device.h" namespace ciface @@ -74,6 +80,16 @@ void Device::ClearInputState() // kinda slow but, w/e, should only happen when user unplugs a device while playing } +bool Device::Control::InputGateOn() +{ + if (SConfig::GetInstance().m_BackgroundInput) + return true; + else if (Host_RendererHasFocus()) + return true; + else + return false; +} + // // DeviceQualifier :: ToString // -- cgit v1.2.3 From 44307c950888a4942a35b0176e2601c266894983 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 16 Jul 2014 10:24:40 -0400 Subject: Host: Add a new "UIHasFocus" hook to determine if the UI has focus We can't use RendererHasFocus for this purpose because of some issues with exclusive fullscreen, and the new RendererHasFocus implementation didn't work for non-Render to Main Window cases, since the renderer window wasn't managed by wx. --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 61057c8162..84af8649a8 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -84,7 +84,7 @@ bool Device::Control::InputGateOn() { if (SConfig::GetInstance().m_BackgroundInput) return true; - else if (Host_RendererHasFocus()) + else if (Host_RendererHasFocus() || Host_UIHasFocus()) return true; else return false; -- cgit v1.2.3 From 61fcfc4bf2058d971af6882af2765ad34d935fcb Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:56:32 -0800 Subject: ControllerInterface: Remove unused ClearInputState --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 84af8649a8..f96c637426 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -66,20 +66,6 @@ Device::Output* Device::FindOutput(const std::string &name) const return nullptr; } -// -// Device :: ClearInputState -// -// Device classes should override this function -// ControllerInterface will call this when the device returns failure during UpdateInput -// used to try to set all buttons and axes to their default state when user unplugs a gamepad during play -// buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging -// -void Device::ClearInputState() -{ - // this is going to be called for every UpdateInput call that fails - // kinda slow but, w/e, should only happen when user unplugs a device while playing -} - bool Device::Control::InputGateOn() { if (SConfig::GetInstance().m_BackgroundInput) -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index f96c637426..fae7e98e2f 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -1,5 +1,5 @@ // Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include -- cgit v1.2.3