Skip to content

Commit b40d02d

Browse files
committed
Update CHANGELOG for version 2.0.4; refactor pathfinding functions and fix issues with capacity and event emissions
1 parent 2f4f8da commit b40d02d

4 files changed

Lines changed: 42 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@
7575
### Fixed
7676

7777
- Fix debug container redraw
78+
79+
## 2.0.4
80+
81+
### Updated
82+
83+
- \_pathfinding_generate_points() function is now called pathfinding_generate_points()
84+
85+
### Fixed
86+
87+
- Fix issue with pathfinding points capacity #1
88+
- astar_changed event was called twice.

addons/hexagon_tilemaplayer/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@
7575
### Fixed
7676

7777
- Fix debug container redraw
78+
79+
## 2.0.4
80+
81+
### Updated
82+
83+
- \_pathfinding_generate_points() function is now called pathfinding_generate_points()
84+
85+
### Fixed
86+
87+
- Fix issue with pathfinding points capacity #1
88+
- astar_changed event was called twice.

addons/hexagon_tilemaplayer/hexagon_tilemaplayer.gd

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ func _ready() -> void:
101101

102102
if pathfinding_enabled:
103103
astar_changed.connect(_draw_debug, Object.CONNECT_DEFERRED)
104-
_pathfinding_generate_points()
105-
astar_changed.emit()
104+
pathfinding_generate_points()
106105
else:
107106
_draw_debug.call_deferred()
108107

@@ -176,10 +175,20 @@ func pathfinding_recalculate_tile_weight(coord: Vector2i):
176175
)
177176

178177

178+
## @deprecated: Use [method pathfinding_generate_points] instead.
179179
func _pathfinding_generate_points():
180+
pathfinding_generate_points()
181+
182+
183+
## Generate points and connections for the [Astar2D] instance.
184+
##
185+
## [br]This is automatically called in the _ready() function.
186+
## [br]The points capacity is automatically adjusted based on the number of used cells.
187+
## [br]If later you need to add more points to the astar instance call [method AStar2D.reserve_space] with num_nodes the total of points multiplied by 1.12.
188+
## [br]See [url=https://github.com/godotengine/godot/issues/102612#issuecomment-2702275926]this issue[/url] for more information.
189+
func pathfinding_generate_points():
180190
if not astar:
181191
astar = AStar2D.new()
182-
astar.clear()
183192
_pathfinding_create_points()
184193
_pathfinding_create_connections()
185194
astar_changed.emit()
@@ -220,11 +229,16 @@ func _draw_debug():
220229

221230

222231
func _pathfinding_create_points():
232+
astar.clear()
223233
var cells := get_used_cells()
224-
astar.reserve_space(1 << int(log(cells.size()) / log(2)))
234+
# Why 1.12 ? See https://github.com/godotengine/godot/issues/102612#issuecomment-2702275926
235+
var needed_space = cells.size() * 1.12
236+
if astar.get_point_capacity() < needed_space:
237+
astar.reserve_space(needed_space)
225238

239+
var id: int = -1
226240
for coord in cells:
227-
var id = astar.get_available_point_id()
241+
id += 1
228242
var weight = _pathfinding_get_tile_weight(coord)
229243
var pos = map_to_local(coord)
230244
astar.add_point(id, pos, weight)

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ config/features=PackedStringArray("4.4", "Mobile")
1616

1717
[editor_plugins]
1818

19-
enabled=PackedStringArray("res://addons/hexagon_tilemaplayer/plugin.cfg", "res://addons/script-ide/plugin.cfg")
19+
enabled=PackedStringArray("res://addons/hexagon_tilemaplayer/plugin.cfg")
2020

2121
[input]
2222

0 commit comments

Comments
 (0)