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

Interpreter Refactor #3233

Merged
merged 7 commits into from
Sep 2, 2024
Merged

Conversation

florianessl
Copy link
Member

  • Refactors & restructures some of the logic of my "AntiLag" branch into a new "Caching" namespace.
  • Moves some of the common helper function from the interpreter class to a new file "game_interpreter_shared.cpp"
  • Adds a new abstract base class for the interpreter: "Game_BaseInterpreterContext"
    • This class holds the declarations for a few member functions which are used for evaluation logic across different sorts of commands
    • All the moved helper functions (CheckOperator, ValueOrVariable, CommandStringOrVariable & others) are agnostic to the actual implementation of the interpreter itself
  • Refactors "ValueOrVariable" & "ValueOrVariableBitfield" into template methods
    • Might save some unecessary branching depending on the context in which they are used

New helper function: "DecodeTargetEvaluationMode"

  • Unifies some of the commonly seen logic that was responsible for decoding command arguments into either a single variable id or a set range of variables.
  • Used in ControlSwitches, ControlVariables & ControlStrings with different template parameters (these specify the supported variable accessing modes). E.g.: A hypothethical new "ControlVariablesEx" command could just set all of these parameters to true and share the rest of its logic with the original command.
  • Used in my ScopedVars branch for these new commands:
    • ControlSwitchesEx
    • ControlVariablesEx
    • ControlScopedSwitches
    • ControlScopedVariables

This should be most of the easier-to-verify-and-merge changes, my "ScopedVars" depends on.

The current draft for ScopedVars also contains some more changes for the "ControlVariables" & "ConditionalBranch" commands, moving all of the operand switching logic into game_interpreter_control_variables.cpp. Basically I reinvented dispatching tables for this, to share this logic between the different new command spin-offs, but I have yet to confirm with benchmarks that this really a good solution. I don't want to slow any of the existing commands down by even a single cycle. :D
https://github.com/florianessl/Player/tree/ScopedVars
Best possible way to implement all this switching would likely be a mix of computed go-tos & tail recursion (see #1919 for the suggestion of implementing computed go-tos; but it´s debatable, if any of these changes would create any speed-ups in current-year & aren't already part of common compiler optimizations.)

@Ghabry
Copy link
Member

Ghabry commented Jun 5, 2024

Nice refactor / cleanup! Besides Refactored several Interpreter related code segments this does not look too controversial. Reviewing that one commit will take a while but on first glance I see no obvious issues.

@carstene1ns carstene1ns added the Awaiting Rebase Pull requests with conflicting files due to former merge label Jun 10, 2024
@Ghabry
Copy link
Member

Ghabry commented Jul 18, 2024

@florianessl could you attempt to do a rebase? There is one conflict in game_interpreter.

- Implemented template method "DecodeTargetEvaluationMode".
  (This logic is shared between ControlVariables, ControlSwitches & ControlStrings but the actual implementation for several special access modes differs between implementations. Support for these modes is evaluated at compile time.)
- Moved some common helper functions into a new file "game_interpreter_shared.cpp" (CheckOperator, ValueOrVariable / CommandStringOrVariable & variants)
- Refactored "ValueOrVariable" & "ValueOrVariableBitfield" into template methods
- Moved some commonly used member function declarations which are needed for certain command argument evaluation methods from Game_Interpreter into a new abstract base class
  (namespace "Game_Interpreter_Shared" is agnostic to the actual implementation of the interpreter)
…d definition of "Game_BaseInterpreterContext" to the bottom of header file
…implicit instantiations here while GCC fails
@Ghabry Ghabry removed the Awaiting Rebase Pull requests with conflicting files due to former merge label Jul 31, 2024
@Ghabry Ghabry added this to the 0.8.1 milestone Jul 31, 2024
@Ghabry
Copy link
Member

Ghabry commented Aug 27, 2024

Would be good to get this one reviewed and in before the event commands because of conflicts.

Will run our test game through this to find bugs...

src/game_map.h Outdated Show resolved Hide resolved
@Ghabry Ghabry merged commit 5d20c6d into EasyRPG:master Sep 2, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants