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

improve the performance of the UnitOnScreen() #29

Open
ipochto opened this issue Sep 25, 2021 · 0 comments
Open

improve the performance of the UnitOnScreen() #29

ipochto opened this issue Sep 25, 2021 · 0 comments

Comments

@ipochto
Copy link
Owner

ipochto commented Sep 25, 2021

Andrettin:

I drastically improved the performance of the UnitOnScreen() function by using Select() to get units within a suitable range, and only then looping through them. Instead of looping through ALL units as UnitOnScreen() previously did for the Select(), I used an offset of (-1, -1) for the viewport's top left pos, and of (1, 1) for the viewport's bottom right pos. The assumption there being that a unit's box size won't fully encompass a tile that the unit doesn't physically occupy. This assumption is valid for both Wyrmsun and Wargus unit types
and with some work, it isn't even necessary to make such an assumption, you just need to calculate the max box size tile overflow
e.g., going through each unit type and doing:

box_width_pixel_overflow = (box_width - (tile_width * pixels_per_tile)) / 2;
box_width_tile_overflow = box_width_pixel_overflow / pixels_per_tile + (box_width_pixel_overflow % pixels_per_tile ? 1 : 0);
max_box_width_tile_overflow = std::max(max_box_width_tile_overflow , box_width_tile_overflow);

and then using that number for the viewport top left/bottom right tile offsets

Andrettin/Wyrmgus@71ec95d

original messages here:
https://discord.com/channels/780082494447288340/780082494447288344/890998108668956722

@ipochto ipochto closed this as completed Sep 27, 2021
@ipochto ipochto reopened this Sep 27, 2021
@ipochto ipochto changed the title to finish improve the performance of the UnitOnScreen() Sep 27, 2021
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

No branches or pull requests

1 participant