2019-02-12 10:30:24 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 flyinghead
|
|
|
|
|
|
|
|
This file is part of reicast.
|
|
|
|
|
|
|
|
reicast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
reicast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with reicast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
2020-03-28 16:58:01 +00:00
|
|
|
|
2019-02-12 10:30:24 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "gamepad.h"
|
|
|
|
|
2020-03-28 16:58:01 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
|
2019-02-12 10:30:24 +00:00
|
|
|
class InputMapping
|
|
|
|
{
|
|
|
|
public:
|
2019-02-21 11:46:00 +00:00
|
|
|
InputMapping() {}
|
|
|
|
InputMapping(const InputMapping& other) {
|
|
|
|
name = other.name;
|
2020-07-07 09:50:57 +00:00
|
|
|
dead_zone = other.dead_zone;
|
2020-11-21 16:57:23 +00:00
|
|
|
for (int port = 0; port < 4; port++)
|
|
|
|
{
|
|
|
|
buttons[port] = other.buttons[port];
|
|
|
|
axes[port] = other.axes[port];
|
|
|
|
axes_inverted[port] = other.axes_inverted[port];
|
|
|
|
}
|
2019-02-21 11:46:00 +00:00
|
|
|
}
|
|
|
|
|
2019-02-12 10:30:24 +00:00
|
|
|
std::string name;
|
2020-11-21 16:57:23 +00:00
|
|
|
float dead_zone = 0.1f;
|
2019-02-12 10:30:24 +00:00
|
|
|
|
2020-11-21 16:57:23 +00:00
|
|
|
DreamcastKey get_button_id(u32 port, u32 code)
|
2019-02-12 10:30:24 +00:00
|
|
|
{
|
2020-11-21 16:57:23 +00:00
|
|
|
auto it = buttons[port].find(code);
|
|
|
|
if (it != buttons[port].end())
|
2019-02-12 10:30:24 +00:00
|
|
|
return it->second;
|
|
|
|
else
|
|
|
|
return EMU_BTN_NONE;
|
|
|
|
}
|
2020-11-21 16:57:23 +00:00
|
|
|
void set_button(u32 port, DreamcastKey id, u32 code);
|
|
|
|
void set_button(DreamcastKey id, u32 code) { set_button(0, id, code); }
|
|
|
|
u32 get_button_code(u32 port, DreamcastKey id);
|
2019-02-12 10:30:24 +00:00
|
|
|
|
2020-11-21 16:57:23 +00:00
|
|
|
DreamcastKey get_axis_id(u32 port, u32 code)
|
2019-02-12 10:30:24 +00:00
|
|
|
{
|
2020-11-21 16:57:23 +00:00
|
|
|
auto it = axes[port].find(code);
|
|
|
|
if (it != axes[port].end())
|
2019-02-12 10:30:24 +00:00
|
|
|
return it->second;
|
|
|
|
else
|
|
|
|
return EMU_AXIS_NONE;
|
|
|
|
}
|
2020-11-21 16:57:23 +00:00
|
|
|
bool get_axis_inverted(u32 port, u32 code)
|
2019-02-12 10:30:24 +00:00
|
|
|
{
|
2020-11-21 16:57:23 +00:00
|
|
|
auto it = axes_inverted[port].find(code);
|
|
|
|
if (it != axes_inverted[port].end())
|
2019-02-12 10:30:24 +00:00
|
|
|
return it->second;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-21 16:57:23 +00:00
|
|
|
u32 get_axis_code(u32 port, DreamcastKey key);
|
|
|
|
void set_axis(u32 port, DreamcastKey id, u32 code, bool inverted);
|
|
|
|
void set_axis(DreamcastKey id, u32 code, bool inverted) { set_axis(0, id, code, inverted); }
|
2019-02-12 10:30:24 +00:00
|
|
|
|
|
|
|
void load(FILE* fp);
|
|
|
|
bool save(const char *name);
|
|
|
|
|
|
|
|
bool is_dirty() { return dirty; }
|
|
|
|
|
2020-03-12 15:09:05 +00:00
|
|
|
static std::shared_ptr<InputMapping> LoadMapping(const char *name);
|
|
|
|
static void SaveMapping(const char *name, std::shared_ptr<InputMapping> mapping);
|
2019-02-12 10:30:24 +00:00
|
|
|
|
|
|
|
protected:
|
2019-02-21 11:46:00 +00:00
|
|
|
bool dirty = false;
|
2019-02-12 10:30:24 +00:00
|
|
|
|
|
|
|
private:
|
2020-11-21 16:57:23 +00:00
|
|
|
std::map<u32, DreamcastKey> buttons[4];
|
|
|
|
std::map<u32, DreamcastKey> axes[4];
|
|
|
|
std::map<u32, bool> axes_inverted[4];
|
2019-02-12 10:30:24 +00:00
|
|
|
|
2020-03-12 15:09:05 +00:00
|
|
|
static std::map<std::string, std::shared_ptr<InputMapping>> loaded_mappings;
|
2019-02-12 10:30:24 +00:00
|
|
|
};
|
2019-02-13 19:29:49 +00:00
|
|
|
|
|
|
|
class IdentityInputMapping : public InputMapping
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IdentityInputMapping() {
|
|
|
|
name = "Default";
|
2020-07-07 09:50:57 +00:00
|
|
|
dead_zone = 0.1f;
|
|
|
|
|
2019-09-27 12:15:29 +00:00
|
|
|
for (int i = 0; i < 32; i++)
|
2020-11-21 16:57:23 +00:00
|
|
|
set_button(0, (DreamcastKey)(1 << i), 1 << i);
|
|
|
|
set_axis(0, DC_AXIS_X, DC_AXIS_X, false);
|
|
|
|
set_axis(0, DC_AXIS_Y, DC_AXIS_Y, false);
|
|
|
|
set_axis(0, DC_AXIS_LT, DC_AXIS_LT, false);
|
|
|
|
set_axis(0, DC_AXIS_RT, DC_AXIS_RT, false);
|
|
|
|
set_axis(0, DC_AXIS_X2, DC_AXIS_X2, false);
|
|
|
|
set_axis(0, DC_AXIS_Y2, DC_AXIS_Y2, false);
|
2019-02-13 19:29:49 +00:00
|
|
|
}
|
|
|
|
};
|