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

Added easily expandable macro for reducing repetition and better debugging for ConsoleMouseKbdHandler controls #79

Conversation

RandomGamingDev
Copy link
Contributor

Previously the code located at DagorEngine/prog/samples/commonFramework/de3_freeCam_mk.cpp

flyMode->keys.left =
  int((kbd.isKeyDown(HumanInput::DKEY_LEFT) && moveWithArrows) || (kbd.isKeyDown(HumanInput::DKEY_A) && moveWithWASD));
flyMode->keys.right =
  int((kbd.isKeyDown(HumanInput::DKEY_RIGHT) && moveWithArrows) || (kbd.isKeyDown(HumanInput::DKEY_D) && moveWithWASD));
flyMode->keys.fwd =
  int((kbd.isKeyDown(HumanInput::DKEY_UP) && moveWithArrows) || (kbd.isKeyDown(HumanInput::DKEY_W) && moveWithWASD));
flyMode->keys.back =
  int((kbd.isKeyDown(HumanInput::DKEY_DOWN) && moveWithArrows) || (kbd.isKeyDown(HumanInput::DKEY_S) && moveWithWASD));

which has a lot of repetition, hard to expand, and is prone to error

This PR just changes it to be simplified so that it's easier to expand, easier to debug, and involves less tedious repetition in a way similar to the chromium codebase (e.g. https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/graphics/gpu/webgl_image_conversion.cc#L3304)

Which gives us this:

#define MKEY(arrows, wasd) int((kbd.isKeyDown(arrows) && moveWithArrows) || (kbd.isKeyDown(wasd) && moveWithWASD));
flyMode->keys.left = MKEY(HumanInput::DKEY_LEFT, HumanInput::DKEY_A);
flyMode->keys.right = MKEY(HumanInput::DKEY_RIGHT, HumanInput::DKEY_D);
flyMode->keys.fwd = MKEY(HumanInput::DKEY_UP, HumanInput::DKEY_W);
flyMode->keys.back = MKEY(HumanInput::DKEY_DOWN, HumanInput::DKEY_S);
#undef MKEY

with MKEY standing for "movement key"

Macros are dangerous, but it'd be nice to see DagorEngine to move to use them a little more like Chromium's code

Copy link
Contributor

@NicSavichev NicSavichev left a comment

Choose a reason for hiding this comment

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

don't add binary files

@RandomGamingDev
Copy link
Contributor Author

don't add binary files

It's been resolved and now the only changes are within the file where the macro was added itself.

@NicSavichev NicSavichev merged commit 165847c into GaijinEntertainment:main Sep 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants