For the a* pathfinding that i created i need a way to speed this part up(code below)), if there is a faster way. I am making the pathfinding for a TBS(turn based strategy) game, where i want to show the movement tiles according to movement points.
I got this all working, but at first, the logic usage went to the roof, 95-98% reducing the frame rate to around 11 fps. I optimised the tiles that are searched. Now the logic is around 20%, a huge increase in frames 60 fps stable.
this all is with a grid spawned out of hexagons (2x2m) total of: 2880 tiles: active 2267 / blocked 613
brings up the physics quite a bit as well 11-20%.
anyway, i’m looking for a way to speed this part up, if it can be any faster/lighter, because this part is actually eating all the logic (code runs in true pulse).
tiles_in_range = kdtree
own['start_tile']['number'] = 1 i = 1 while i < len(own['tiles_in_range']): for co, index, dist in own['tiles_in_range']: tile = own['limited_tile_list'][index] # if tile == own['end_tile']: # break if tile['number'] == i: for neighbor in tile['neighbors']: if neighbor['number'] == 0 and neighbor['active_tile']: neighbor['number'] = i+1 i += 1
#edit a video:
- green are tiles allowed to move
- red-/ tiles that are selected and can’t move to (not enough movement points)
- dark red = area outside of the search range (to give me a visual border)
- everything within the dark red tiles is the search/pathing area