Fix travis build. Fix more code style issues

This commit is contained in:
Anon 2016-08-06 17:09:25 -05:00
parent 750838581d
commit 6ad7260471
11 changed files with 143 additions and 143 deletions

View File

@ -42,7 +42,7 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
}
void EmuWindow_SDL2::OnKeyEvent(SDL_Keysym key, u8 state) {
auto& keyboard = InputCore::GetKeyboard();
auto keyboard = InputCore::GetKeyboard();
KeyboardKey param = KeyboardKey(key.sym, key.scancode, SDL_GetKeyName(key.scancode));
if (state == SDL_PRESSED) {

View File

@ -237,14 +237,14 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
void GRenderWindow::keyPressEvent(QKeyEvent* event)
{
auto& keyboard = InputCore::GetKeyboard();
auto keyboard = InputCore::GetKeyboard();
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
keyboard->KeyPressed(param);
}
void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
{
auto& keyboard = InputCore::GetKeyboard();
auto keyboard = InputCore::GetKeyboard();
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
keyboard->KeyReleased(param);
}

View File

@ -18,5 +18,4 @@ public:
virtual bool CloseDevice() = 0;
protected:
std::map<std::string, std::vector<KeyMap::KeyTarget>> keyMapping; ///< Maps the string in the settings file to the HID Padstate object
};

View File

@ -23,17 +23,17 @@ void Keyboard::ProcessInput() {
std::lock_guard<std::mutex> lock(m);
keysPressedCopy = keysPressed;
}
for (const auto &ent1 : keyMapping) {
int scancode = std::stoul(ent1.first, nullptr, 16);
for (const auto& entry : keyMapping) {
int scancode = std::stoul(entry.first, nullptr, 16);
KeyboardKey proxy = KeyboardKey(0, scancode, "");
if (keysPressedCopy[proxy] == true && keysPressedLast[scancode] == false) {
for (const auto& key : ent1.second) {
for (const auto& key : entry.second) {
KeyMap::PressKey(key, 1.0);
}
keysPressedLast[scancode] = true;
}
else if (keysPressedCopy[proxy] == false && keysPressedLast[scancode] == true) {
for (const auto& key : ent1.second) {
for (const auto& key : entry.second) {
KeyMap::ReleaseKey(key);
}
keysPressedLast[scancode] = false;

View File

@ -32,7 +32,9 @@ struct KeyboardKey {
uint32_t scancode;
std::string character;
KeyboardKey(uint32_t key_, uint32_t scancode_, std::string character_) : key(key_), scancode(scancode_), character(std::move(character_)) {
KeyboardKey(uint32_t key_, uint32_t scancode_, std::string character_)
: key(key_), scancode(scancode_), character(std::move(character_))
{
}
bool operator==(const KeyboardKey& other) const {
return scancode == other.scancode;

View File

@ -47,29 +47,29 @@ void SDLGamepad::ProcessInput() {
if (gamepad == nullptr)
return;
SDL_GameControllerUpdate();
for (const auto &ent1 : keyMapping) {
SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(friendlyNameMapping[ent1.first].c_str());
for (const auto& entry : keyMapping) {
SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(friendlyNameMapping[entry.first].c_str());
if (button != SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_INVALID) {
Uint8 pressed = SDL_GameControllerGetButton(gamepad, button);
if (pressed == 1 && keysPressed[ent1.first] == false) {
for (const auto& padstate : ent1.second) {
if (pressed == 1 && keysPressed[entry.first] == false) {
for (const auto& padstate : entry.second) {
KeyMap::PressKey(padstate, 1.0);
keysPressed[ent1.first] = true;
keysPressed[entry.first] = true;
}
}
else if (pressed == 0 && keysPressed[ent1.first] == true) {
for (const auto& padstate : ent1.second) {
else if (pressed == 0 && keysPressed[entry.first] == true) {
for (const auto& padstate : entry.second) {
KeyMap::ReleaseKey(padstate);
keysPressed[ent1.first] = false;
keysPressed[entry.first] = false;
}
}
}
else {
// Try axis if button isn't valid
SDL_GameControllerAxis axis = SDL_GameControllerGetAxisFromString(friendlyNameMapping[ent1.first].c_str());
SDL_GameControllerAxis axis = SDL_GameControllerGetAxisFromString(friendlyNameMapping[entry.first].c_str());
if (axis != SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_INVALID) {
Sint16 value = SDL_GameControllerGetAxis(gamepad, axis);
for (const auto& padstate : ent1.second) {
for (const auto& padstate : entry.second) {
// dont process if in deadzone. Replace later with settings for deadzone.
if (abs(value) < 0.2 * 32767.0)
KeyMap::ReleaseKey(padstate);

View File

@ -17,7 +17,8 @@ public:
void ProcessInput() override;
bool CloseDevice() override;
private:
std::map<std::string, std::string> friendlyNameMapping = { /// Maps the friendly name shown on GUI with the string name for getting the SDL button instance.
/// Maps the friendly name shown on GUI with the string name for getting the SDL button instance.
std::map<std::string, std::string> friendlyNameMapping = {
{ "Button A","a" },
{ "Button B","b" },
{ "Button X","x" },

View File

@ -14,10 +14,10 @@
namespace InputCore {
constexpr u64 frame_ticks = 268123480ull / 60;
static int tick_event;
Service::HID::PadState pad_state;
std::tuple<s16, s16> circle_pad = { 0,0 };
std::shared_ptr<Keyboard> main_keyboard;
std::vector<std::shared_ptr<IDevice>> devices; ///< Devices that are handling input for the game
static Service::HID::PadState pad_state;
static std::tuple<s16, s16> circle_pad = { 0,0 };
static std::shared_ptr<Keyboard> main_keyboard;
static std::vector<std::shared_ptr<IDevice>> devices; ///< Devices that are handling input for the game
static void InputTickCallback(u64, int cycles_late) {
for (auto& device : devices)
@ -43,7 +43,7 @@ Service::HID::PadState GetPadState() {
return pad_state;
}
void SetPadState(Service::HID::PadState& state) {
void SetPadState(const Service::HID::PadState& state) {
pad_state.hex = state.hex;
}
@ -51,7 +51,7 @@ std::tuple<s16, s16> GetCirclePad() {
return circle_pad;
}
void SetCirclePad(std::tuple<s16, s16>& pad) {
void SetCirclePad(std::tuple<s16, s16> pad) {
circle_pad = pad;
}
@ -59,11 +59,11 @@ std::shared_ptr<Keyboard> GetKeyboard() {
return main_keyboard;
}
///Get Unique input mappings from settings
std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() {
/// Get Unique input mappings from settings
static std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() {
std::vector<Settings::InputDeviceMapping> uniqueMappings;
for (auto& mapping : Settings::values.input_mappings) {
for (const auto& mapping : Settings::values.input_mappings) {
if (!CheckIfMappingExists(uniqueMappings, mapping)) {
uniqueMappings.push_back(mapping);
}
@ -71,9 +71,9 @@ std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() {
return uniqueMappings;
}
std::map<std::string, std::vector<KeyMap::KeyTarget>> BuildKeyMapping(Settings::InputDeviceMapping mapping) {
static std::map<std::string, std::vector<KeyMap::KeyTarget>> BuildKeyMapping(Settings::InputDeviceMapping mapping) {
std::map<std::string, std::vector<KeyMap::KeyTarget>> keyMapping;
for (int i = 0; i < Settings::values.input_mappings.size(); i++) {
for (size_t i = 0; i < Settings::values.input_mappings.size(); i++) {
KeyMap::KeyTarget val = KeyMap::mapping_targets[i];
std::string key = Settings::values.input_mappings[i].key;
if (Settings::values.input_mappings[i] == mapping) {
@ -83,10 +83,10 @@ std::map<std::string, std::vector<KeyMap::KeyTarget>> BuildKeyMapping(Settings::
return keyMapping;
}
///Generate a device for each unique mapping
void GenerateUniqueDevices(std::vector<Settings::InputDeviceMapping> uniqueMappings) {
/// Generate a device for each unique mapping
static void GenerateUniqueDevices(const std::vector<Settings::InputDeviceMapping>& uniqueMappings) {
std::shared_ptr<IDevice> input;
for (auto& mapping : uniqueMappings) {
for (const auto& mapping : uniqueMappings) {
switch (mapping.framework) {
case Settings::DeviceFramework::Qt:
{
@ -109,19 +109,17 @@ void GenerateUniqueDevices(std::vector<Settings::InputDeviceMapping> uniqueMappi
}
devices.push_back(input);
//Build map of inputs to listen for, for this device
// Build map of inputs to listen for, for this device
auto keyMapping = BuildKeyMapping(mapping);
input->InitDevice(mapping.number, keyMapping);
}
}
void ParseSettings() {
std::vector<std::shared_ptr<IDevice>> devices;
auto uniqueMappings = GatherUniqueMappings();
GenerateUniqueDevices(uniqueMappings);
//init keyboard, if it hasn't already
// init keyboard, if it hasn't already
if (main_keyboard == nullptr)
main_keyboard = std::make_shared<Keyboard>();
}

View File

@ -14,16 +14,16 @@
class Keyboard;
namespace InputCore {
void Init();
void Shutdown();
Service::HID::PadState GetPadState();
void SetPadState(Service::HID::PadState& state);
std::tuple<s16, s16> GetCirclePad();
void SetCirclePad(std::tuple<s16, s16>& circle );
std::shared_ptr<Keyboard> GetKeyboard();
/// Read settings to initialize devices
void ParseSettings();
void Init();
void Shutdown();
Service::HID::PadState GetPadState();
void SetPadState(const Service::HID::PadState& state);
std::tuple<s16, s16> GetCirclePad();
void SetCirclePad(std::tuple<s16, s16> circle);
std::shared_ptr<Keyboard> GetKeyboard();
/// Read settings to initialize devices
void ParseSettings();
/// Helper method to check if device was already initialized
bool CheckIfMappingExists(const std::vector<Settings::InputDeviceMapping>& uniqueMapping, Settings::InputDeviceMapping mappingToCheck);
/// Helper method to check if device was already initialized
bool CheckIfMappingExists(const std::vector<Settings::InputDeviceMapping>& uniqueMapping, Settings::InputDeviceMapping mappingToCheck);
}

View File

@ -12,8 +12,8 @@
#include "input_core/key_map.h"
namespace KeyMap {
constexpr int MAX_CIRCLEPAD_POS = 0x9C; /// Max value for a circle pad position
const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets = { {
constexpr int MAX_CIRCLEPAD_POS = 0x9C; /// Max value for a circle pad position
const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets = { {
Service::HID::PAD_A, Service::HID::PAD_B, Service::HID::PAD_X, Service::HID::PAD_Y,
Service::HID::PAD_L, Service::HID::PAD_R, Service::HID::PAD_ZL, Service::HID::PAD_ZR,
Service::HID::PAD_START, Service::HID::PAD_SELECT, Service::HID::PAD_TOUCH,
@ -24,16 +24,16 @@ namespace KeyMap {
Service::HID::PAD_CIRCLE_DOWN,
Service::HID::PAD_CIRCLE_LEFT,
Service::HID::PAD_CIRCLE_RIGHT,
} };
///Array of inputs that are analog only, and require a strength when set
const std::array<KeyTarget, 4> analog_inputs = {
} };
///Array of inputs that are analog only, and require a strength when set
const std::array<KeyTarget, 4> analog_inputs = {
Service::HID::PAD_CIRCLE_UP,
Service::HID::PAD_CIRCLE_DOWN,
Service::HID::PAD_CIRCLE_LEFT,
Service::HID::PAD_CIRCLE_RIGHT
};
};
void PressKey(KeyTarget target, const float strength) {
void PressKey(KeyTarget target, const float strength) {
auto pad_state = InputCore::GetPadState();
// If is digital keytarget
if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) {
@ -50,9 +50,9 @@ namespace KeyMap {
}
InputCore::SetCirclePad(circle_pad);
}
}
}
void ReleaseKey(KeyTarget target) {
void ReleaseKey(KeyTarget target) {
auto pad_state = InputCore::GetPadState();
// If is digital keytarget
if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) {
@ -69,5 +69,5 @@ namespace KeyMap {
}
InputCore::SetCirclePad(circle_pad);
}
}
}
}

View File

@ -12,23 +12,23 @@
class EmuWindow;
namespace KeyMap {
/**
/**
* Represents key mapping targets that are not real 3DS buttons.
* They will be handled by KeyMap and translated to 3DS input.
*/
enum class IndirectTarget {
enum class IndirectTarget {
CirclePadUp,
CirclePadDown,
CirclePadLeft,
CirclePadRight,
CirclePadModifier
};
};
/**
/**
* Represents a key mapping target. It can be a PadState that represents real 3DS buttons,
* or an IndirectTarget.
*/
struct KeyTarget {
struct KeyTarget {
bool direct;
union {
u32 direct_target_hex;
@ -52,13 +52,13 @@ namespace KeyMap {
const bool operator==(const KeyTarget &other) const {
return this->target.direct_target_hex == other.target.direct_target_hex;
}
};
};
extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets;
extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets;
///Handles the pressing of a key and modifies InputCore state
void PressKey(KeyTarget target, float strength);
///Handles the pressing of a key and modifies InputCore state
void PressKey(KeyTarget target, float strength);
///Handles the releasing of a key and modifies InputCore state
void ReleaseKey(KeyTarget target);
///Handles the releasing of a key and modifies InputCore state
void ReleaseKey(KeyTarget target);
}