Skip to content

improve the performance of the UnitOnScreen() #29

@ipochto

Description

@ipochto

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions