Repository navigation
Expand file tree
/
Copy pathmapping.h
More file actions
90 lines (76 loc) · 1.83 KB
/
Copy pathmapping.h
File metadata and controls
90 lines (76 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
This file is part of libswirl
original code by flyinghead
*/
#include "license/bsd"
#pragma once
#include <map>
#include <stdio.h>
#include "types.h"
#include "gamepad.h"
class InputMapping
{
public:
InputMapping() {}
InputMapping(const InputMapping& other) {
name = other.name;
buttons = other.buttons;
axes = other.axes;
axes_inverted = other.axes_inverted;
}
std::string name;
DreamcastKey get_button_id(u32 code)
{
auto it = buttons.find(code);
if (it != buttons.end())
return it->second;
else
return EMU_BTN_NONE;
}
void set_button(DreamcastKey id, u32 code);
u32 get_button_code(DreamcastKey key);
DreamcastKey get_axis_id(u32 code)
{
auto it = axes.find(code);
if (it != axes.end())
return it->second;
else
return EMU_AXIS_NONE;
}
bool get_axis_inverted(u32 code)
{
auto it = axes_inverted.find(code);
if (it != axes_inverted.end())
return it->second;
else
return false;
}
u32 get_axis_code(DreamcastKey key);
void set_axis(DreamcastKey id, u32 code, bool inverted);
void load(FILE* fp);
bool save(const char *name);
bool is_dirty() { return dirty; }
static InputMapping *LoadMapping(const char *name);
protected:
bool dirty = false;
private:
std::map<u32, DreamcastKey> buttons;
std::map<u32, DreamcastKey> axes;
std::map<u32, bool> axes_inverted;
static std::map<std::string, InputMapping *> loaded_mappings;
};
class IdentityInputMapping : public InputMapping
{
public:
IdentityInputMapping() {
name = "Default";
for (int i = 0; i < 16; i++)
set_button((DreamcastKey)(1 << i), 1 << i);
set_axis(DC_AXIS_X, DC_AXIS_X, false);
set_axis(DC_AXIS_Y, DC_AXIS_Y, false);
set_axis(DC_AXIS_LT, DC_AXIS_LT, false);
set_axis(DC_AXIS_RT, DC_AXIS_RT, false);
set_axis(DC_AXIS_X2, DC_AXIS_X2, false);
set_axis(DC_AXIS_Y2, DC_AXIS_Y2, false);
}
};