#ifndef _controllerframe__hpp__included__ #define _controllerframe__hpp__included__ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "library/controller-data.hpp" /** * Analog indices. */ #define MAX_ANALOG 3 /** * Controllers state. */ class controller_state { public: /** * Constructor. */ controller_state() throw(); /** * Convert lcid (Logical Controller ID) into pcid (Physical Controler ID). * * Parameter lcid: The logical controller ID. * Return: The physical controller ID, or <-1, -1> if no such controller exists. */ std::pair lcid_to_pcid(unsigned lcid) throw(); /** * 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 legacy_pcid_to_pair(unsigned pcid) throw(); /** * Is given pcid present? * * Parameter port: The port. * Parameter controller: The controller. * Returns: True if present, false if not. */ bool pcid_present(unsigned port, unsigned controller) throw(); /** * Set types of ports. * * Parameter ptype: The new types for ports. * Throws std::runtime_error: Illegal port type. */ void set_ports(const port_type_set& ptype) throw(std::runtime_error); /** * Get status of current controls (with autohold/autofire factored in). * * Parameter framenum: Number of current frame (for evaluating autofire). * Returns: The current controls. */ controller_frame get(uint64_t framenum) throw(); /** * Commit given controls (autohold/autofire is factored in). * * Parameter framenum: Number of current frame (for evaluating autofire). * Returns: The committed controls. */ controller_frame commit(uint64_t framenum) throw(); /** * Commit given controls (autohold/autofire is ignored). * * Parameter controls: The controls to commit * Returns: The committed controls. */ controller_frame commit(controller_frame controls) throw(); /** * Get status of committed controls. * Returns: The committed controls. */ controller_frame get_committed() throw(); /** * Get blank frame. */ controller_frame get_blank() throw(); /** * Send analog input to given controller. * * Parameter port: The port to send input to. * Parameter controller: The controller to send input to. * Parameter control: The control to send. * Parameter x: The coordinate to send. */ void analog(unsigned port, unsigned controller, unsigned control, short x) throw(); /** * Manipulate autohold. * * Parameter port: The port. * Parameter controller: The controller. * Parameter pbid: The physical button ID to manipulate. * Parameter newstate: The new state for autohold. */ void autohold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw(); /** * Query autohold. * * Parameter port: The port. * Parameter controller: The controller. * Parameter pbid: The physical button ID to query. * Returns: The state of autohold. */ bool autohold2(unsigned port, unsigned controller, unsigned pbid) throw(); /** * Reset all frame holds. */ void reset_framehold() throw(); /** * Manipulate hold for frame. * * Parameter port: The port. * Parameter controller: The controller. * Parameter pbid: The physical button ID to manipulate. * Parameter newstate: The new state for framehold. */ void framehold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw(); /** * Query hold for frame. * * Parameter port: The port. * Parameter controller: The controller. * Parameter pbid: The physical button ID to query. * Returns: The state of framehold. */ bool framehold2(unsigned port, unsigned controller, unsigned pbid) throw(); /** * Manipulate button. * * Parameter port: The port. * Parameter controller: The controller. * Parameter pbid: The physical button ID to manipulate. * Parameter newstate: The new state for button. */ void button2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw(); /** * Query button. * * Parameter port: The port. * Parameter controller: The controller. * Parameter pbid: The physical button ID to query. * Returns: The state of button. */ bool button2(unsigned port, unsigned controller, unsigned pbid) throw(); /** * Set autofire pattern. * * Parameter pattern: The new pattern. * Throws std::bad_alloc: Not enough memory. */ void autofire(std::vector pattern) throw(std::bad_alloc); /** * TODO: Document. */ bool is_present(unsigned port, unsigned controller) throw(); private: const port_type_set* types; controller_frame _input; controller_frame _autohold; controller_frame _framehold; controller_frame _committed; std::vector _autofire; }; /** * Generic port controller name function. */ template inline const char* generic_controller_name(unsigned controller) { if(controller >= controllers) return NULL; return *name; } #endif