Skip to content
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

Merged
merged 38 commits into from Oct 17, 2019

Conversation

jordan-woyak
Copy link
Member

@jordan-woyak jordan-woyak commented Dec 30, 2018

Demonstrations (note: syntax has changed. function names used to be prefixed with !)
https://i.imgur.com/9wCT3sH.gif
https://i.imgur.com/codD9p2.gif
https://i.imgur.com/PbeGoKl.gif

Added syntax highlighting and parse result display:
https://giant.gfycat.com/GlaringOddballGenet.webm
https://giant.gfycat.com/BasicScaredBarracuda.webm

When a function is inserted with the improper number of arguments the expected arguments are shown in the parse-result textbox.

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

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

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

Added a toggle 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 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 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.

FYI, multi-line expressions fail to save because of our ini-file code.

This will fix (or at least alleviate) these 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/7636
https://bugs.dolphin-emu.org/issues/11187

@jordan-woyak jordan-woyak force-pushed the expression-parser-improve branch 4 times, most recently from d58fb6d to 3e11b4c Compare January 6, 2019 15:09
@jordan-woyak jordan-woyak force-pushed the expression-parser-improve branch 2 times, most recently from 6a06f9b to b51642b Compare January 6, 2019 17:18
@jordan-woyak jordan-woyak force-pushed the expression-parser-improve branch 2 times, most recently from 08f4e43 to 35d02f8 Compare January 26, 2019 18:44

connect(m_expression_text, &QPlainTextEdit::textChanged, [this] {
m_apply_button->setText(m_apply_button->text().remove(QStringLiteral("*")));
m_apply_button->setText(m_apply_button->text() + QStringLiteral("*"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks...weird. Why does it have to be done this way (not to mention: why at all?)
Is this trying to add an asterisk as "hey, something changed!" indicator at the end of the apply text?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That is what it's doing. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda gets the job done, but feels a little roundabout...but I cannot really think of a better way to do this though other than moving it to a method (or providing a shown/hidden text instead of changing the button text)

@iwubcode
Copy link
Contributor

iwubcode commented Apr 4, 2019

The !hold(...) syntax will be fantastic for games like Boom Blox when paired with configurable shakes/swings. This is great work @jordan-woyak !

}

m_functions_combo = new QComboBox();
m_functions_combo->addItem(tr("Functions"));
Copy link
Contributor

@iwubcode iwubcode Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed in this PR but even with documentation available it might be helpful to have some sort of description box. Many of these are self explanatory but a couple aren't as obvious.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a wiki page with documentation on the functions.

@jordan-woyak jordan-woyak changed the title Expression parser improvements WIP - Expression parser improvements Apr 6, 2019
…unctions so people are semi-aware of them. Fixed the "Apply" button. Display an error message on expression parse error.
@jordan-woyak jordan-woyak changed the title WIP - Expression parser improvements Expression parser improvements Oct 12, 2019
Copy link
Member

@BhaaLseN BhaaLseN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code seems good, untested.

@JMC47
Copy link
Contributor

JMC47 commented Oct 17, 2019

I've tested this a bit and it seems to work. I'm nervous about how it'll end up with people who do more complex things than I do, but it's the middle of the month and if there are any major issues, they should be sorted out before the monthly build.

@JMC47 JMC47 merged commit 8bc0a92 into dolphin-emu:master Oct 17, 2019
@mbc07
Copy link
Contributor

mbc07 commented Oct 17, 2019

It would be wise having a wiki page or something detailing everything the Expression Parser supports now before the next Progress Report. Also, does it break anything configured on the "older" syntax?

@JMC47
Copy link
Contributor

JMC47 commented Oct 17, 2019

Trial by fire I guess? We do need a wiki page (and maybe a help page somewhere in the controller configuration that links to that wiki page?)

Dolphin's controller configuration is awesome, but it's really complicated to use some of these features. It took me a long time.

@jordan-woyak
Copy link
Member Author

@mbc07 The only thing that should be broken is that a typical order of operations is now obeyed.
Previously everything was left to right. This shouldn't break much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants