From 67c78124d58074224e38d5f48742ec01f2f5c140 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Thu, 14 Mar 2013 00:15:43 +0200 Subject: [PATCH] Support per-button autofire --- include/core/controllerframe.hpp | 29 ++++++-- include/core/dispatch.hpp | 18 +++++ manual.lyx | 54 ++++++++++++-- manual.txt | 38 +++++++--- src/core/controller.cpp | 115 ++++++++++++++++++----------- src/core/controllerframe.cpp | 46 +++++++++--- src/core/dispatch.cpp | 16 ++++ src/platform/wxwidgets/editor-autohold.cpp | 67 ++++++++++++++--- src/platform/wxwidgets/mainwindow.cpp | 2 +- 9 files changed, 297 insertions(+), 88 deletions(-) diff --git a/include/core/controllerframe.hpp b/include/core/controllerframe.hpp index ce6a515e..96dce1a6 100644 --- a/include/core/controllerframe.hpp +++ b/include/core/controllerframe.hpp @@ -161,23 +161,42 @@ public: */ bool button2(unsigned port, unsigned controller, unsigned pbid) throw(); /** - * Set autofire pattern. + * Manipulate autofire. * - * Parameter pattern: The new pattern. - * Throws std::bad_alloc: Not enough memory. + * 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. */ - void autofire(std::vector pattern) throw(std::bad_alloc); + std::pair autofire2(unsigned port, unsigned controller, unsigned pbid) throw(); /** * TODO: Document. */ bool is_present(unsigned port, unsigned controller) throw(); private: + struct autofire_info + { + uint64_t first_frame; + unsigned duty; + unsigned cyclelen; + bool eval_at(uint64_t frame); + }; const port_type_set* types; controller_frame _input; controller_frame _autohold; controller_frame _framehold; + std::map _autofire; controller_frame _committed; - std::vector _autofire; }; /** diff --git a/include/core/dispatch.hpp b/include/core/dispatch.hpp index e2db8da4..bbe96efb 100644 --- a/include/core/dispatch.hpp +++ b/include/core/dispatch.hpp @@ -163,6 +163,24 @@ public: */ static void do_autohold_update(unsigned port, unsigned controller, unsigned ctrlnum, bool newstate) throw(); /** + * Autofire on button might have been changed. + * + * The default handler does nothing. + * + * Parameter port: The port. + * Parameter controller: The controller + * Parameter ctrlnum: Physical control number (0-15). + * Parameter duty: Duty cycle. + * Parameter cyclelen: Cycle length. + */ + virtual void on_autofire_update(unsigned port, unsigned controller, unsigned ctrlnum, unsigned duty, + unsigned cyclelen); +/** + * Call all on_autohold_update() handlers. + */ + static void do_autofire_update(unsigned port, unsigned controller, unsigned ctrlnum, unsigned duty, + unsigned cyclelen) throw(); +/** * Controller configuration may have been changed. * * The default handler does nothing. diff --git a/manual.lyx b/manual.lyx index e5a193ba..89183b89 100644 --- a/manual.lyx +++ b/manual.lyx @@ -663,23 +663,39 @@ Cauntion: Does not work properly if outside frame advance. \end_layout \begin_layout Subsubsection -designate-position -<#>-analog ++autofire-controller -<#>-