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

Change how isometric coordinates are calculated #59

Closed
SimplyLiz opened this issue Jan 14, 2019 · 1 comment
Closed

Change how isometric coordinates are calculated #59

SimplyLiz opened this issue Jan 14, 2019 · 1 comment
Assignees
Labels
performance Impacts / improves performance

Comments

@SimplyLiz
Copy link
Contributor

SimplyLiz commented Jan 14, 2019

Currently each of the elements are checked if the pixel color is transparent at the the clicked coordinates (with camera offsets and zoomlevel taken into account and if it's not, it's iso coordinates are returned.

It takes between 2 and 3 ms to calculate the isometric coordinates at a given screen coordinate this way and this is not viable. And certainly not for getting the current mouse over iso coordinates.

First attempt to improve performance.
Check all elements for SDL_PointInRect which should be way cheaper. If a collision occurs, check for pixel-alpha collision. If it's not the correct tile, use the next one in the list.

Further investiagtion showed that the performance penalty comes from iterating through all the tiles. Find a smarter way to do this.

@SimplyLiz SimplyLiz added the performance Impacts / improves performance label Jan 14, 2019
@SimplyLiz SimplyLiz self-assigned this Jan 14, 2019
@SimplyLiz
Copy link
Contributor Author

Now the clicked iso coordinate is caluclated mathematically. This coordinate is then traversed down in a "column" (with one field to the left and one to the right taken into account).

This reduces the nessary checks from 128x128 (or more for bigger maps) to 128 x 3 elements and calculating coordinates now takes <0ms.

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

No branches or pull requests

1 participant