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

Enhance Multiway implementation #931

Closed
wants to merge 1 commit into from

Conversation

mucaho
Copy link
Contributor

@mucaho mucaho commented Jul 19, 2015

Benefits:

  • Limit diagonal movement to same magnitude as horizontal or vertical movement.
  • Allow diagonal movement and arbitrary direction movement with correct speed when pressing down multiple keys (may be of interest for isometric)

Caveat:

  • Takes an additional 5% of total frame time on top of current approach in worst-case scenario (smashing combination of 8 keys on a blank screen with 1 entity).

Notes:

  • See the 8-way example.
  • Velocity values handled by Multiway are truncated, so diagonal movement is approximated (can be changed).
  • Solves issue described here
  • I tried many alternatives to the current implementation, but my benchmarks showed it's not worth it on newest firefox and chrome
    • checking if we move in only one direction / diagonal so we can avoid Math.sqrt calculations, not worth it
    • memoization of input parameters, not worth it
  • There is probably a faster approach to handle diagonal movement only (current one is for generic directions)

@mucaho mucaho force-pushed the enhance_multiway_new branch 3 times, most recently from 5246083 to a36343e Compare July 28, 2015 17:40
@mucaho
Copy link
Contributor Author

mucaho commented Nov 29, 2015

I'm still on the fence whether the additional correctness & complexity is needed for Multiway or not (at least for its current uses).
What do you think @starwed? I'd like to hear your input on this.

Limit diagonal movement to same magnitude as horizontal or vertical
movement.
Allow arbitrary direction movement with correct speed when pressing down multiple keys.
var oldActiveSpeedX = this._activeSpeedX,
oldActiveSpeedY = this._activeSpeedY;

var magnitude_e6 = this._directionMagnitudes_e6[direction],
Copy link
Member

Choose a reason for hiding this comment

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

What's the point of all the e6 stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each direction vector is added to the net movement vector when key is pressed.
Each direction vector is substracted from the net movement vector when key is released.
Pressing and then releasing 5 different direction keys should net into 0 movement.
However, due to rounding errors, you don't get 0.
That's why this net movement vector is represented as a number * 10e6.

@mucaho
Copy link
Contributor Author

mucaho commented Dec 1, 2015

I have put some more thought to it, it's just overly complicated.
Who needs more than 8 directions for keyboard control?
Joystick / Gamepad support (with arbitrary directions) is already provided by external component.

@starwed
Copy link
Member

starwed commented Sep 30, 2016

Closing, since mucaho ended up feeling it was too complicated, and it's also superseded by #1051

@starwed starwed closed this Sep 30, 2016
@mucaho mucaho deleted the enhance_multiway_new branch May 17, 2017 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants