1 #ifndef _controller__hpp__included__
2 #define _controller__hpp__included__
6 #include "library/dispatch.hpp"
7 #include "library/command.hpp"
10 struct controller_state
;
11 struct emu_framebuffer
;
12 struct emulator_dispatch
;
15 namespace keyboard
{ class invbind
; }
16 namespace keyboard
{ class ctrlrkey
; }
17 namespace keyboard
{ class mapper
; }
18 namespace keyboard
{ class keyboard
; }
19 namespace portctrl
{ struct type
; }
20 namespace portctrl
{ struct controller
; }
25 struct controller_bind
30 int mode
; //0 => Button, 1 => Axis pair, 2 => Single axis.
34 unsigned control2
; //Axis only, UINT_MAX if not valid.
43 struct controller_bind bind
;
45 struct controller_triple
50 bool operator<(const struct controller_triple
& t
) const throw()
52 if(cclass
< t
.cclass
) return true;
53 if(cclass
> t
.cclass
) return false;
54 if(port
< t
.port
) return true;
55 if(port
> t
.port
) return false;
56 if(controller
< t
.controller
) return true;
57 if(controller
> t
.controller
) return false;
60 bool operator==(const struct controller_triple
& t
) const throw()
62 return (cclass
== t
.cclass
&& port
== t
.port
&& controller
== t
.controller
);
68 button_mapping(controller_state
& _controls
, keyboard::mapper
& mapper
, keyboard::keyboard
& keyboard
,
69 emu_framebuffer
& fbuf
, emulator_dispatch
& _dispatch
, lua_state
& _lua2
, command::group
& _cmd
);
75 * Reread active buttons.
79 * Reinitialize buttons.
85 void load(controller_state
& ctrlstate
);
87 * Load macros (from project).
89 void load(controller_state
& ctrlstate
, project_info
& pinfo
);
91 * Cleanup memory used.
95 * Lookup button by name.
97 std::pair
<int, int> byname(const std::string
& name
);
101 std::map
<std::string
, std::string
> button_keys
;
103 void do_analog_action(const std::string
& a
);
104 void do_autofire_action(const std::string
& a
, int mode
);
105 void do_action(const std::string
& name
, short state
, int mode
);
106 void promote_key(keyboard::ctrlrkey
& k
);
107 void add_button(const std::string
& name
, const controller_bind
& binding
);
108 void process_controller(portctrl::controller
& controller
, unsigned number
);
109 void process_controller(std::map
<std::string
, unsigned>& allocated
,
110 std::map
<controller_triple
, unsigned>& assigned
, portctrl::controller
& controller
, unsigned port
,
111 unsigned number_in_port
);
112 void process_port(std::map
<std::string
, unsigned>& allocated
,
113 std::map
<controller_triple
, unsigned>& assigned
, unsigned port
, portctrl::type
& ptype
);
115 bool check_button_active(const std::string
& name
);
116 void do_button_action(const std::string
& name
, short newstate
, int mode
);
117 void send_analog(const std::string
& name
, int32_t x
, int32_t y
);
118 std::map
<std::string
, keyboard::invbind
*> macro_binds
;
119 std::map
<std::string
, keyboard::invbind
*> macro_binds2
;
120 std::map
<std::string
, controller_bind
> all_buttons
;
121 std::map
<std::string
, active_bind
> active_buttons
;
122 std::map
<std::string
, keyboard::ctrlrkey
*> added_keys
;
123 std::set
<core_core
*> cores_done
;
124 bool promote_autohold
;
125 bool promote_autofire
;
127 controller_state
& controls
;
128 keyboard::mapper
& mapper
;
129 keyboard::keyboard
& keyboard
;
130 emu_framebuffer
& fbuf
;
131 emulator_dispatch
& edispatch
;
134 struct dispatch::target
<> ncore
;
135 command::_fnptr
<const std::string
&> button_p
;
136 command::_fnptr
<const std::string
&> button_r
;
137 command::_fnptr
<const std::string
&> button_h
;
138 command::_fnptr
<const std::string
&> button_t
;
139 command::_fnptr
<const std::string
&> button_d
;
140 command::_fnptr
<const std::string
&> button_ap
;
141 command::_fnptr
<const std::string
&> button_ar
;
142 command::_fnptr
<const std::string
&> button_at
;
143 command::_fnptr
<const std::string
&> button_a
;
144 command::_fnptr
<> afire_p
;
145 command::_fnptr
<> afire_n
;
146 command::_fnptr
<> ahold_p
;
147 command::_fnptr
<> ahold_n
;
148 command::_fnptr
<> typed_p
;
149 command::_fnptr
<> typed_n
;