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
Great game! This can be great for a turn based game. Though, what is the goal for this. Is it like a escape some room game and the first person to escape wins? Or something else?
nah it’s not against the ticrate, a while loop executes in 1 frame, so everything within will be executed before the frame goes to the next one. An if statement can’t be run because it will get to an hold after the first tile, because i resets and so far i know you can’t count numbers with an if statement.
@Aj8841
It’s not a game, it’s only a pathing mechanism.
The type of game that i am after is like: For the kings.
Ok figured it out, redone the structure of the script, rewrote some functions and here is the result:
(still using the while loop, can’t get it to work without)
Optimized even further. 4 tiles movement from ± 20% logic usage to ±5 % logic usage. From 10 movement @ 50%+ to ± 11%.
going to limit the max to 8 i think, 6 rolled by dice and 2 as character upgrades(passive/skils/talent/etc) i think. Anyway I am very happy with the result.
Imagine the colors as border only, with a bloom/glow shader, would be neat.
The numbers where a bit tricky, adding text objects on the fly in the loops took a bit of performace, so i simply parented a text object to the tile, spawn the tile and text object is there, then just when the tile is in the path, activate visibility little to no performance cost, and what is not visible won’t be rendered as well.
To be honest i thought blender would get into trouble, because tiles+text = 5760 objects but it’s actually not a problem.