Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pad Refactoring #3283

Merged
merged 2 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 136 additions & 136 deletions rpcs3/Emu/Cell/Modules/cellPad.cpp

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions rpcs3/Emu/Io/Null/NullPadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@
class NullPadHandler final : public PadHandlerBase
{
public:
void Init(const u32 max_connect) override
bool Init() override
{
memset(&m_info, 0, sizeof(PadInfo));
m_info.max_connect = max_connect;
m_pads.clear();
return true;
}

std::vector<std::string> ListDevices() override
{
std::vector<std::string> nulllist;
nulllist.push_back("Default Null Device");
return nulllist;
}

bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override
{
return true;
}

void ThreadProc() override
{
}

};
92 changes: 24 additions & 68 deletions rpcs3/Emu/Io/PadHandler.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#include <vector>
#include <memory>
#include "../../Utilities/types.h"

// TODO: HLE info (constants, structs, etc.) should not be available here

enum PortStatus
Expand Down Expand Up @@ -190,6 +194,14 @@ struct Pad
u16 m_sensor_z;
u16 m_sensor_g;

void Init(u32 port_status, u32 port_setting, u32 device_capability, u32 device_type)
{
m_port_status = port_status;
m_port_setting = port_setting;
m_device_capability = device_capability;
m_device_type = device_type;
}

Pad(u32 port_status, u32 port_setting, u32 device_capability, u32 device_type)
: m_buffer_cleared(true)
, m_port_status(port_status)
Expand Down Expand Up @@ -226,79 +238,23 @@ struct Pad
}
};

struct PadInfo
{
u32 max_connect;
u32 now_connect;
u32 system_info;
};

class PadHandlerBase
{
protected:
PadInfo m_info;
std::vector<Pad> m_pads;
bool b_has_config = false;

public:
virtual void Init(const u32 max_connect) = 0;
virtual bool Init() { return true; };
virtual ~PadHandlerBase() = default;

//Set value to set pressure/axi to certain level, otherwise 0/255 default
void Key(const u32 code, bool pressed, u16 value=255)
{
for(Pad& pad : m_pads)
{
for (Button& button : pad.m_buttons)
{
if (button.m_keyCode != code)
continue;

if (value >= 256){ value = 255; }

//Todo: Is this flush necessary once games hit decent speeds?
if (button.m_pressed && !pressed)
{
button.m_flush = true;

}
else
{
button.m_pressed = pressed;
if (pressed)
button.m_value = value;
else
button.m_value = 0;
}
}

for(AnalogStick& stick : pad.m_sticks)
{
if (stick.m_keyCodeMax != code && stick.m_keyCodeMin != code)
continue;

//slightly less hack job for key based analog stick
// should also fix/make transitions when using keys smoother
// the logic here is that when a key is released,
// if we are at the opposite end of the axis, dont reset to middle
if (stick.m_keyCodeMax == code)
{
if (pressed) stick.m_value = 255;
else if (stick.m_value==0) stick.m_value = 0;
else stick.m_value = 128;
}
if (stick.m_keyCodeMin == code)
{
if (pressed) stick.m_value = 0;
else if (stick.m_value == 255) stick.m_value = 255;
else stick.m_value = 128;
}
}
}
}

virtual PadInfo& GetInfo() { return m_info; }
virtual std::vector<Pad>& GetPads() { return m_pads; }
virtual void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor) {};
std::vector<Button>& GetButtons(const u32 pad) { return m_pads[pad].m_buttons; }
std::vector<AnalogStick>& GetSticks(const u32 pad) { return m_pads[pad].m_sticks; }
//Does it have GUI Config?
bool has_config() { return b_has_config; };
//Sets window to config the controller(optional)
virtual void ConfigController(std::string device) {};
//Return list of devices for that handler
virtual std::vector<std::string> ListDevices() = 0;
//Callback called during pad_thread::ThreadFunc
virtual void ThreadProc() = 0;
//Binds a Pad to a device
virtual bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) = 0;
};
2 changes: 1 addition & 1 deletion rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct EmuCallbacks
std::function<void()> exit;
std::function<std::shared_ptr<class KeyboardHandlerBase>()> get_kb_handler;
std::function<std::shared_ptr<class MouseHandlerBase>()> get_mouse_handler;
std::function<std::shared_ptr<class PadHandlerBase>()> get_pad_handler;
std::function<std::shared_ptr<class pad_thread>()> get_pad_handler;
std::function<std::unique_ptr<class GSFrameBase>()> get_gs_frame;
std::function<std::shared_ptr<class GSRender>()> get_gs_render;
std::function<std::shared_ptr<class AudioThread>()> get_audio;
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/VFS.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <string>

namespace vfs
{
// VFS type
Expand Down
Loading