2012-01-09 21:55:55 +02:00
|
|
|
#ifndef _controllerframe__hpp__included__
|
|
|
|
#define _controllerframe__hpp__included__
|
|
|
|
|
|
|
|
#include <cstring>
|
2012-02-23 16:48:56 +02:00
|
|
|
#include <climits>
|
2012-02-23 23:05:48 +02:00
|
|
|
#include <cstdio>
|
2012-01-09 21:55:55 +02:00
|
|
|
#include <cstdlib>
|
2012-03-04 15:41:06 +02:00
|
|
|
#include <cstdio>
|
2012-01-09 21:55:55 +02:00
|
|
|
#include <cstdint>
|
2012-02-23 16:48:56 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <iostream>
|
2012-01-09 21:55:55 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2012-07-15 13:32:15 +03:00
|
|
|
#include <list>
|
2012-10-11 11:32:44 +03:00
|
|
|
#include "library/controller-data.hpp"
|
2014-03-23 09:45:42 +02:00
|
|
|
#include "library/threads.hpp"
|
2012-01-09 21:55:55 +02:00
|
|
|
|
2014-05-24 11:39:36 +03:00
|
|
|
class project_state;
|
|
|
|
class movie_logic;
|
|
|
|
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Controllers state.
|
|
|
|
*/
|
|
|
|
class controller_state
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
2014-05-24 11:39:36 +03:00
|
|
|
controller_state(project_state& _project, movie_logic& _mlogic) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Convert lcid (Logical Controller ID) into pcid (Physical Controler ID).
|
|
|
|
*
|
|
|
|
* Parameter lcid: The logical controller ID.
|
2012-10-11 20:06:40 +03:00
|
|
|
* Return: The physical controller ID, or <-1, -1> if no such controller exists.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
std::pair<int, int> lcid_to_pcid(unsigned lcid) throw();
|
2012-10-19 19:53:15 +03:00
|
|
|
/**
|
|
|
|
* Lookup (port,controller) pair corresponding to given legacy pcid.
|
|
|
|
*
|
|
|
|
* Parameter pcid: The legacy pcid.
|
|
|
|
* Returns: The controller index, or <-1, -1> if no such thing exists.
|
|
|
|
* Note: Even if this does return a valid index, it still may not exist.
|
|
|
|
*/
|
|
|
|
std::pair<int, int> legacy_pcid_to_pair(unsigned pcid) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
2012-07-08 12:57:22 +03:00
|
|
|
* Is given pcid present?
|
2012-01-11 23:07:31 +02:00
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-07-08 12:57:22 +03:00
|
|
|
* Returns: True if present, false if not.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool pcid_present(unsigned port, unsigned controller) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
2012-10-11 20:06:40 +03:00
|
|
|
* Set types of ports.
|
2012-01-11 23:07:31 +02:00
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter ptype: The new types for ports.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Throws std::runtime_error: Illegal port type.
|
|
|
|
*/
|
2013-01-05 09:19:09 +02:00
|
|
|
void set_ports(const port_type_set& ptype) throw(std::runtime_error);
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Get status of current controls (with autohold/autofire factored in).
|
|
|
|
*
|
|
|
|
* Parameter framenum: Number of current frame (for evaluating autofire).
|
2012-01-13 06:51:47 +02:00
|
|
|
* Returns: The current controls.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
|
|
|
controller_frame get(uint64_t framenum) throw();
|
2012-01-13 06:51:47 +02:00
|
|
|
/**
|
|
|
|
* Commit given controls (autohold/autofire is ignored).
|
|
|
|
*
|
|
|
|
* Parameter controls: The controls to commit
|
|
|
|
*/
|
2013-04-05 20:06:00 +03:00
|
|
|
void commit(controller_frame controls) throw();
|
2012-01-13 06:51:47 +02:00
|
|
|
/**
|
|
|
|
* Get status of committed controls.
|
|
|
|
* Returns: The committed controls.
|
|
|
|
*/
|
|
|
|
controller_frame get_committed() throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Get blank frame.
|
|
|
|
*/
|
|
|
|
controller_frame get_blank() throw();
|
|
|
|
/**
|
2012-10-11 20:06:40 +03:00
|
|
|
* Send analog input to given controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port to send input to.
|
|
|
|
* Parameter controller: The controller to send input to.
|
2013-01-04 20:41:11 +02:00
|
|
|
* Parameter control: The control to send.
|
|
|
|
* Parameter x: The coordinate to send.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
2013-01-04 20:41:11 +02:00
|
|
|
void analog(unsigned port, unsigned controller, unsigned control, short x) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Manipulate autohold.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter newstate: The new state for autohold.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
void autohold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Query autohold.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of autohold.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool autohold2(unsigned port, unsigned controller, unsigned pbid) throw();
|
2012-05-11 19:37:06 +03:00
|
|
|
/**
|
|
|
|
* Reset all frame holds.
|
|
|
|
*/
|
|
|
|
void reset_framehold() throw();
|
|
|
|
/**
|
|
|
|
* Manipulate hold for frame.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-05-11 19:37:06 +03:00
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter newstate: The new state for framehold.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
void framehold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
|
2012-05-11 19:37:06 +03:00
|
|
|
/**
|
|
|
|
* Query hold for frame.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-05-11 19:37:06 +03:00
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of framehold.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool framehold2(unsigned port, unsigned controller, unsigned pbid) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Manipulate button.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter newstate: The new state for button.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
void button2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Query button.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of button.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool button2(unsigned port, unsigned controller, unsigned pbid) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
2013-03-14 00:15:43 +02:00
|
|
|
* Manipulate autofire.
|
2012-01-11 23:07:31 +02:00
|
|
|
*
|
2013-03-14 00:15:43 +02:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter duty: The new duty cycle for autofire.
|
|
|
|
* Parameter cyclelen: The new cycle length.
|
|
|
|
*/
|
|
|
|
void autofire2(unsigned port, unsigned controller, unsigned pbid, unsigned duty, unsigned cyclelen) throw();
|
|
|
|
/**
|
|
|
|
* Query autofire.
|
|
|
|
*
|
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of autofire.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
2013-03-14 00:15:43 +02:00
|
|
|
std::pair<unsigned, unsigned> autofire2(unsigned port, unsigned controller, unsigned pbid) throw();
|
2013-03-15 18:42:41 +02:00
|
|
|
/**
|
|
|
|
* Manipulate TASinput.
|
|
|
|
*
|
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter state: The new state.
|
|
|
|
*/
|
|
|
|
void tasinput(unsigned port, unsigned controller, unsigned pbid, int16_t state) throw();
|
|
|
|
/**
|
|
|
|
* Query tasinput.
|
|
|
|
*
|
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of tasinput.
|
|
|
|
*/
|
|
|
|
int16_t tasinput(unsigned port, unsigned controller, unsigned pbid) throw();
|
|
|
|
/**
|
|
|
|
* Enage/Disenage tasinput.
|
|
|
|
*/
|
|
|
|
void tasinput_enable(bool enabled);
|
2012-07-08 12:57:22 +03:00
|
|
|
/**
|
|
|
|
* TODO: Document.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool is_present(unsigned port, unsigned controller) throw();
|
2013-06-12 22:15:25 +03:00
|
|
|
void erase_macro(const std::string& macro);
|
|
|
|
std::set<std::string> enumerate_macro();
|
|
|
|
controller_macro& get_macro(const std::string& macro);
|
|
|
|
void set_macro(const std::string& macro, const controller_macro& m);
|
|
|
|
void apply_macro(controller_frame& f);
|
|
|
|
void rename_macro(const std::string& old, const std::string& newn);
|
|
|
|
void do_macro(const std::string& a, int mode);
|
|
|
|
std::set<std::string> active_macro_set();
|
|
|
|
void advance_macros();
|
|
|
|
std::map<std::string, uint64_t> get_macro_frames();
|
|
|
|
void set_macro_frames(const std::map<std::string, uint64_t>& f);
|
2012-01-11 23:07:31 +02:00
|
|
|
private:
|
2013-03-14 00:15:43 +02:00
|
|
|
struct autofire_info
|
|
|
|
{
|
|
|
|
uint64_t first_frame;
|
|
|
|
unsigned duty;
|
|
|
|
unsigned cyclelen;
|
|
|
|
bool eval_at(uint64_t frame);
|
|
|
|
};
|
2013-03-15 18:42:41 +02:00
|
|
|
struct tasinput_info
|
|
|
|
{
|
|
|
|
int mode;
|
|
|
|
int16_t state;
|
|
|
|
};
|
|
|
|
void reread_tasinput_mode(const port_type_set& ptype);
|
2012-10-11 20:06:40 +03:00
|
|
|
const port_type_set* types;
|
2012-01-11 23:07:31 +02:00
|
|
|
controller_frame _input;
|
|
|
|
controller_frame _autohold;
|
2012-05-11 19:37:06 +03:00
|
|
|
controller_frame _framehold;
|
2013-03-14 00:15:43 +02:00
|
|
|
std::map<unsigned, autofire_info> _autofire;
|
2013-03-15 18:42:41 +02:00
|
|
|
std::map<unsigned, tasinput_info> _tasinput;
|
|
|
|
bool tasinput_enaged;
|
2012-01-13 06:51:47 +02:00
|
|
|
controller_frame _committed;
|
2013-06-12 22:15:25 +03:00
|
|
|
std::map<std::string, controller_macro> all_macros;
|
|
|
|
std::list<std::pair<uint64_t, controller_macro*>> active_macros;
|
2014-03-23 09:45:42 +02:00
|
|
|
threads::lock macro_lock;
|
2014-05-24 11:39:36 +03:00
|
|
|
project_state& project;
|
|
|
|
movie_logic& mlogic;
|
2012-01-11 23:07:31 +02:00
|
|
|
};
|
|
|
|
|
2012-01-09 21:55:55 +02:00
|
|
|
#endif
|