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

Optimize guide line algorithm #7

Open
Technius opened this issue Jan 16, 2018 · 5 comments
Open

Optimize guide line algorithm #7

Technius opened this issue Jan 16, 2018 · 5 comments
Assignees

Comments

@Technius
Copy link
Collaborator

The guide line algorithm is too slow; there's a noticeable FPS loss after creating a movement order to somewhere far from the ship. We should probably either cache the line (by dynamically creating and adding a node) or make the algo faster.

@Technius
Copy link
Collaborator Author

Another way to do it is to draw all the lines at once instead of calling draw_line multiple times, which is expensive. Maybe we can combine draw_arc and draw_line?

@TropicMango
Copy link
Owner

I have changed the way the indicator path is being calculated, it now is calculated when you first change the click, and that is now stored into a list. However the guide line is still being up dated when you "end turn", which was not expected (i was thinking that the path will just stay at the original location while the ship moved along it)

@Technius
Copy link
Collaborator Author

Looks like you committed to godot3 branch by accident. I'll merge your commit into master.

@Technius
Copy link
Collaborator Author

The performance is much better, but it's still bad. On my desktop, CPU usage went from 144% to 40%, but this is just for two lines! I think we need to come up with a few more changes to fix the problem.

@Technius
Copy link
Collaborator Author

Technius commented Jan 23, 2018

I moved the todo list from #8 to here, since #8 is "good enough" to merge for now.

TODO (in no particular order):

  • If traveling in a straight line, only add the endpoints. We can tell if we're in a straight line if the angle difference stays at zero.
  • Use draw_polyline instead of looping over the points and calling draw_line individually. (Need help here: https://imgur.com/a/3PxiA)
  • Create a physics helper class to serve as a "source of truth" for all the physics things (like movement code, angle conversions, etc.). This is so that if we change the movement logic, we won't have to modify both the movement line logic and the entity movement logic.
  • Recalculating the line is expensive (can take up to 50% of frame time), so we need to figure out how to not do it on every frame. (Update: line is only recalculated when the player position or target changes, but it's still recalculated when the player moves).
  • In recalculate_move_approx_line, we can probably store pow(_player.speed * line_draw_rate, 2) in a constant instead of recalculating it on every iteration.
  • Maybe abstract the approximation logic so that we can reuse it for AI?
  • Make target a variable in MoveTargetIndicator

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

No branches or pull requests

2 participants