1 #ifndef _controllerframe__hpp__included__
2 #define _controllerframe__hpp__included__
18 #include "library/controller-data.hpp"
19 #include "library/threads.hpp"
27 class controller_state
33 controller_state(project_state
& _project
, movie_logic
& _mlogic
) throw();
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();
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();
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();
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
);
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();
72 * Commit given controls (autohold/autofire is ignored).
74 * Parameter controls: The controls to commit
76 void commit(controller_frame controls
) throw();
78 * Get status of committed controls.
79 * Returns: The committed controls.
81 controller_frame
get_committed() throw();
85 controller_frame
get_blank() throw();
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();
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();
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();
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();
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();
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();
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
);
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
);
212 uint64_t first_frame
;
215 bool eval_at(uint64_t frame
);
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
;