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

Fix bug in MapGetTileWorld and refactor #20

Merged
merged 1 commit into from
Aug 12, 2023

Conversation

hellworld111
Copy link

After analyzing the code, I have identified an issue with the MapGetTileWorld function where passing a negative x or y in the range of (-TILE_SIZE, 0) would return the first tile in the map instead of EMPTY. To address this issue, I have made a modification to the function where I immediately return EMPTY if x or y is negative. This not only fixes the problem but also simplifies the second condition on line 324, resulting in more efficient code.

Furthermore, upon reviewing the code, I noticed that the shift operator (>>) and TILE_SHIFT were being used unnecessarily for every call to MapGetTile. Given that this logic is already used inside of MapGetTileWorld, I replaced all instances of MapGetTile with MapGetTileWorld and removed the unnecessary shifting-related code. Consequently, the TILE_SHIFT variable was no longer required, allowing me to remove it and further streamline the code.

@abolinsky
Copy link

@raysan5

@raysan5 raysan5 merged commit 5ceec7c into raysan5:master Aug 12, 2023
@raysan5
Copy link
Owner

raysan5 commented Aug 12, 2023

@hellworld111 thanks for the review! Actually I haven't touched this code in many years, probably now I would write it in a completely different way.

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.

3 participants