ss_int24_t and ss_uint24_t are integers
[lsnes.git] / include / core / controller.hpp
blobab329a24ecaa9e4e44b3c39f03c1b274a66f031d
1 #ifndef _controller__hpp__included__
2 #define _controller__hpp__included__
4 #include <string>
5 #include <map>
6 #include "library/dispatch.hpp"
7 #include "library/command.hpp"
9 struct project_info;
10 struct controller_state;
11 struct emu_framebuffer;
12 struct emulator_dispatch;
13 struct lua_state;
14 struct core_core;
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; }
22 class button_mapping
24 public:
25 struct controller_bind
27 std::string cclass;
28 unsigned number;
29 std::string name;
30 int mode; //0 => Button, 1 => Axis pair, 2 => Single axis.
31 bool xrel;
32 bool yrel;
33 unsigned control1;
34 unsigned control2; //Axis only, UINT_MAX if not valid.
35 int16_t rmin;
36 int16_t rmax;
37 bool centered;
39 struct active_bind
41 unsigned port;
42 unsigned controller;
43 struct controller_bind bind;
45 struct controller_triple
47 std::string cclass;
48 unsigned port;
49 unsigned controller;
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;
58 return false;
60 bool operator==(const struct controller_triple& t) const throw()
62 return (cclass == t.cclass && port == t.port && controller == t.controller);
65 /**
66 * Ctor.
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);
70 /**
71 * Dtor.
73 ~button_mapping();
74 /**
75 * Reread active buttons.
77 void reread();
78 /**
79 * Reinitialize buttons.
81 void reinit();
82 /**
83 * Load macros.
85 void load(controller_state& ctrlstate);
86 /**
87 * Load macros (from project).
89 void load(controller_state& ctrlstate, project_info& pinfo);
90 /**
91 * Cleanup memory used.
93 void cleanup();
94 /**
95 * Lookup button by name.
97 std::pair<int, int> byname(const std::string& name);
98 /**
99 * Map of button keys.
101 std::map<std::string, std::string> button_keys;
102 private:
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);
114 void init();
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 controller_state& controls;
125 keyboard::mapper& mapper;
126 keyboard::keyboard& keyboard;
127 emu_framebuffer& fbuf;
128 emulator_dispatch& edispatch;
129 lua_state& lua2;
130 command::group& cmd;
131 struct dispatch::target<> ncore;
132 command::_fnptr<const std::string&> button_p;
133 command::_fnptr<const std::string&> button_r;
134 command::_fnptr<const std::string&> button_h;
135 command::_fnptr<const std::string&> button_t;
136 command::_fnptr<const std::string&> button_d;
137 command::_fnptr<const std::string&> button_ap;
138 command::_fnptr<const std::string&> button_ar;
139 command::_fnptr<const std::string&> button_at;
140 command::_fnptr<const std::string&> button_a;
145 #endif