New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression parser improvements #7663

Open
wants to merge 25 commits into
base: master
from

Conversation

4 participants
@jordan-woyak
Copy link
Contributor

jordan-woyak commented Dec 30, 2018

Demonstrations (note: syntax of expressions has changed slightly since):
https://i.imgur.com/9wCT3sH.gif
https://i.imgur.com/codD9p2.gif
https://i.imgur.com/PbeGoKl.gif

Literals are now supported, e.g. `Trigger R`+0.25
This is useful for:

  • Holding Wiimote "Tilt" or IR "Forward/Backward" to a certain neutral value.
  • Modifying dirty input values on troublesome gamepads.
  • Math in advanced configurations

The ! (NOT) function syntax has been extended to support named functions.

  • Arguments syntax is C++-like
  • E.g. !if (`Button 1`, 0.5, 0.0)

Additional binary and unary operators have been added for advanced configurations:

  • , * - / % < > !sin !if !while etc.

Added a !toggle unary function whose state toggles on/off when its inner expression is activated.
This allows for any mapped input in Dolphin to be toggled on and off rather than held without needing separate "toggle" settings.

  • This was wanted for Wiimote IR Hide, Speed-limiter, etc.

Added special function named !timer which increases from 0.0 to 1.0 every N seconds.

  • e.g. !timer(1/2) for a 2Hz timer.
  • This can be used for creating auto-fire buttons.

Added named variables and assignment operator, e.g. $my_var=`Button 1`

  • Each ControllerEmu has its own set of variables.
  • Variables are reset on rebinding calls (going to change that) and default to 0.0
  • Useful to transfer state between different mappings.

Outputs and Inputs can now be used in the same expression.

  • E.g. `Motor R`=`Button 1` will set rumble motor on when pressing a button.

Added !while function which re-evaluates the 2nd argument while the 1st argument is > 0.5

  • Limited to 10000 reps to prevent infinite loops.

Added !if function

Added comma operator which behaves like it does in c++ to string together expressions.

  • Lhs is evaluated and discarded. Expression takes value of Rhs.

C++-style operator precedence is now followed.

  • Yes, this may break some existing expressions, but I think it's worth it.

TODO
Update GUI so people are semi-aware of these features.
Maybe add some additional functions people would want. Deadzone, Smoothing, etc.

This will fix issues:
https://bugs.dolphin-emu.org/issues/5531
https://bugs.dolphin-emu.org/issues/6513
https://bugs.dolphin-emu.org/issues/6827
https://bugs.dolphin-emu.org/issues/11187

@jordan-woyak jordan-woyak force-pushed the jordan-woyak:expression-parser-improve branch from 0aed2d4 to 0a3f023 Dec 30, 2018

@jordan-woyak jordan-woyak force-pushed the jordan-woyak:expression-parser-improve branch from 7063eae to e0ac877 Dec 30, 2018

@jordan-woyak jordan-woyak force-pushed the jordan-woyak:expression-parser-improve branch 4 times, most recently from d58fb6d to 3e11b4c Dec 31, 2018

@jordan-woyak jordan-woyak force-pushed the jordan-woyak:expression-parser-improve branch from 90859f0 to 6a06f9b Jan 6, 2019

Techjar and others added some commits Sep 12, 2018

NetPlay: Fix server peer initialization hang
The implementation of peer initialization would hang if the initial
packet was never received. This fixes that issue by deferring the
initialization to the packet receive loop.
NetPlay: Sync Wiimote extension
Small addition of NetPlay code in Core.cpp was needed to set the
extensions at the right time, as init would override them otherwise.
This solution is more elegant than modifying the user's INI files on
game start.
ResetRumble on emu pause/stop regardless of presence of DInput/Xinput…
… as that's not relevant. All the backends would like to stop rumbling.
Reduce input mapping detection time to 3 seconds because 5 seconds wa…
…s ridciculously long and output (rumble) testing time to 2 seconds because 5 seconds was annoyingly long.
ControllerInterface: Make CoalesceExpression not set the inactive chi…
…ld's value (rumble) to 0. This caused rumble to not enable when a control expression was both a valid "bareword" and "complex" expression.
ControllerInterface: DInput: Update force feedback effects in a threa…
…d. This should prevent slowdowns experienced by a handful of users.
ControllerInterface: Set DInput FF effect parameters sanely. This fix…
…es a crash with periodic effects and my GCPad adapter (probably a divide by zero behind the scenes).
ExpressionParser: Add multiplication and division operators. (divisio…
…n by zero evaluates as zero). Don't clamp result of addition operator. Clamping will be done later.
ExpressionParser: Expand ! symbol to allow for named unary functions.…
… Added !toggle function which toggles on/off with each activation of its inner expression.
ExpressionParser: Add mod operator, sin function, and timer "constant…
…" which can be used for auto-fire and oscillators.
ExpressionParser: Renamed ControlFinder to ControlEnvironment. Added …
…support for variables and assignment operator. ControlExpression objects now reference a matching input and output so the two can me mixed in any expression. (you can set rumble directly from inputs)
ExpressionParser: Add !while loop unary expression. Limited to 10000 …
…reps to prevent infinite loops. Rhs is re-evaluated until it is < 0.5. Added comma operator, which behaves like it does in c++. Added subration operator.

jordan-woyak added some commits Jan 5, 2019

ExpressionParser: Replace the timer literal with a timer function tha…
…t increases from 0.0 to 1.0 and resets after N seconds. e.g. (!timer 2.0) is a 2 second timer. Fixed parsing of unary expressions so things like (! ! 1.0) work.
ExpressionParser: Suppport N-ary functions. Arguments are read LISP s…
…tyle. N atoms are read after the function name. Added "if" function and made the "while" function more sensible with an arity of 2. Removed the ugly binary conditional operator.

@jordan-woyak jordan-woyak force-pushed the jordan-woyak:expression-parser-improve branch from 6a06f9b to b51642b Jan 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment