Make various instance stuff to take references to other instance objs
[lsnes.git] / include / core / controllerframe.hpp
blobc2cd6f8fc81eda59e48263a388fd5330d470e752
1 #ifndef _controllerframe__hpp__included__
2 #define _controllerframe__hpp__included__
4 #include <cstring>
5 #include <climits>
6 #include <cstdio>
7 #include <cstdlib>
8 #include <cstdio>
9 #include <cstdint>
10 #include <sstream>
11 #include <iomanip>
12 #include <iostream>
13 #include <stdexcept>
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include <list>
18 #include "library/controller-data.hpp"
19 #include "library/threads.hpp"
21 class project_state;
22 class movie_logic;
24 /**
25 * Controllers state.
27 class controller_state
29 public:
30 /**
31 * Constructor.
33 controller_state(project_state& _project, movie_logic& _mlogic) throw();
34 /**
35 * Convert lcid (Logical Controller ID) into pcid (Physical Controler ID).
37 * Parameter lcid: The logical controller ID.
38 * Return: The physical controller ID, or <-1, -1> if no such controller exists.
40 std::pair<int, int> lcid_to_pcid(unsigned lcid) throw();
41 /**
42 * Lookup (port,controller) pair corresponding to given legacy pcid.
44 * Parameter pcid: The legacy pcid.
45 * Returns: The controller index, or <-1, -1> if no such thing exists.
46 * Note: Even if this does return a valid index, it still may not exist.
48 std::pair<int, int> legacy_pcid_to_pair(unsigned pcid) throw();
49 /**
50 * Is given pcid present?
52 * Parameter port: The port.
53 * Parameter controller: The controller.
54 * Returns: True if present, false if not.
56 bool pcid_present(unsigned port, unsigned controller) throw();
57 /**
58 * Set types of ports.
60 * Parameter ptype: The new types for ports.
61 * Throws std::runtime_error: Illegal port type.
63 void set_ports(const port_type_set& ptype) throw(std::runtime_error);
64 /**
65 * Get status of current controls (with autohold/autofire factored in).
67 * Parameter framenum: Number of current frame (for evaluating autofire).
68 * Returns: The current controls.
70 controller_frame get(uint64_t framenum) throw();
71 /**
72 * Commit given controls (autohold/autofire is ignored).
74 * Parameter controls: The controls to commit
76 void commit(controller_frame controls) throw();
77 /**
78 * Get status of committed controls.
79 * Returns: The committed controls.
81 controller_frame get_committed() throw();
82 /**
83 * Get blank frame.
85 controller_frame get_blank() throw();
86 /**
87 * Send analog input to given controller.
89 * Parameter port: The port to send input to.
90 * Parameter controller: The controller to send input to.
91 * Parameter control: The control to send.
92 * Parameter x: The coordinate to send.
94 void analog(unsigned port, unsigned controller, unsigned control, short x) throw();
95 /**
96 * Manipulate autohold.
98 * Parameter port: The port.
99 * Parameter controller: The controller.
100 * Parameter pbid: The physical button ID to manipulate.
101 * Parameter newstate: The new state for autohold.
103 void autohold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
105 * Query autohold.
107 * Parameter port: The port.
108 * Parameter controller: The controller.
109 * Parameter pbid: The physical button ID to query.
110 * Returns: The state of autohold.
112 bool autohold2(unsigned port, unsigned controller, unsigned pbid) throw();
114 * Reset all frame holds.
116 void reset_framehold() throw();
118 * Manipulate hold for frame.
120 * Parameter port: The port.
121 * Parameter controller: The controller.
122 * Parameter pbid: The physical button ID to manipulate.
123 * Parameter newstate: The new state for framehold.
125 void framehold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
127 * Query hold for frame.
129 * Parameter port: The port.
130 * Parameter controller: The controller.
131 * Parameter pbid: The physical button ID to query.
132 * Returns: The state of framehold.
134 bool framehold2(unsigned port, unsigned controller, unsigned pbid) throw();
136 * Manipulate button.
138 * Parameter port: The port.
139 * Parameter controller: The controller.
140 * Parameter pbid: The physical button ID to manipulate.
141 * Parameter newstate: The new state for button.
143 void button2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
145 * Query button.
147 * Parameter port: The port.
148 * Parameter controller: The controller.
149 * Parameter pbid: The physical button ID to query.
150 * Returns: The state of button.
152 bool button2(unsigned port, unsigned controller, unsigned pbid) throw();
154 * Manipulate autofire.
156 * Parameter port: The port.
157 * Parameter controller: The controller.
158 * Parameter pbid: The physical button ID to manipulate.
159 * Parameter duty: The new duty cycle for autofire.
160 * Parameter cyclelen: The new cycle length.
162 void autofire2(unsigned port, unsigned controller, unsigned pbid, unsigned duty, unsigned cyclelen) throw();
164 * Query autofire.
166 * Parameter port: The port.
167 * Parameter controller: The controller.
168 * Parameter pbid: The physical button ID to query.
169 * Returns: The state of autofire.
171 std::pair<unsigned, unsigned> autofire2(unsigned port, unsigned controller, unsigned pbid) throw();
173 * Manipulate TASinput.
175 * Parameter port: The port.
176 * Parameter controller: The controller.
177 * Parameter pbid: The physical button ID to manipulate.
178 * Parameter state: The new state.
180 void tasinput(unsigned port, unsigned controller, unsigned pbid, int16_t state) throw();
182 * Query tasinput.
184 * Parameter port: The port.
185 * Parameter controller: The controller.
186 * Parameter pbid: The physical button ID to query.
187 * Returns: The state of tasinput.
189 int16_t tasinput(unsigned port, unsigned controller, unsigned pbid) throw();
191 * Enage/Disenage tasinput.
193 void tasinput_enable(bool enabled);
195 * TODO: Document.
197 bool is_present(unsigned port, unsigned controller) throw();
198 void erase_macro(const std::string& macro);
199 std::set<std::string> enumerate_macro();
200 controller_macro& get_macro(const std::string& macro);
201 void set_macro(const std::string& macro, const controller_macro& m);
202 void apply_macro(controller_frame& f);
203 void rename_macro(const std::string& old, const std::string& newn);
204 void do_macro(const std::string& a, int mode);
205 std::set<std::string> active_macro_set();
206 void advance_macros();
207 std::map<std::string, uint64_t> get_macro_frames();
208 void set_macro_frames(const std::map<std::string, uint64_t>& f);
209 private:
210 struct autofire_info
212 uint64_t first_frame;
213 unsigned duty;
214 unsigned cyclelen;
215 bool eval_at(uint64_t frame);
217 struct tasinput_info
219 int mode;
220 int16_t state;
222 void reread_tasinput_mode(const port_type_set& ptype);
223 const port_type_set* types;
224 controller_frame _input;
225 controller_frame _autohold;
226 controller_frame _framehold;
227 std::map<unsigned, autofire_info> _autofire;
228 std::map<unsigned, tasinput_info> _tasinput;
229 bool tasinput_enaged;
230 controller_frame _committed;
231 std::map<std::string, controller_macro> all_macros;
232 std::list<std::pair<uint64_t, controller_macro*>> active_macros;
233 threads::lock macro_lock;
234 project_state& project;
235 movie_logic& mlogic;
238 #endif